From 5cbf1ec6533c118b0c1692c95b5b10cfe105e03d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arvis=20L=C4=81cis?= Date: Thu, 11 Aug 2022 20:12:45 +0300 Subject: [PATCH] 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. --- ...000026_Db_System_Add_App_Birthday_Date.php | 30 +++++++++++++++++++ modules/system/reportwidgets/Status.php | 4 +-- 2 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 modules/system/database/migrations/2022_08_06_000026_Db_System_Add_App_Birthday_Date.php diff --git a/modules/system/database/migrations/2022_08_06_000026_Db_System_Add_App_Birthday_Date.php b/modules/system/database/migrations/2022_08_06_000026_Db_System_Add_App_Birthday_Date.php new file mode 100644 index 000000000..25aaf9b99 --- /dev/null +++ b/modules/system/database/migrations/2022_08_06_000026_Db_System_Add_App_Birthday_Date.php @@ -0,0 +1,30 @@ +first() + ?->created_at; + + $appBirthday = $firstPluginCreated ?: Carbon::now(); + + Parameter::set('system::app.birthday', $appBirthday); + } + + public function down() + { + } +}; diff --git a/modules/system/reportwidgets/Status.php b/modules/system/reportwidgets/Status.php index 4950dc10c..678cfcb12 100644 --- a/modules/system/reportwidgets/Status.php +++ b/modules/system/reportwidgets/Status.php @@ -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()