From f958c9bd6bacd44c497ae0d23e867cb02155863e Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 4 Oct 2023 09:43:27 +0200 Subject: [PATCH] Rebase feat/tasks (#642) * fix: user API sometimes returning trainings with keys Sometimes the trainings key returned a key=value array, where the key had counted all trainings with some black magic. This fix forces it to only return the values as that's intended functionality * misc: version bump * fix: errors on update check job * fix: last cron setting variable name and defaults * Version bump * Pint, cheers :beers: * fix: display cron/version warnings only to admins --- app/Console/Commands/CheckUpdate.php | 22 ++++++++++++------- app/Console/Kernel.php | 2 +- app/Http/Controllers/API/UserController.php | 2 +- app/Http/Controllers/DashboardController.php | 4 ++-- config/app.php | 2 +- ...2023_10_01_200047_add_cronjob_datetime.php | 4 ++-- .../views/admin/globalsettings.blade.php | 4 ++-- 7 files changed, 23 insertions(+), 17 deletions(-) diff --git a/app/Console/Commands/CheckUpdate.php b/app/Console/Commands/CheckUpdate.php index 72c77ec63..9ad596026 100644 --- a/app/Console/Commands/CheckUpdate.php +++ b/app/Console/Commands/CheckUpdate.php @@ -31,16 +31,22 @@ public function handle() { $currentVersion = 'v' . config('app.version'); - $releasedVersion = Http::get('https://api.github.com/repos/Vatsim-Scandinavia/controlcenter/releases')->json()[0]['name']; + $releasedData = Http::get('https://api.github.com/repos/Vatsim-Scandinavia/controlcenter/releases')->json(); - if ($currentVersion != $releasedVersion) { - $this->info("There's a new version of Control Center available! Please update to $releasedVersion."); - Setting::set('_updateAvailable', $releasedVersion); - } else { - Setting::set('_updateAvailable', null); - } + if (isset($releasedData) && isset($releasedData[0]) && isset($releasedData[0]['name'])) { + $releasedVersion = $releasedData[0]['name']; + + if ($currentVersion != $releasedVersion) { + $this->info("There's a new version of Control Center available! Please update to $releasedVersion."); + Setting::set('_updateAvailable', $releasedVersion); + } else { + $this->info('Control Center is up to date.'); + Setting::forget('_updateAvailable'); + } - Setting::save(); + Setting::save(); + + } return Command::SUCCESS; } diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 3ee12ea12..32ef0cd54 100755 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -87,7 +87,7 @@ protected function schedule(Schedule $schedule) // Log last cronjob time $schedule->call(function () { - Setting::set('lastCronRun', now()); + Setting::set('_lastCronRun', now()); Setting::save(); })->everyMinute(); } diff --git a/app/Http/Controllers/API/UserController.php b/app/Http/Controllers/API/UserController.php index e657fc8b7..b161247c7 100644 --- a/app/Http/Controllers/API/UserController.php +++ b/app/Http/Controllers/API/UserController.php @@ -267,6 +267,6 @@ private function mapTrainings(Collection $trainings) 'started_at' => $training->started_at, 'ratings' => $training->ratings->pluck('name'), ]; - }); + })->values(); } } diff --git a/app/Http/Controllers/DashboardController.php b/app/Http/Controllers/DashboardController.php index 134682d43..3f24fb1c0 100644 --- a/app/Http/Controllers/DashboardController.php +++ b/app/Http/Controllers/DashboardController.php @@ -70,9 +70,9 @@ public function index() $studentTrainings = \Auth::user()->mentoringTrainings(); - $cronJobError = ((App::environment('production')) && (\Carbon\Carbon::parse(Setting::get('lastCronRun')) <= \Carbon\Carbon::now()->subMinutes(5))); + $cronJobError = (($user->isAdmin() && App::environment('production')) && (\Carbon\Carbon::parse(Setting::get('_lastCronRun', '2000-01-01')) <= \Carbon\Carbon::now()->subMinutes(5))); - $oudatedVersionWarning = Setting::get('_updateAvailable'); + $oudatedVersionWarning = $user->isAdmin() && Setting::get('_updateAvailable'); return view('dashboard', compact('data', 'trainings', 'statuses', 'types', 'dueInterestRequest', 'atcInactiveMessage', 'completedTrainingMessage', 'activeVote', 'atcHours', 'workmailRenewal', 'studentTrainings', 'cronJobError', 'oudatedVersionWarning')); } diff --git a/config/app.php b/config/app.php index e1808ab4f..dd6f63272 100755 --- a/config/app.php +++ b/config/app.php @@ -25,7 +25,7 @@ | */ - 'version' => '4.1.0', + 'version' => '4.2.2', /* |-------------------------------------------------------------------------- diff --git a/database/migrations/2023_10_01_200047_add_cronjob_datetime.php b/database/migrations/2023_10_01_200047_add_cronjob_datetime.php index d0dc11ab9..47c6ff769 100644 --- a/database/migrations/2023_10_01_200047_add_cronjob_datetime.php +++ b/database/migrations/2023_10_01_200047_add_cronjob_datetime.php @@ -15,7 +15,7 @@ public function up() { Schema::table('settings', function (Blueprint $table) { DB::table(Config::get('settings.table'))->insert([ - ['key' => 'lastCronRun', 'value' => now()], + ['key' => '_lastCronRun', 'value' => now()], ]); }); } @@ -28,7 +28,7 @@ public function up() public function down() { Schema::table('settings', function (Blueprint $table) { - DB::table(Config::get('settings.table'))->where('key', 'lastCronRun')->delete(); + DB::table(Config::get('settings.table'))->where('key', '_lastCronRun')->delete(); }); } }; diff --git a/resources/views/admin/globalsettings.blade.php b/resources/views/admin/globalsettings.blade.php index 31c1c354d..ae046ced6 100644 --- a/resources/views/admin/globalsettings.blade.php +++ b/resources/views/admin/globalsettings.blade.php @@ -46,10 +46,10 @@
- +
- @if(\Carbon\Carbon::parse(Setting::get('lastCronRun')) > \Carbon\Carbon::now()->subMinutes(5)) + @if(\Carbon\Carbon::parse(Setting::get('_lastCronRun', '2000-01-01')) > \Carbon\Carbon::now()->subMinutes(5))