From 84ef4ce14e9ff7e2dab738e8b8e9c9c31e549d88 Mon Sep 17 00:00:00 2001 From: Chaitali Sakhale Date: Thu, 13 Aug 2020 21:02:31 +0530 Subject: [PATCH] Breaking fix for composer update --- src/WebSocketsServiceProvider.php | 54 +++++++++++++++++++------------ 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/src/WebSocketsServiceProvider.php b/src/WebSocketsServiceProvider.php index cf32f34..561f55c 100644 --- a/src/WebSocketsServiceProvider.php +++ b/src/WebSocketsServiceProvider.php @@ -13,6 +13,7 @@ use BeyondCode\LaravelWebSockets\Statistics\Http\Controllers\WebSocketStatistics use BeyondCode\LaravelWebSockets\Statistics\Http\Middleware\Authorize as AuthorizeStatistics; use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager; use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManagers\ArrayChannelManager; +use Illuminate\Database\QueryException; use Illuminate\Support\Facades\Gate; use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Schema; @@ -23,31 +24,38 @@ class WebSocketsServiceProvider extends ServiceProvider public function boot() { $this->publishes([ - __DIR__.'/../config/websockets.php' => base_path('config/websockets.php'), + __DIR__ . '/../config/websockets.php' => base_path('config/websockets.php'), ], 'config'); - if (! Schema::hasTable('websockets_statistics_entries')) { - $this->publishes([ - __DIR__.'/../database/migrations/create_websockets_statistics_entries_table.php.stub' => database_path('migrations/'.date('Y_m_d_His', time()).'_create_websockets_statistics_entries_table.php'), - ], 'migrations'); + try { + if (!Schema::hasTable('websockets_statistics_entries')) { + $this->publishes([ + __DIR__ . '/../database/migrations/create_websockets_statistics_entries_table.php.stub' => database_path('migrations/' . date('Y_m_d_His', time()) . '_create_websockets_statistics_entries_table.php'), + ], 'migrations'); + } + + $this + ->registerRoutes() + ->registerDashboardGate(); + + $this->loadViewsFrom(__DIR__ . '/../resources/views/', 'websockets'); + + $this->commands([ + Console\StartWebSocketServer::class, + Console\CleanStatistics::class, + Console\RestartWebSocketServer::class, + ]); + } catch (QueryException $e) { + // Exception raised by composer update + // Usually happens when doing on CI where no DB exists at start + // Either way if DB connection not obtained + // Catching and doing nothing is ignore for composer update } - - $this - ->registerRoutes() - ->registerDashboardGate(); - - $this->loadViewsFrom(__DIR__.'/../resources/views/', 'websockets'); - - $this->commands([ - Console\StartWebSocketServer::class, - Console\CleanStatistics::class, - Console\RestartWebSocketServer::class, - ]); } public function register() { - $this->mergeConfigFrom(__DIR__.'/../config/websockets.php', 'websockets'); + $this->mergeConfigFrom(__DIR__ . '/../config/websockets.php', 'websockets'); $this->app->singleton('websockets.router', function () { return new Router(); @@ -55,7 +63,7 @@ class WebSocketsServiceProvider extends ServiceProvider $this->app->singleton(ChannelManager::class, function () { return config('websockets.channel_manager') !== null && class_exists(config('websockets.channel_manager')) - ? app(config('websockets.channel_manager')) : new ArrayChannelManager(); + ? app(config('websockets.channel_manager')) : new ArrayChannelManager(); }); $this->app->singleton(AppProvider::class, function () { @@ -63,12 +71,15 @@ class WebSocketsServiceProvider extends ServiceProvider }); } + /** + * @return mixed + */ protected function registerRoutes() { Route::prefix(config('websockets.path'))->group(function () { Route::middleware(config('websockets.middleware', [AuthorizeDashboard::class]))->group(function () { Route::get('/', ShowDashboard::class); - Route::get('/api/{appId}/statistics', [DashboardApiController::class, 'getStatistics']); + Route::get('/api/{appId}/statistics', [DashboardApiController::class, 'getStatistics']); Route::post('auth', AuthenticateDashboard::class); Route::post('event', SendMessage::class); }); @@ -81,6 +92,9 @@ class WebSocketsServiceProvider extends ServiceProvider return $this; } + /** + * @return mixed + */ protected function registerDashboardGate() { Gate::define('viewWebSocketsDashboard', function ($user = null) {