From 782ecca6a93cef85ad52a35880fb05ff50c80194 Mon Sep 17 00:00:00 2001 From: James Cole Date: Wed, 20 May 2020 06:40:18 +0200 Subject: [PATCH] Warning if people disabled update checking. Every 4 weeks. --- .../Events/VersionCheckEventHandler.php | 33 +++++++++++++++++++ resources/lang/en_US/firefly.php | 1 + 2 files changed, 34 insertions(+) diff --git a/app/Handlers/Events/VersionCheckEventHandler.php b/app/Handlers/Events/VersionCheckEventHandler.php index 2af01ca01f..3c068ffade 100644 --- a/app/Handlers/Events/VersionCheckEventHandler.php +++ b/app/Handlers/Events/VersionCheckEventHandler.php @@ -54,6 +54,7 @@ class VersionCheckEventHandler $value = (int) $permission->data; if (1 !== $value) { Log::info('Update check is not enabled.'); + $this->warnToCheckForUpdates($event); return; } @@ -85,4 +86,36 @@ class VersionCheckEventHandler session()->flash($release['level'], $release['message']); app('fireflyconfig')->set('last_update_check', time()); } + + /** + * @param RequestedVersionCheckStatus $event + */ + protected function warnToCheckForUpdates(RequestedVersionCheckStatus $event): void + { + /** @var UserRepositoryInterface $repository */ + $repository = app(UserRepositoryInterface::class); + /** @var User $user */ + $user = $event->user; + if (!$repository->hasRole($user, 'owner')) { + Log::debug('User is not admin, done.'); + + return; + } + + /** @var Configuration $lastCheckTime */ + $lastCheckTime = app('fireflyconfig')->get('last_update_warning', time()); + $now = time(); + $diff = $now - $lastCheckTime->data; + Log::debug(sprintf('Last warning time is %d, current time is %d, difference is %d', $lastCheckTime->data, $now, $diff)); + if ($diff < 604800 * 4) { + Log::debug(sprintf('Warned about updates less than four weeks ago (on %s).', date('Y-m-d H:i:s', $lastCheckTime->data))); + + return; + } + // last check time was more than a week ago. + Log::debug('Have warned about a new version in four weeks!'); + + session()->flash('info', (string) trans('firefly.disabled_but_check')); + app('fireflyconfig')->set('last_update_warning', time()); + } } diff --git a/resources/lang/en_US/firefly.php b/resources/lang/en_US/firefly.php index cec412bce1..6a68404391 100644 --- a/resources/lang/en_US/firefly.php +++ b/resources/lang/en_US/firefly.php @@ -242,6 +242,7 @@ return [ 'update_check_error' => 'An error occurred while checking for updates: :error', 'unknown_error' => 'Unknown error. Sorry about that.', 'just_new_release' => 'A new version is available! Version :version was released :date. This release is very fresh. Wait a few days for the new release to stabilize.', + 'disabled_but_check' => 'You disabled update checking. So don\'t forget to check for updates yourself every now and then. Thank you!', 'admin_update_channel_title' => 'Update channel', 'admin_update_channel_explain' => 'Firefly III has three update "channels" which determine how ahead of the curve you are in terms of features, enhancements and bugs. Use the "beta" channel if you\'re adventurous and the "alpha" when you like to live life dangerously.', 'update_channel_stable' => 'Stable. Everything should work as expected.',