diff --git a/app/Console/Commands/System/OutputsInstructions.php b/app/Console/Commands/System/OutputsInstructions.php index fb99e99692..1e8c0b6d80 100644 --- a/app/Console/Commands/System/OutputsInstructions.php +++ b/app/Console/Commands/System/OutputsInstructions.php @@ -26,16 +26,18 @@ namespace FireflyIII\Console\Commands\System; use Carbon\Carbon; use FireflyIII\Support\System\GeneratesInstallationId; +use FireflyIII\Support\System\IsOldVersion; use Illuminate\Console\Command; use Random\RandomException; class OutputsInstructions extends Command { use GeneratesInstallationId; + use IsOldVersion; protected $description = 'Instructions in case of upgrade trouble.'; - protected $signature = 'firefly-iii:instructions {task=install}'; + protected $signature = 'firefly-iii:instructions {task=install}'; /** * Execute the console command. @@ -58,26 +60,26 @@ class OutputsInstructions extends Command */ private function updateInstructions(): void { - $version = (string) config('firefly.version'); + $version = (string)config('firefly.version'); /** @var array $config */ - $config = config('upgrade.text.upgrade'); - $text = ''; + $config = config('upgrade.text.upgrade'); + $text = ''; /** @var string $compare */ foreach (array_keys($config) as $compare) { // if string starts with: if (str_starts_with($version, $compare)) { - $text = (string) $config[$compare]; + $text = (string)$config[$compare]; } } // validate some settings. - if ('' === $text && 'local' === (string) config('app.env')) { + if ('' === $text && 'local' === (string)config('app.env')) { $text = 'Please set APP_ENV=production for a safer environment.'; } - $prefix = 'v'; + $prefix = 'v'; if (str_starts_with($version, 'develop') || str_starts_with($version, 'branch')) { $prefix = ''; } @@ -114,8 +116,8 @@ class OutputsInstructions extends Command */ private function showLogo(): void { - $today = Carbon::now()->format('m-d'); - $month = Carbon::now()->format('m'); + $today = Carbon::now()->format('m-d'); + $month = Carbon::now()->format('m'); // variation in colors and effects just because I can! // default is Ukraine flag: $colors = ['blue', 'blue', 'blue', 'yellow', 'yellow', 'yellow', 'default', 'default']; @@ -164,7 +166,7 @@ class OutputsInstructions extends Command { $parts = explode("\n", wordwrap($text)); foreach ($parts as $string) { - $this->line('| '.sprintf('%-77s', $string).'|'); + $this->line('| ' . sprintf('%-77s', $string) . '|'); } } @@ -175,7 +177,7 @@ class OutputsInstructions extends Command { $parts = explode("\n", wordwrap($text)); foreach ($parts as $string) { - $this->info('| '.sprintf('%-77s', $string).'|'); + $this->info('| ' . sprintf('%-77s', $string) . '|'); } } @@ -191,26 +193,26 @@ class OutputsInstructions extends Command */ private function installInstructions(): void { - $version = (string) config('firefly.version'); + $version = (string)config('firefly.version'); /** @var array $config */ - $config = config('upgrade.text.install'); - $text = ''; + $config = config('upgrade.text.install'); + $text = ''; /** @var string $compare */ foreach (array_keys($config) as $compare) { // if string starts with: if (str_starts_with($version, $compare)) { - $text = (string) $config[$compare]; + $text = (string)$config[$compare]; } } // validate some settings. - if ('' === $text && 'local' === (string) config('app.env')) { + if ('' === $text && 'local' === (string)config('app.env')) { $text = 'Please set APP_ENV=production for a safer environment.'; } - $prefix = 'v'; + $prefix = 'v'; if (str_starts_with($version, 'develop')) { $prefix = ''; } @@ -242,14 +244,15 @@ class OutputsInstructions extends Command private function someQuote(): void { - $lines = [ - 'Forgive yourself for not being at peace.', - 'Doesn\'t look like anything to me.', - 'Be proud of what you make.', - 'Be there or forever wonder.', - 'A year from now you will wish you had started today.', + $lines = [ + '"Forgive yourself for not being at peace."', + '"Doesn\'t look like anything to me."', + '"Be proud of what you make."', + '"Be there or forever wonder."', + '"A year from now you will wish you had started today."', + '🇺🇦 Слава Україні!', + '🇺🇦 Slava Ukraini!', ]; - $addQuotes = true; // fuck the Russian aggression in Ukraine. @@ -260,8 +263,7 @@ class OutputsInstructions extends Command // going on, to allow that to happen. if ('ru_RU' === config('firefly.default_language')) { - $addQuotes = false; - $lines = [ + $lines = [ '🇺🇦 Слава Україні!', '🇺🇦 Slava Ukraini!', ]; @@ -272,11 +274,6 @@ class OutputsInstructions extends Command } catch (RandomException) { $random = 0; } - if ($addQuotes) { - $this->line(sprintf(' "%s"', $lines[$random])); - - return; - } $this->line(sprintf(' %s', $lines[$random])); } diff --git a/app/Http/Middleware/Installer.php b/app/Http/Middleware/Installer.php index f7d38232ca..79f9494929 100644 --- a/app/Http/Middleware/Installer.php +++ b/app/Http/Middleware/Installer.php @@ -26,6 +26,8 @@ namespace FireflyIII\Http\Middleware; use Closure; use FireflyIII\Exceptions\FireflyException; +use FireflyIII\Support\FireflyConfig; +use FireflyIII\Support\System\IsOldVersion; use FireflyIII\Support\System\OAuthKeys; use Illuminate\Database\QueryException; use Illuminate\Http\Request; @@ -37,6 +39,7 @@ use Illuminate\Support\Facades\Log; */ class Installer { + use IsOldVersion; /** * Handle an incoming request. * @@ -65,7 +68,7 @@ class Installer // run installer when no tables are present, // or when old scheme version // or when old firefly version - if ($this->hasNoTables() || $this->oldDBVersion() || $this->oldVersion()) { + if ($this->hasNoTables() || $this->isOldVersionInstalled()) { return response()->redirectTo(route('installer.index')); } OAuthKeys::verifyKeysRoutine(); @@ -126,59 +129,4 @@ class Installer { return false !== stripos($message, 'Base table or view not found'); } - - /** - * Check if the "db_version" variable is correct. - */ - private function oldDBVersion(): bool - { - // older version in config than database? - $configVersion = (int) config('firefly.db_version'); - $dbVersion = (int) app('fireflyconfig')->getFresh('db_version', 1)->data; - if ($configVersion > $dbVersion) { - Log::warning( - sprintf( - 'The current configured version (%d) is older than the required version (%d). Redirect to migrate routine.', - $dbVersion, - $configVersion - ) - ); - - return true; - } - - // Log::info(sprintf('Configured DB version (%d) equals expected DB version (%d)', $dbVersion, $configVersion)); - - return false; - } - - /** - * Check if the "firefly_version" variable is correct. - */ - private function oldVersion(): bool - { - // version compare thing. - $configVersion = (string) config('firefly.version'); - $dbVersion = (string) app('fireflyconfig')->getFresh('ff3_version', '1.0')->data; - if (str_starts_with($configVersion, 'develop')) { - Log::debug('Skipping version check for develop version.'); - - return false; - } - if (1 === version_compare($configVersion, $dbVersion)) { - 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::info(sprintf('Installed Firefly III version (%s) equals expected Firefly III version (%s)', $dbVersion, $configVersion)); - - return false; - } } diff --git a/app/Services/FireflyIIIOrg/Update/UpdateRequest.php b/app/Services/FireflyIIIOrg/Update/UpdateRequest.php index 9516071ddb..b2c806a966 100644 --- a/app/Services/FireflyIIIOrg/Update/UpdateRequest.php +++ b/app/Services/FireflyIIIOrg/Update/UpdateRequest.php @@ -26,6 +26,7 @@ namespace FireflyIII\Services\FireflyIIIOrg\Update; use Carbon\Carbon; use FireflyIII\Events\NewVersionAvailable; +use FireflyIII\Support\System\IsOldVersion; use GuzzleHttp\Client; use GuzzleHttp\Exception\GuzzleException; use Illuminate\Support\Facades\Log; @@ -38,6 +39,7 @@ use function Safe\json_decode; */ class UpdateRequest implements UpdateRequestInterface { + use IsOldVersion; public function getUpdateInformation(string $channel): array { Log::debug(sprintf('Now in getUpdateInformation(%s)', $channel)); @@ -183,20 +185,15 @@ class UpdateRequest implements UpdateRequestInterface private function parseResultDevelop(string $current, string $latest, array $information): array { Log::debug(sprintf('User is running develop version "%s"', $current)); - $parts = explode('/', $current); + $compare = $this->compareDevelopVersions($current, $latest); $return = []; - /** @var Carbon $devDate */ - $devDate = Carbon::createFromFormat('Y-m-d', $parts[1]); - - if ($devDate->lte($information['date'])) { - Log::debug(sprintf('This development release is older, release = %s, latest version %s = %s', $devDate->format('Y-m-d'), $latest, $information['date']->format('Y-m-d'))); + if (-1 === $compare) { $return['level'] = 'info'; $return['message'] = (string) trans('firefly.update_current_dev_older', ['version' => $current, 'new_version' => $latest]); return $return; } - Log::debug(sprintf('This development release is newer, release = %s, latest version %s = %s', $devDate->format('Y-m-d'), $latest, $information['date']->format('Y-m-d'))); $return['level'] = 'info'; $return['message'] = (string) trans('firefly.update_current_dev_newer', ['version' => $current, 'new_version' => $latest]); diff --git a/app/Support/System/IsOldVersion.php b/app/Support/System/IsOldVersion.php new file mode 100644 index 0000000000..175a8ed7fa --- /dev/null +++ b/app/Support/System/IsOldVersion.php @@ -0,0 +1,94 @@ +. + */ + +namespace FireflyIII\Support\System; + +use Carbon\Carbon; +use FireflyIII\Support\Facades\FireflyConfig; +use Illuminate\Support\Facades\Log; + +trait IsOldVersion +{ + + /** + * By default, version_compare() returns -1 if the first version is lower than the second, 0 if they are equal, and + * 1 if the second is lower. + */ + protected function compareDevelopVersions(string $current, string $latest): int + { + $currentParts = explode('/', $current); + $latestParts = explode('/', $latest); + if (2 !== count($currentParts) || 2 !== count($latestParts)) { + Log::error(sprintf('Version "%s" or "%s" is not a valid develop-version.', $current, $latest)); + return 0; + } + + $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)); + return -1; + } + if ($currentDate->gt($latestDate)) { + Log::debug(sprintf('This current version is newer, current = %s, latest version %s.', $current, $latest)); + return 1; + } + Log::debug(sprintf('This current version is of the same age, current = %s, latest version %s.', $current, $latest)); + + return 0; + } + + /** + * Check if the "firefly_version" variable is correct. + */ + 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')) { + 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; + } + return false; + } +} diff --git a/config/firefly.php b/config/firefly.php index d3ff9f679b..7b1af7a67a 100644 --- a/config/firefly.php +++ b/config/firefly.php @@ -81,7 +81,7 @@ return [ 'version' => 'develop/2025-09-29', 'build_time' => 1759116036, 'api_version' => '2.1.0', // field is no longer used. - 'db_version' => 27, + 'db_version' => 28, // generic settings 'maxUploadSize' => 1073741824, // 1 GB