Skip to content

Commit

Permalink
Rebase feat/tasks (#642)
Browse files Browse the repository at this point in the history
* 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 🍻

* fix: display cron/version warnings only to admins
  • Loading branch information
blt950 authored Oct 4, 2023
1 parent ef8d886 commit f958c9b
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 17 deletions.
22 changes: 14 additions & 8 deletions app/Console/Commands/CheckUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/API/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,6 @@ private function mapTrainings(Collection $trainings)
'started_at' => $training->started_at,
'ratings' => $training->ratings->pluck('name'),
];
});
})->values();
}
}
4 changes: 2 additions & 2 deletions app/Http/Controllers/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
Expand Down
2 changes: 1 addition & 1 deletion config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
|
*/

'version' => '4.1.0',
'version' => '4.2.2',

/*
|--------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()],
]);
});
}
Expand All @@ -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();
});
}
};
4 changes: 2 additions & 2 deletions resources/views/admin/globalsettings.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@

<div class="mb-4">
<label class="form-label" for="spoUrl">Last Cronjob Run</label>
<input type="text" class="form-control" required value="{{ \Carbon\Carbon::parse(Setting::get('lastCronRun'))->diffForHumans() }}" disabled>
<input type="text" class="form-control" required value="{{ \Carbon\Carbon::parse(Setting::get('_lastCronRun', '2000-01-01'))->diffForHumans() }}" disabled>
</div>

@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))
<div class="alert alert-success" role="alert">
Cronjob is running as expected
</div>
Expand Down

0 comments on commit f958c9b

Please sign in to comment.