. */ declare(strict_types=1); namespace FireflyIII\Handlers\Events; use FireflyConfig; use FireflyIII\User; use Illuminate\Auth\Events\Login; use Log; /** * Class VersionCheckEventHandler */ class VersionCheckEventHandler { /** * @param Login $event */ public function checkForUpdates(Login $event) { // in Sandstorm, cannot check for updates: $sandstorm = 1 === intval(getenv('SANDSTORM')); if ($sandstorm === true) { return; } /** @var User $user */ $user = $event->user; if (!$user->hasRole('owner')) { return; } $permission = FireflyConfig::get('permission_update_check', -1); $lastCheckTime = FireflyConfig::get('last_update_check', time()); $now = time(); if ($now - $lastCheckTime->data < 604800) { Log::debug('Checked for updates less than a week ago.'); return; } // last check time was more than a week ago. Log::debug('Have not checked for a new version in a week!'); // have actual permission? if ($permission->data === -1) { // never asked before. session()->flash('info', strval(trans('firefly.check_for_updates_permission', ['link' => route('admin.update-check')]))); return; } } }