Store system first boot date in the database explicitly (#639)

The first plugin version record is unreliable, especially as plugins are added and removed; so this commit stores the first boot date in the database explicitly by using a database migration.
This commit is contained in:
Arvis Lācis 2022-08-11 20:12:45 +03:00 committed by GitHub
parent 916151f20c
commit 5cbf1ec653
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 3 deletions

View File

@ -0,0 +1,30 @@
<?php
use Winter\Storm\Database\Updates\Migration;
use Carbon\Carbon;
use System\Models\Parameter;
use System\Models\PluginVersion;
return new class extends Migration
{
public function up()
{
$appBirthday = Parameter::get('system::app.birthday');
if ($appBirthday) {
// Return early if the birthday has already been set
return;
}
$firstPluginCreated = PluginVersion::orderBy('created_at')
->first()
?->created_at;
$appBirthday = $firstPluginCreated ?: Carbon::now();
Parameter::set('system::app.birthday', $appBirthday);
}
public function down()
{
}
};

View File

@ -11,7 +11,6 @@ use Backend\Classes\ReportWidgetBase;
use Backend\Models\User;
use System\Models\EventLog;
use System\Models\RequestLog;
use System\Models\PluginVersion;
use Exception;
/**
@ -69,8 +68,7 @@ class Status extends ReportWidgetBase
$this->vars['requestLog'] = RequestLog::count();
$this->vars['requestLogMsg'] = LogSetting::get('log_requests', false) ? false : true;
// TODO: Store system boot date in `Parameter`
$this->vars['appBirthday'] = PluginVersion::orderBy('created_at')->first()?->created_at;
$this->vars['appBirthday'] = Parameter::get('system::app.birthday');
}
public function onLoadWarningsForm()