diff --git a/app/Http/Controllers/System/InstallController.php b/app/Http/Controllers/System/InstallController.php index 6e1e168d0a..f07f47758b 100644 --- a/app/Http/Controllers/System/InstallController.php +++ b/app/Http/Controllers/System/InstallController.php @@ -34,6 +34,7 @@ use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Cache; +use Illuminate\Support\Facades\Log; use Illuminate\View\View; use Laravel\Passport\Passport; use phpseclib3\Crypt\RSA; @@ -81,8 +82,10 @@ class InstallController extends Controller public function index() { app('view')->share('FF_VERSION', config('firefly.version')); + // index will set FF3 version. FireflyConfig::set('ff3_version', (string) config('firefly.version')); + FireflyConfig::set('ff3_build_time', (int) config('firefly.build_time')); return view('install.index'); } @@ -98,18 +101,18 @@ class InstallController extends Controller 'errorMessage' => null, ]; - app('log')->debug(sprintf('Will now run commands. Request index is %d', $requestIndex)); + Log::debug(sprintf('Will now run commands. Request index is %d', $requestIndex)); $indexes = array_keys($this->upgradeCommands); if (array_key_exists($requestIndex, $indexes)) { $command = $indexes[$requestIndex]; $parameters = $this->upgradeCommands[$command]; - app('log')->debug(sprintf('Will now execute command "%s" with parameters', $command), $parameters); + Log::debug(sprintf('Will now execute command "%s" with parameters', $command), $parameters); try { $result = $this->executeCommand($command, $parameters); } catch (FireflyException $e) { - app('log')->error($e->getMessage()); - app('log')->error($e->getTraceAsString()); + Log::error($e->getMessage()); + Log::error($e->getTraceAsString()); if (str_contains($e->getMessage(), 'open_basedir restriction in effect')) { $this->lastError = self::BASEDIR_ERROR; } @@ -134,7 +137,7 @@ class InstallController extends Controller */ private function executeCommand(string $command, array $args): bool { - app('log')->debug(sprintf('Will now call command %s with args.', $command), $args); + Log::debug(sprintf('Will now call command %s with args.', $command), $args); try { if ('generate-keys' === $command) { @@ -142,7 +145,7 @@ class InstallController extends Controller } if ('generate-keys' !== $command) { Artisan::call($command, $args); - app('log')->debug(Artisan::output()); + Log::debug(Artisan::output()); } } catch (Exception $e) { // intentional generic exception throw new FireflyException($e->getMessage(), 0, $e); diff --git a/app/Support/System/IsOldVersion.php b/app/Support/System/IsOldVersion.php index 2499debbe8..73fcf809ba 100644 --- a/app/Support/System/IsOldVersion.php +++ b/app/Support/System/IsOldVersion.php @@ -43,8 +43,8 @@ trait IsOldVersion return 0; } - $currentDate = Carbon::createFromFormat('!Y-m-d', $currentParts[1]); - $latestDate = Carbon::createFromFormat('!Y-m-d', $latestParts[1]); + $currentDate = Carbon::createFromFormat('!Y-m-d', $currentParts[1]); + $latestDate = Carbon::createFromFormat('!Y-m-d', $latestParts[1]); if ($currentDate->lt($latestDate)) { Log::debug(sprintf('This current version is older, current = %s, latest version %s.', $current, $latest)); @@ -67,33 +67,15 @@ trait IsOldVersion protected function isOldVersionInstalled(): bool { // version compare thing. - $configVersion = (string)config('firefly.version'); - $dbVersion = (string)FireflyConfig::getFresh('ff3_version', '1.0')->data; - $compare = 0; - // compare develop to develop - if (str_starts_with($configVersion, 'develop') && str_starts_with($dbVersion, 'develop')) { - $compare = $this->compareDevelopVersions($configVersion, $dbVersion); - } - // user has develop installed, goes to normal version. - if (!str_starts_with($configVersion, 'develop') && str_starts_with($dbVersion, 'develop')) { + $configBuildTime = (int)config('firefly.build_time'); + $dbBuildTime = (int)FireflyConfig::getFresh('ff3_build_time', 123)->data; + $configTime = Carbon::createFromTimestamp($configBuildTime, config('app.timezone')); + $dbTime = Carbon::createFromTimestamp($dbBuildTime, config('app.timezone')); + if ($dbBuildTime < $configBuildTime) { + Log::warning(sprintf('Your database was last managed by an older version of Firefly III (I see %s, I expect %s). Redirect to migrate routine.', $dbTime->format('Y-m-d H:i:s'), $configTime->format('Y-m-d H:i:s'),)); return true; } - - // user has normal, goes to develop version. - if (str_starts_with($configVersion, 'develop') && !str_starts_with($dbVersion, 'develop')) { - return true; - } - - // compare normal with normal. - if (!str_starts_with($configVersion, 'develop') && !str_starts_with($dbVersion, 'develop')) { - $compare = version_compare($configVersion, $dbVersion); - } - if (-1 === $compare) { - Log::warning(sprintf('The current configured Firefly III version (%s) is older than the required version (%s). Redirect to migrate routine.', $dbVersion, $configVersion)); - - return true; - } - + Log::debug(sprintf('Your database is up to date (I see %s, I expect %s).', $dbTime->format('Y-m-d H:i:s'), $configTime->format('Y-m-d H:i:s'),)); return false; } }