From cb695b620c4b7303ab72e392d1623db6ab12d4dc Mon Sep 17 00:00:00 2001 From: jschlies Date: Mon, 17 Jul 2023 11:16:51 -0700 Subject: [PATCH 1/7] Need to chech maint up/down before hitting DB --- src/PanicHDServiceProvider.php | 241 +++++++++++++++++++++------------ 1 file changed, 153 insertions(+), 88 deletions(-) diff --git a/src/PanicHDServiceProvider.php b/src/PanicHDServiceProvider.php index e08df9bf..4f670e65 100644 --- a/src/PanicHDServiceProvider.php +++ b/src/PanicHDServiceProvider.php @@ -27,24 +27,37 @@ class PanicHDServiceProvider extends ServiceProvider */ public function boot() { - if (!Schema::hasTable('migrations')) { + /** + * since this calls DB, gotta check if up/down + */ + if ($this->app->isDownForMaintenance()) + { + return; + } + if ( ! Schema::hasTable('migrations')) + { // Database isn't installed yet. return; } // Alias for Member model $loader = \Illuminate\Foundation\AliasLoader::getInstance(); - if (Schema::hasTable('panichd_settings') and Setting::where('slug', 'member_model_class')->count() == 1) { + if (Schema::hasTable('panichd_settings') and Setting::where('slug', 'member_model_class')->count() == 1) + { $member_model_class = Setting::grab('member_model_class'); } - if (!isset($member_model_class) or $member_model_class == 'default'){ - $member_model_class = Cache::remember('panichd::provider_member_class', 3600, function () { + if ( ! isset($member_model_class) or $member_model_class == 'default') + { + $member_model_class = Cache::remember('panichd::provider_member_class', 3600, function () + { // Check App\Models\User existence first - if (class_exists('\App\Models\User')){ + if (class_exists('\App\Models\User')) + { return 'PanicHD\PanicHD\Models\Member_AppModelsUser'; - - }else{ + } + else + { // Inherit from App\User as default return 'PanicHD\PanicHD\Models\Member_AppUser'; } @@ -53,16 +66,17 @@ public function boot() $loader->alias('PanicHDMember', $member_model_class); - $this->loadTranslationsFrom(__DIR__.'/Translations', 'panichd'); - $this->loadViewsFrom(__DIR__.'/Views', 'panichd'); + $this->loadTranslationsFrom(__DIR__ . '/Translations', 'panichd'); + $this->loadViewsFrom(__DIR__ . '/Views', 'panichd'); $authMiddleware = Helpers\LaravelVersion::authMiddleware(); Route::get('panichd', 'PanicHD\PanicHD\Controllers\InstallController@index') - ->middleware($authMiddleware) - ->name('panichd.install.index'); + ->middleware($authMiddleware) + ->name('panichd.install.index'); - if (Request::is('panichd') || Request::is('panichd/*')) { + if (Request::is('panichd') || Request::is('panichd/*')) + { Route::post('/panichd/install', [ 'middleware' => $authMiddleware, 'as' => 'panichd.install.setup', @@ -82,24 +96,28 @@ public function boot() ]); } - $this->publishes([__DIR__.'/Translations' => base_path('resources/lang/vendor/panichd')], 'panichd-lang'); - $this->publishes([__DIR__.'/Views' => base_path('resources/views/vendor/panichd')], 'panichd-views'); - $this->publishes([__DIR__.'/Public' => public_path('vendor/panichd')], 'panichd-public'); - $this->publishes([__DIR__.'/Migrations' => base_path('database/migrations')], 'panichd-db'); + $this->publishes([__DIR__ . '/Translations' => base_path('resources/lang/vendor/panichd')], 'panichd-lang'); + $this->publishes([__DIR__ . '/Views' => base_path('resources/views/vendor/panichd')], 'panichd-views'); + $this->publishes([__DIR__ . '/Public' => public_path('vendor/panichd')], 'panichd-public'); + $this->publishes([__DIR__ . '/Migrations' => base_path('database/migrations')], 'panichd-db'); $installer = new InstallController(); // if a migration or new setting is missing scape to the installation - if ($installer->isUpdated()) { + if ($installer->isUpdated()) + { // Send the Agent User model to the view under $u // Send settings to views under $setting //cache $u $u = null; - view()->composer('panichd::*', function ($view) use (&$u) { - if (auth()->check()) { - if ($u === null) { + view()->composer('panichd::*', function ($view) use (&$u) + { + if (auth()->check()) + { + if ($u === null) + { $u = \PanicHDMember::find(auth()->user()->id); } $view->with('u', $u); @@ -109,41 +127,51 @@ public function boot() }); // Adding HTML5 color picker to form elements - CollectiveForm::macro('custom', function ($type, $name, $value = '#000000', $options = []) { + CollectiveForm::macro('custom', function ($type, $name, $value = '#000000', $options = []) + { $field = $this->input($type, $name, $value, $options); return $field; }); // Passing to views the master view value from the setting file - view()->composer('panichd::*', function ($view) { - $tools = new ToolsController(); - $master = Setting::grab('master_template'); - $email = Setting::grab('email.template'); - $editor_enabled = Setting::grab('editor_enabled'); + view()->composer('panichd::*', function ($view) + { + $tools = new ToolsController(); + $master = Setting::grab('master_template'); + $email = Setting::grab('email.template'); + $editor_enabled = Setting::grab('editor_enabled'); $codemirror_enabled = Setting::grab('editor_html_highlighter'); - $codemirror_theme = Setting::grab('codemirror_theme'); + $codemirror_theme = Setting::grab('codemirror_theme'); $view->with(compact('master', 'email', 'tools', 'editor_enabled', 'codemirror_enabled', 'codemirror_theme')); }); // Include $n_notices in shared.nav and tickets.createedit templates - view()->composer(['panichd::shared.nav', 'panichd::tickets.createedit'], function ($view) { + view()->composer(['panichd::shared.nav', 'panichd::tickets.createedit'], function ($view) + { $n_notices = Setting::grab('departments_notices_feature') ? Ticket::active()->notHidden()->whereIn('user_id', \PanicHDMember::find(auth()->user()->id)->getMyNoticesUsers())->count() : 0; $view->with(compact('n_notices')); }); - view()->composer(['panichd::tickets.partials.summernote', 'panichd::shared.summernote'], function ($view) { + view()->composer(['panichd::tickets.partials.summernote', 'panichd::shared.summernote'], function ($view) + { $editor_locale = Setting::grab('summernote_locale'); - if ($editor_locale == 'laravel') { + if ($editor_locale == 'laravel') + { $editor_locale = config('app.locale'); } - if (substr($editor_locale, 0, 2) == 'en') { + if (substr($editor_locale, 0, 2) == 'en') + { $editor_locale = null; - } else { - if (strlen($editor_locale) == 2) { - switch ($editor_locale) { + } + else + { + if (strlen($editor_locale) == 2) + { + switch ($editor_locale) + { case 'ca': $editor_locale = 'ca-ES'; break; @@ -187,7 +215,7 @@ public function boot() $editor_locale = 'zh-CN'; break; default: - $editor_locale = $editor_locale.'-'.strtoupper($editor_locale); + $editor_locale = $editor_locale . '-' . strtoupper($editor_locale); break; } } @@ -198,51 +226,67 @@ public function boot() // Load summernote options // $editor_options = $user_editor != "0" ? $user_editor : file_get_contents(base_path(Setting::grab('summernote_options_json_file'))); - if ($user_editor != '0') { + if ($user_editor != '0') + { $editor_options = $user_editor; - } elseif (Setting::grab('summernote_options_json_file') != 'default' and file_exists(base_path(Setting::grab('summernote_options_json_file')))) { + } + elseif (Setting::grab('summernote_options_json_file') != 'default' and file_exists(base_path(Setting::grab('summernote_options_json_file')))) + { $editor_options = file_get_contents(base_path(Setting::grab('summernote_options_json_file'))); - } else { - $editor_options = file_get_contents(realpath(__DIR__).'/JSON/summernote_init.json'); + } + else + { + $editor_options = file_get_contents(realpath(__DIR__) . '/JSON/summernote_init.json'); } $view->with(compact('editor_locale', 'editor_options')); }); // Change agent modal - view()->composer('panichd::tickets.partials.modal_agent', function ($view) { + view()->composer('panichd::tickets.partials.modal_agent', function ($view) + { $status_check_name = Setting::grab('default_reopen_status_id') == '0' ? Status::first()->name : Status::find(Setting::grab('default_reopen_status_id'))->name; $view->with(compact('status_check_name')); }); // Notices widget - view()->composer(['panichd::notices.widget', 'panichd::notices.index'], function ($view) { - if (Setting::grab('departments_notices_feature')) { + view()->composer(['panichd::notices.widget', 'panichd::notices.index'], function ($view) + { + if (Setting::grab('departments_notices_feature')) + { // Get available notice users list - if (is_null(auth()->user())) { + if (is_null(auth()->user())) + { $all_dept_users = \PanicHDMember::where('ticketit_department', '0'); - if (version_compare(app()->version(), '5.3.0', '>=')) { + if (version_compare(app()->version(), '5.3.0', '>=')) + { $a_notice_users = $all_dept_users->pluck('id')->toArray(); - } else { + } + else + { $a_notice_users = $all_dept_users->lists('id')->toArray(); } - } else { + } + else + { $a_notice_users = \PanicHDMember::find(auth()->user()->id)->getMyNoticesUsers(); } // Get notices $a_notices = Ticket::active()->notHidden()->whereIn('user_id', $a_notice_users) - ->join('panichd_priorities', 'priority_id', '=', 'panichd_priorities.id') - ->select('panichd_tickets.*') - ->with('owner.department') - ->with('status')->with('tags') - ->withCount('allAttachments') - ->orderByRaw('CASE when status_id="'.Setting::grab('default_close_status_id').'" then 2 else 1 end') - ->orderByRaw('date(start_date)') - ->orderBy('panichd_priorities.magnitude', 'desc') - ->orderBy('start_date', 'asc') - ->get(); - } else { + ->join('panichd_priorities', 'priority_id', '=', 'panichd_priorities.id') + ->select('panichd_tickets.*') + ->with('owner.department') + ->with('status')->with('tags') + ->withCount('allAttachments') + ->orderByRaw('CASE when status_id="' . Setting::grab('default_close_status_id') . '" then 2 else 1 end') + ->orderByRaw('date(start_date)') + ->orderBy('panichd_priorities.magnitude', 'desc') + ->orderBy('start_date', 'asc') + ->get(); + } + else + { // Don't show notices $a_notices = []; } @@ -253,7 +297,8 @@ public function boot() }); // Send notification when comment is modified - Event::listen('PanicHD\PanicHD\Events\CommentUpdated', function ($event) { + Event::listen('PanicHD\PanicHD\Events\CommentUpdated', function ($event) + { $original = $event->original; $modified = $event->modified; @@ -262,34 +307,41 @@ public function boot() }); // Send notification when new comment is added - Event::listen('PanicHD\PanicHD\Events\CommentCreated', function ($event) { - if (Setting::grab('comment_notification')) { - $comment = $event->comment; + Event::listen('PanicHD\PanicHD\Events\CommentCreated', function ($event) + { + if (Setting::grab('comment_notification')) + { + $comment = $event->comment; $notification = new NotificationsController($comment->ticket->category); $notification->newComment($comment, $event->request); } }); - Ticket::saved(function ($ticket) { + Ticket::saved(function ($ticket) + { Cache::forget('panichd::a_complete_ticket_year_counts'); }); - Ticket::deleted(function ($ticket) { + Ticket::deleted(function ($ticket) + { Cache::forget('panichd::a_complete_ticket_year_counts'); }); - Event::listen('PanicHD\PanicHD\Events\TicketUpdated', function ($event) { + Event::listen('PanicHD\PanicHD\Events\TicketUpdated', function ($event) + { $original = $event->original; $modified = $event->modified; // Send notification when ticket status is modified or ticket is closed - if (Setting::grab('status_notification')) { - if (!strtotime($original->completed_at) and strtotime($modified->completed_at)) { - + if (Setting::grab('status_notification')) + { + if ( ! strtotime($original->completed_at) and strtotime($modified->completed_at)) + { // Notificate closed ticket $notification = new NotificationsController($modified->category); $notification->ticketClosed($original, $modified); - } elseif ($original->status_id != $modified->status_id) { - + } + elseif ($original->status_id != $modified->status_id) + { // Notificate updated status $notification = new NotificationsController($modified->category); $notification->ticketStatusUpdated($original, $modified); @@ -297,8 +349,10 @@ public function boot() } // Send notification when agent is modified - if (Setting::grab('assigned_notification')) { - if ($original->agent->id != $modified->agent->id) { + if (Setting::grab('assigned_notification')) + { + if ($original->agent->id != $modified->agent->id) + { $notification = new NotificationsController($modified->category); $notification->ticketAgentUpdated($original, $modified); } @@ -308,8 +362,10 @@ public function boot() }); // Send notification when ticket is created - Event::listen('PanicHD\PanicHD\Events\TicketCreated', function ($event) { - if (Setting::grab('assigned_notification')) { + Event::listen('PanicHD\PanicHD\Events\TicketCreated', function ($event) + { + if (Setting::grab('assigned_notification')) + { $notification = new NotificationsController($event->ticket->category); $notification->newTicket($event->ticket); } @@ -317,26 +373,31 @@ public function boot() return true; }); - $main_route = Setting::grab('main_route'); - $main_route_path = Setting::grab('main_route_path'); - $admin_route = Setting::grab('admin_route'); + $main_route = Setting::grab('main_route'); + $main_route_path = Setting::grab('main_route_path'); + $admin_route = Setting::grab('admin_route'); $admin_route_path = Setting::grab('admin_route_path'); - include __DIR__.'/routes.php'; + include __DIR__ . '/routes.php'; - if ($this->app->runningInConsole()) { + if ($this->app->runningInConsole()) + { $this->commands([ - Console\DemoRollback::class, - Console\WipeOffLists::class, - Console\WipeOffTickets::class, - ]); + Console\DemoRollback::class, + Console\WipeOffLists::class, + Console\WipeOffTickets::class, + ]); } - } else { - Route::get('/tickets/{params?}', function () { + } + else + { + Route::get('/tickets/{params?}', function () + { return redirect()->route('panichd.install.index'); })->where('params', '(.*)'); - Route::get('/panichd/{menu?}', function () { + Route::get('/panichd/{menu?}', function () + { return redirect()->route('panichd.install.index'); })->where('menu', '(.*)'); } @@ -356,9 +417,12 @@ public function register() $this->app->register(\Intervention\Image\ImageServiceProvider::class); $this->app->register(\Jenssegers\Date\DateServiceProvider::class); $this->app->register(\Mews\Purifier\PurifierServiceProvider::class); - if (class_exists('\Yajra\DataTables\DataTablesServiceProvider')) { + if (class_exists('\Yajra\DataTables\DataTablesServiceProvider')) + { $this->app->register(\Yajra\DataTables\DataTablesServiceProvider::class); - } else { + } + else + { $this->app->register(\Yajra\Datatables\DatatablesServiceProvider::class); } @@ -374,7 +438,8 @@ public function register() * Register htmlify command. Need to run this when upgrading from <=0.2.2 */ - $this->app->singleton('command.panichd.panichd.htmlify', function ($app) { + $this->app->singleton('command.panichd.panichd.htmlify', function ($app) + { return new Htmlify(); }); $this->commands('command.panichd.panichd.htmlify'); From d0bf3f6de55b45c4ac50fca8bbff3f97ffe54124 Mon Sep 17 00:00:00 2001 From: jschlies Date: Mon, 17 Jul 2023 11:50:22 -0700 Subject: [PATCH 2/7] Need to chech maint up/down before hitting DB style --- src/PanicHDServiceProvider.php | 238 ++++++++++++++------------------- 1 file changed, 101 insertions(+), 137 deletions(-) diff --git a/src/PanicHDServiceProvider.php b/src/PanicHDServiceProvider.php index 4f670e65..c0076b9c 100644 --- a/src/PanicHDServiceProvider.php +++ b/src/PanicHDServiceProvider.php @@ -27,47 +27,56 @@ class PanicHDServiceProvider extends ServiceProvider */ public function boot() { + /** * since this calls DB, gotta check if up/down */ - if ($this->app->isDownForMaintenance()) - { - return; - } - if ( ! Schema::hasTable('migrations')) - { - // Database isn't installed yet. + if ($this->app->isDownForMaintenance()) { return; } // Alias for Member model $loader = \Illuminate\Foundation\AliasLoader::getInstance(); - if (Schema::hasTable('panichd_settings') and Setting::where('slug', 'member_model_class')->count() == 1) - { + if (Schema::hasTable('panichd_settings') and Setting::where('slug', 'member_model_class')->count() == 1) { $member_model_class = Setting::grab('member_model_class'); } - if ( ! isset($member_model_class) or $member_model_class == 'default') - { - $member_model_class = Cache::remember('panichd::provider_member_class', 3600, function () - { + if (!isset($member_model_class) or $member_model_class == 'default'){ + $member_model_class = Cache::remember('panichd::provider_member_class', 3600, function () { // Check App\Models\User existence first - if (class_exists('\App\Models\User')) - { + if (class_exists('\UCSF\DOM\Models\MySQL\Models\User')){ return 'PanicHD\PanicHD\Models\Member_AppModelsUser'; - } - else - { + + }else{ // Inherit from App\User as default return 'PanicHD\PanicHD\Models\Member_AppUser'; } }); } + $loader = \Illuminate\Foundation\AliasLoader::getInstance(); + if (Schema::hasTable('panichd_settings') and Setting::where('slug', 'member_model_class')->count() == 1) + { + $member_model_class = Setting::grab('member_model_class'); + } + + if ( ! isset($member_model_class) or $member_model_class == 'default') + { + // Check App\Models\User existence first + if (class_exists('\UCSF\DOM\Models\MySQL\User')) + { + $member_model_class = 'PanicHD\PanicHD\Models\Member_AppModelsUser'; + } + else + { + // Inherit from App\User as default + $member_model_class = 'PanicHD\PanicHD\Models\Member_AppUser'; + } + } $loader->alias('PanicHDMember', $member_model_class); - $this->loadTranslationsFrom(__DIR__ . '/Translations', 'panichd'); - $this->loadViewsFrom(__DIR__ . '/Views', 'panichd'); + $this->loadTranslationsFrom(__DIR__.'/Translations', 'panichd'); + $this->loadViewsFrom(__DIR__.'/Views', 'panichd'); $authMiddleware = Helpers\LaravelVersion::authMiddleware(); @@ -75,8 +84,7 @@ public function boot() ->middleware($authMiddleware) ->name('panichd.install.index'); - if (Request::is('panichd') || Request::is('panichd/*')) - { + if (Request::is('panichd') || Request::is('panichd/*')) { Route::post('/panichd/install', [ 'middleware' => $authMiddleware, 'as' => 'panichd.install.setup', @@ -96,28 +104,24 @@ public function boot() ]); } - $this->publishes([__DIR__ . '/Translations' => base_path('resources/lang/vendor/panichd')], 'panichd-lang'); - $this->publishes([__DIR__ . '/Views' => base_path('resources/views/vendor/panichd')], 'panichd-views'); - $this->publishes([__DIR__ . '/Public' => public_path('vendor/panichd')], 'panichd-public'); - $this->publishes([__DIR__ . '/Migrations' => base_path('database/migrations')], 'panichd-db'); + $this->publishes([__DIR__.'/Translations' => base_path('resources/lang/vendor/panichd')], 'panichd-lang'); + $this->publishes([__DIR__.'/Views' => base_path('resources/views/vendor/panichd')], 'panichd-views'); + $this->publishes([__DIR__.'/Public' => public_path('vendor/panichd')], 'panichd-public'); + $this->publishes([__DIR__.'/Migrations' => base_path('database/migrations')], 'panichd-db'); $installer = new InstallController(); // if a migration or new setting is missing scape to the installation - if ($installer->isUpdated()) - { + if ($installer->isUpdated()) { // Send the Agent User model to the view under $u // Send settings to views under $setting //cache $u $u = null; - view()->composer('panichd::*', function ($view) use (&$u) - { - if (auth()->check()) - { - if ($u === null) - { + view()->composer('panichd::*', function ($view) use (&$u) { + if (auth()->check()) { + if ($u === null) { $u = \PanicHDMember::find(auth()->user()->id); } $view->with('u', $u); @@ -127,51 +131,41 @@ public function boot() }); // Adding HTML5 color picker to form elements - CollectiveForm::macro('custom', function ($type, $name, $value = '#000000', $options = []) - { + CollectiveForm::macro('custom', function ($type, $name, $value = '#000000', $options = []) { $field = $this->input($type, $name, $value, $options); return $field; }); // Passing to views the master view value from the setting file - view()->composer('panichd::*', function ($view) - { - $tools = new ToolsController(); - $master = Setting::grab('master_template'); - $email = Setting::grab('email.template'); - $editor_enabled = Setting::grab('editor_enabled'); + view()->composer('panichd::*', function ($view) { + $tools = new ToolsController(); + $master = Setting::grab('master_template'); + $email = Setting::grab('email.template'); + $editor_enabled = Setting::grab('editor_enabled'); $codemirror_enabled = Setting::grab('editor_html_highlighter'); - $codemirror_theme = Setting::grab('codemirror_theme'); + $codemirror_theme = Setting::grab('codemirror_theme'); $view->with(compact('master', 'email', 'tools', 'editor_enabled', 'codemirror_enabled', 'codemirror_theme')); }); // Include $n_notices in shared.nav and tickets.createedit templates - view()->composer(['panichd::shared.nav', 'panichd::tickets.createedit'], function ($view) - { + view()->composer(['panichd::shared.nav', 'panichd::tickets.createedit'], function ($view) { $n_notices = Setting::grab('departments_notices_feature') ? Ticket::active()->notHidden()->whereIn('user_id', \PanicHDMember::find(auth()->user()->id)->getMyNoticesUsers())->count() : 0; $view->with(compact('n_notices')); }); - view()->composer(['panichd::tickets.partials.summernote', 'panichd::shared.summernote'], function ($view) - { + view()->composer(['panichd::tickets.partials.summernote', 'panichd::shared.summernote'], function ($view) { $editor_locale = Setting::grab('summernote_locale'); - if ($editor_locale == 'laravel') - { + if ($editor_locale == 'laravel') { $editor_locale = config('app.locale'); } - if (substr($editor_locale, 0, 2) == 'en') - { + if (substr($editor_locale, 0, 2) == 'en') { $editor_locale = null; - } - else - { - if (strlen($editor_locale) == 2) - { - switch ($editor_locale) - { + } else { + if (strlen($editor_locale) == 2) { + switch ($editor_locale) { case 'ca': $editor_locale = 'ca-ES'; break; @@ -215,7 +209,7 @@ public function boot() $editor_locale = 'zh-CN'; break; default: - $editor_locale = $editor_locale . '-' . strtoupper($editor_locale); + $editor_locale = $editor_locale.'-'.strtoupper($editor_locale); break; } } @@ -226,49 +220,35 @@ public function boot() // Load summernote options // $editor_options = $user_editor != "0" ? $user_editor : file_get_contents(base_path(Setting::grab('summernote_options_json_file'))); - if ($user_editor != '0') - { + if ($user_editor != '0') { $editor_options = $user_editor; - } - elseif (Setting::grab('summernote_options_json_file') != 'default' and file_exists(base_path(Setting::grab('summernote_options_json_file')))) - { + } elseif (Setting::grab('summernote_options_json_file') != 'default' and file_exists(base_path(Setting::grab('summernote_options_json_file')))) { $editor_options = file_get_contents(base_path(Setting::grab('summernote_options_json_file'))); - } - else - { - $editor_options = file_get_contents(realpath(__DIR__) . '/JSON/summernote_init.json'); + } else { + $editor_options = file_get_contents(realpath(__DIR__).'/JSON/summernote_init.json'); } $view->with(compact('editor_locale', 'editor_options')); }); // Change agent modal - view()->composer('panichd::tickets.partials.modal_agent', function ($view) - { + view()->composer('panichd::tickets.partials.modal_agent', function ($view) { $status_check_name = Setting::grab('default_reopen_status_id') == '0' ? Status::first()->name : Status::find(Setting::grab('default_reopen_status_id'))->name; $view->with(compact('status_check_name')); }); // Notices widget - view()->composer(['panichd::notices.widget', 'panichd::notices.index'], function ($view) - { - if (Setting::grab('departments_notices_feature')) - { + view()->composer(['panichd::notices.widget', 'panichd::notices.index'], function ($view) { + if (Setting::grab('departments_notices_feature')) { // Get available notice users list - if (is_null(auth()->user())) - { + if (is_null(auth()->user())) { $all_dept_users = \PanicHDMember::where('ticketit_department', '0'); - if (version_compare(app()->version(), '5.3.0', '>=')) - { + if (version_compare(app()->version(), '5.3.0', '>=')) { $a_notice_users = $all_dept_users->pluck('id')->toArray(); - } - else - { + } else { $a_notice_users = $all_dept_users->lists('id')->toArray(); } - } - else - { + } else { $a_notice_users = \PanicHDMember::find(auth()->user()->id)->getMyNoticesUsers(); } @@ -279,14 +259,12 @@ public function boot() ->with('owner.department') ->with('status')->with('tags') ->withCount('allAttachments') - ->orderByRaw('CASE when status_id="' . Setting::grab('default_close_status_id') . '" then 2 else 1 end') + ->orderByRaw('CASE when status_id="'.Setting::grab('default_close_status_id').'" then 2 else 1 end') ->orderByRaw('date(start_date)') ->orderBy('panichd_priorities.magnitude', 'desc') ->orderBy('start_date', 'asc') ->get(); - } - else - { + } else { // Don't show notices $a_notices = []; } @@ -297,8 +275,7 @@ public function boot() }); // Send notification when comment is modified - Event::listen('PanicHD\PanicHD\Events\CommentUpdated', function ($event) - { + Event::listen('PanicHD\PanicHD\Events\CommentUpdated', function ($event) { $original = $event->original; $modified = $event->modified; @@ -307,41 +284,34 @@ public function boot() }); // Send notification when new comment is added - Event::listen('PanicHD\PanicHD\Events\CommentCreated', function ($event) - { - if (Setting::grab('comment_notification')) - { - $comment = $event->comment; + Event::listen('PanicHD\PanicHD\Events\CommentCreated', function ($event) { + if (Setting::grab('comment_notification')) { + $comment = $event->comment; $notification = new NotificationsController($comment->ticket->category); $notification->newComment($comment, $event->request); } }); - Ticket::saved(function ($ticket) - { + Ticket::saved(function ($ticket) { Cache::forget('panichd::a_complete_ticket_year_counts'); }); - Ticket::deleted(function ($ticket) - { + Ticket::deleted(function ($ticket) { Cache::forget('panichd::a_complete_ticket_year_counts'); }); - Event::listen('PanicHD\PanicHD\Events\TicketUpdated', function ($event) - { + Event::listen('PanicHD\PanicHD\Events\TicketUpdated', function ($event) { $original = $event->original; $modified = $event->modified; // Send notification when ticket status is modified or ticket is closed - if (Setting::grab('status_notification')) - { - if ( ! strtotime($original->completed_at) and strtotime($modified->completed_at)) - { + if (Setting::grab('status_notification')) { + if (!strtotime($original->completed_at) and strtotime($modified->completed_at)) { + // Notificate closed ticket $notification = new NotificationsController($modified->category); $notification->ticketClosed($original, $modified); - } - elseif ($original->status_id != $modified->status_id) - { + } elseif ($original->status_id != $modified->status_id) { + // Notificate updated status $notification = new NotificationsController($modified->category); $notification->ticketStatusUpdated($original, $modified); @@ -349,10 +319,8 @@ public function boot() } // Send notification when agent is modified - if (Setting::grab('assigned_notification')) - { - if ($original->agent->id != $modified->agent->id) - { + if (Setting::grab('assigned_notification')) { + if ($original->agent->id != $modified->agent->id) { $notification = new NotificationsController($modified->category); $notification->ticketAgentUpdated($original, $modified); } @@ -362,10 +330,8 @@ public function boot() }); // Send notification when ticket is created - Event::listen('PanicHD\PanicHD\Events\TicketCreated', function ($event) - { - if (Setting::grab('assigned_notification')) - { + Event::listen('PanicHD\PanicHD\Events\TicketCreated', function ($event) { + if (Setting::grab('assigned_notification')) { $notification = new NotificationsController($event->ticket->category); $notification->newTicket($event->ticket); } @@ -373,31 +339,26 @@ public function boot() return true; }); - $main_route = Setting::grab('main_route'); - $main_route_path = Setting::grab('main_route_path'); - $admin_route = Setting::grab('admin_route'); + $main_route = Setting::grab('main_route'); + $main_route_path = Setting::grab('main_route_path'); + $admin_route = Setting::grab('admin_route'); $admin_route_path = Setting::grab('admin_route_path'); - include __DIR__ . '/routes.php'; + include __DIR__.'/routes.php'; - if ($this->app->runningInConsole()) - { + if ($this->app->runningInConsole()) { $this->commands([ Console\DemoRollback::class, Console\WipeOffLists::class, Console\WipeOffTickets::class, ]); } - } - else - { - Route::get('/tickets/{params?}', function () - { + } else { + Route::get('/tickets/{params?}', function () { return redirect()->route('panichd.install.index'); })->where('params', '(.*)'); - Route::get('/panichd/{menu?}', function () - { + Route::get('/panichd/{menu?}', function () { return redirect()->route('panichd.install.index'); })->where('menu', '(.*)'); } @@ -410,6 +371,13 @@ public function boot() */ public function register() { + /** + * since this calls DB, gotta check if up/down + */ + if ($this->app->isDownForMaintenance()) + { + return; + } /* * Register the service provider for the dependency. */ @@ -417,12 +385,9 @@ public function register() $this->app->register(\Intervention\Image\ImageServiceProvider::class); $this->app->register(\Jenssegers\Date\DateServiceProvider::class); $this->app->register(\Mews\Purifier\PurifierServiceProvider::class); - if (class_exists('\Yajra\DataTables\DataTablesServiceProvider')) - { + if (class_exists('\Yajra\DataTables\DataTablesServiceProvider')) { $this->app->register(\Yajra\DataTables\DataTablesServiceProvider::class); - } - else - { + } else { $this->app->register(\Yajra\Datatables\DatatablesServiceProvider::class); } @@ -438,10 +403,9 @@ public function register() * Register htmlify command. Need to run this when upgrading from <=0.2.2 */ - $this->app->singleton('command.panichd.panichd.htmlify', function ($app) - { + $this->app->singleton('command.panichd.panichd.htmlify', function ($app) { return new Htmlify(); }); $this->commands('command.panichd.panichd.htmlify'); } -} +} \ No newline at end of file From d8a57598a429ab47cd85e8b8f08b54fd5edb4660 Mon Sep 17 00:00:00 2001 From: jschlies Date: Mon, 17 Jul 2023 11:52:24 -0700 Subject: [PATCH 3/7] Need to chech maint up/down before hitting DB style 2 --- src/PanicHDServiceProvider.php | 38 +++++++--------------------------- 1 file changed, 8 insertions(+), 30 deletions(-) diff --git a/src/PanicHDServiceProvider.php b/src/PanicHDServiceProvider.php index c0076b9c..345ecc67 100644 --- a/src/PanicHDServiceProvider.php +++ b/src/PanicHDServiceProvider.php @@ -27,11 +27,15 @@ class PanicHDServiceProvider extends ServiceProvider */ public function boot() { - /** * since this calls DB, gotta check if up/down */ - if ($this->app->isDownForMaintenance()) { + if ($this->app->isDownForMaintenance()) + { + return; + } + if (!Schema::hasTable('migrations')) { + // Database isn't installed yet. return; } @@ -44,7 +48,7 @@ public function boot() if (!isset($member_model_class) or $member_model_class == 'default'){ $member_model_class = Cache::remember('panichd::provider_member_class', 3600, function () { // Check App\Models\User existence first - if (class_exists('\UCSF\DOM\Models\MySQL\Models\User')){ + if (class_exists('\App\Models\User')){ return 'PanicHD\PanicHD\Models\Member_AppModelsUser'; }else{ @@ -53,25 +57,6 @@ public function boot() } }); } - $loader = \Illuminate\Foundation\AliasLoader::getInstance(); - if (Schema::hasTable('panichd_settings') and Setting::where('slug', 'member_model_class')->count() == 1) - { - $member_model_class = Setting::grab('member_model_class'); - } - - if ( ! isset($member_model_class) or $member_model_class == 'default') - { - // Check App\Models\User existence first - if (class_exists('\UCSF\DOM\Models\MySQL\User')) - { - $member_model_class = 'PanicHD\PanicHD\Models\Member_AppModelsUser'; - } - else - { - // Inherit from App\User as default - $member_model_class = 'PanicHD\PanicHD\Models\Member_AppUser'; - } - } $loader->alias('PanicHDMember', $member_model_class); @@ -371,13 +356,6 @@ public function boot() */ public function register() { - /** - * since this calls DB, gotta check if up/down - */ - if ($this->app->isDownForMaintenance()) - { - return; - } /* * Register the service provider for the dependency. */ @@ -408,4 +386,4 @@ public function register() }); $this->commands('command.panichd.panichd.htmlify'); } -} \ No newline at end of file +} From 06a3f9f5db4d23a970e90f616ead79d6c7f53cfb Mon Sep 17 00:00:00 2001 From: jschlies Date: Mon, 17 Jul 2023 12:02:00 -0700 Subject: [PATCH 4/7] Need to chech maint up/down before hitting DB style 2 lint --- src/PanicHDServiceProvider.php | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/PanicHDServiceProvider.php b/src/PanicHDServiceProvider.php index 345ecc67..bd7dda83 100644 --- a/src/PanicHDServiceProvider.php +++ b/src/PanicHDServiceProvider.php @@ -66,8 +66,8 @@ public function boot() $authMiddleware = Helpers\LaravelVersion::authMiddleware(); Route::get('panichd', 'PanicHD\PanicHD\Controllers\InstallController@index') - ->middleware($authMiddleware) - ->name('panichd.install.index'); + ->middleware($authMiddleware) + ->name('panichd.install.index'); if (Request::is('panichd') || Request::is('panichd/*')) { Route::post('/panichd/install', [ @@ -239,16 +239,16 @@ public function boot() // Get notices $a_notices = Ticket::active()->notHidden()->whereIn('user_id', $a_notice_users) - ->join('panichd_priorities', 'priority_id', '=', 'panichd_priorities.id') - ->select('panichd_tickets.*') - ->with('owner.department') - ->with('status')->with('tags') - ->withCount('allAttachments') - ->orderByRaw('CASE when status_id="'.Setting::grab('default_close_status_id').'" then 2 else 1 end') - ->orderByRaw('date(start_date)') - ->orderBy('panichd_priorities.magnitude', 'desc') - ->orderBy('start_date', 'asc') - ->get(); + ->join('panichd_priorities', 'priority_id', '=', 'panichd_priorities.id') + ->select('panichd_tickets.*') + ->with('owner.department') + ->with('status')->with('tags') + ->withCount('allAttachments') + ->orderByRaw('CASE when status_id="'.Setting::grab('default_close_status_id').'" then 2 else 1 end') + ->orderByRaw('date(start_date)') + ->orderBy('panichd_priorities.magnitude', 'desc') + ->orderBy('start_date', 'asc') + ->get(); } else { // Don't show notices $a_notices = []; @@ -333,10 +333,10 @@ public function boot() if ($this->app->runningInConsole()) { $this->commands([ - Console\DemoRollback::class, - Console\WipeOffLists::class, - Console\WipeOffTickets::class, - ]); + Console\DemoRollback::class, + Console\WipeOffLists::class, + Console\WipeOffTickets::class, + ]); } } else { Route::get('/tickets/{params?}', function () { From 2789e0e53f1299a496ea6396f78e6724d2bb81b0 Mon Sep 17 00:00:00 2001 From: jschlies Date: Mon, 17 Jul 2023 12:38:56 -0700 Subject: [PATCH 5/7] Need to chech maint up/down before hitting DB style 2 more lint --- src/PanicHDServiceProvider.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/PanicHDServiceProvider.php b/src/PanicHDServiceProvider.php index bd7dda83..c49f162a 100644 --- a/src/PanicHDServiceProvider.php +++ b/src/PanicHDServiceProvider.php @@ -30,8 +30,7 @@ public function boot() /** * since this calls DB, gotta check if up/down */ - if ($this->app->isDownForMaintenance()) - { + if ($this->app->isDownForMaintenance()) { return; } if (!Schema::hasTable('migrations')) { From 3d77d20ec39209ba356d59c686af8b312cc5c511 Mon Sep 17 00:00:00 2001 From: jschlies Date: Mon, 17 Jul 2023 12:41:44 -0700 Subject: [PATCH 6/7] Need to chech maint up/down before hitting DB style 3 more lint --- src/PanicHDServiceProvider.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/PanicHDServiceProvider.php b/src/PanicHDServiceProvider.php index c49f162a..1dadee1d 100644 --- a/src/PanicHDServiceProvider.php +++ b/src/PanicHDServiceProvider.php @@ -28,7 +28,7 @@ class PanicHDServiceProvider extends ServiceProvider public function boot() { /** - * since this calls DB, gotta check if up/down + * since this calls DB, gotta check if up/down. */ if ($this->app->isDownForMaintenance()) { return; @@ -40,11 +40,11 @@ public function boot() // Alias for Member model $loader = \Illuminate\Foundation\AliasLoader::getInstance(); - if (Schema::hasTable('panichd_settings') and Setting::where('slug', 'member_model_class')->count() == 1) { + if (Schema::hasTable('panichd_settings') and Setting::where('slug', 'member_model_class')->count() == 1){ $member_model_class = Setting::grab('member_model_class'); } - if (!isset($member_model_class) or $member_model_class == 'default'){ + if (!isset($member_model_class) or $member_model_class == 'default') { $member_model_class = Cache::remember('panichd::provider_member_class', 3600, function () { // Check App\Models\User existence first if (class_exists('\App\Models\User')){ From aeba0c6226650e3c1588ffa191a4c9166544753c Mon Sep 17 00:00:00 2001 From: jschlies Date: Mon, 17 Jul 2023 12:43:02 -0700 Subject: [PATCH 7/7] Need to chech maint up/down before hitting DB style 4 more lint --- src/PanicHDServiceProvider.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PanicHDServiceProvider.php b/src/PanicHDServiceProvider.php index 1dadee1d..cad1de1b 100644 --- a/src/PanicHDServiceProvider.php +++ b/src/PanicHDServiceProvider.php @@ -40,11 +40,11 @@ public function boot() // Alias for Member model $loader = \Illuminate\Foundation\AliasLoader::getInstance(); - if (Schema::hasTable('panichd_settings') and Setting::where('slug', 'member_model_class')->count() == 1){ + if (Schema::hasTable('panichd_settings') and Setting::where('slug', 'member_model_class')->count() == 1) { $member_model_class = Setting::grab('member_model_class'); } - if (!isset($member_model_class) or $member_model_class == 'default') { + if (!isset($member_model_class) or $member_model_class == 'default'){ $member_model_class = Cache::remember('panichd::provider_member_class', 3600, function () { // Check App\Models\User existence first if (class_exists('\App\Models\User')){