mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-15 08:35:00 +00:00
Stop using "db_version", check versions instead.
This commit is contained in:
@@ -26,16 +26,18 @@ namespace FireflyIII\Console\Commands\System;
|
|||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Support\System\GeneratesInstallationId;
|
use FireflyIII\Support\System\GeneratesInstallationId;
|
||||||
|
use FireflyIII\Support\System\IsOldVersion;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Random\RandomException;
|
use Random\RandomException;
|
||||||
|
|
||||||
class OutputsInstructions extends Command
|
class OutputsInstructions extends Command
|
||||||
{
|
{
|
||||||
use GeneratesInstallationId;
|
use GeneratesInstallationId;
|
||||||
|
use IsOldVersion;
|
||||||
|
|
||||||
protected $description = 'Instructions in case of upgrade trouble.';
|
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.
|
* Execute the console command.
|
||||||
@@ -58,26 +60,26 @@ class OutputsInstructions extends Command
|
|||||||
*/
|
*/
|
||||||
private function updateInstructions(): void
|
private function updateInstructions(): void
|
||||||
{
|
{
|
||||||
$version = (string) config('firefly.version');
|
$version = (string)config('firefly.version');
|
||||||
|
|
||||||
/** @var array $config */
|
/** @var array $config */
|
||||||
$config = config('upgrade.text.upgrade');
|
$config = config('upgrade.text.upgrade');
|
||||||
$text = '';
|
$text = '';
|
||||||
|
|
||||||
/** @var string $compare */
|
/** @var string $compare */
|
||||||
foreach (array_keys($config) as $compare) {
|
foreach (array_keys($config) as $compare) {
|
||||||
// if string starts with:
|
// if string starts with:
|
||||||
if (str_starts_with($version, $compare)) {
|
if (str_starts_with($version, $compare)) {
|
||||||
$text = (string) $config[$compare];
|
$text = (string)$config[$compare];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// validate some settings.
|
// 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.';
|
$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')) {
|
if (str_starts_with($version, 'develop') || str_starts_with($version, 'branch')) {
|
||||||
$prefix = '';
|
$prefix = '';
|
||||||
}
|
}
|
||||||
@@ -114,8 +116,8 @@ class OutputsInstructions extends Command
|
|||||||
*/
|
*/
|
||||||
private function showLogo(): void
|
private function showLogo(): void
|
||||||
{
|
{
|
||||||
$today = Carbon::now()->format('m-d');
|
$today = Carbon::now()->format('m-d');
|
||||||
$month = Carbon::now()->format('m');
|
$month = Carbon::now()->format('m');
|
||||||
// variation in colors and effects just because I can!
|
// variation in colors and effects just because I can!
|
||||||
// default is Ukraine flag:
|
// default is Ukraine flag:
|
||||||
$colors = ['blue', 'blue', 'blue', 'yellow', 'yellow', 'yellow', 'default', 'default'];
|
$colors = ['blue', 'blue', 'blue', 'yellow', 'yellow', 'yellow', 'default', 'default'];
|
||||||
@@ -164,7 +166,7 @@ class OutputsInstructions extends Command
|
|||||||
{
|
{
|
||||||
$parts = explode("\n", wordwrap($text));
|
$parts = explode("\n", wordwrap($text));
|
||||||
foreach ($parts as $string) {
|
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));
|
$parts = explode("\n", wordwrap($text));
|
||||||
foreach ($parts as $string) {
|
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
|
private function installInstructions(): void
|
||||||
{
|
{
|
||||||
$version = (string) config('firefly.version');
|
$version = (string)config('firefly.version');
|
||||||
|
|
||||||
/** @var array $config */
|
/** @var array $config */
|
||||||
$config = config('upgrade.text.install');
|
$config = config('upgrade.text.install');
|
||||||
$text = '';
|
$text = '';
|
||||||
|
|
||||||
/** @var string $compare */
|
/** @var string $compare */
|
||||||
foreach (array_keys($config) as $compare) {
|
foreach (array_keys($config) as $compare) {
|
||||||
// if string starts with:
|
// if string starts with:
|
||||||
if (str_starts_with($version, $compare)) {
|
if (str_starts_with($version, $compare)) {
|
||||||
$text = (string) $config[$compare];
|
$text = (string)$config[$compare];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// validate some settings.
|
// 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.';
|
$text = 'Please set APP_ENV=production for a safer environment.';
|
||||||
}
|
}
|
||||||
|
|
||||||
$prefix = 'v';
|
$prefix = 'v';
|
||||||
if (str_starts_with($version, 'develop')) {
|
if (str_starts_with($version, 'develop')) {
|
||||||
$prefix = '';
|
$prefix = '';
|
||||||
}
|
}
|
||||||
@@ -242,14 +244,15 @@ class OutputsInstructions extends Command
|
|||||||
|
|
||||||
private function someQuote(): void
|
private function someQuote(): void
|
||||||
{
|
{
|
||||||
$lines = [
|
$lines = [
|
||||||
'Forgive yourself for not being at peace.',
|
'"Forgive yourself for not being at peace."',
|
||||||
'Doesn\'t look like anything to me.',
|
'"Doesn\'t look like anything to me."',
|
||||||
'Be proud of what you make.',
|
'"Be proud of what you make."',
|
||||||
'Be there or forever wonder.',
|
'"Be there or forever wonder."',
|
||||||
'A year from now you will wish you had started today.',
|
'"A year from now you will wish you had started today."',
|
||||||
|
'🇺🇦 Слава Україні!',
|
||||||
|
'🇺🇦 Slava Ukraini!',
|
||||||
];
|
];
|
||||||
$addQuotes = true;
|
|
||||||
|
|
||||||
// fuck the Russian aggression in Ukraine.
|
// fuck the Russian aggression in Ukraine.
|
||||||
|
|
||||||
@@ -260,8 +263,7 @@ class OutputsInstructions extends Command
|
|||||||
// going on, to allow that to happen.
|
// going on, to allow that to happen.
|
||||||
|
|
||||||
if ('ru_RU' === config('firefly.default_language')) {
|
if ('ru_RU' === config('firefly.default_language')) {
|
||||||
$addQuotes = false;
|
$lines = [
|
||||||
$lines = [
|
|
||||||
'🇺🇦 Слава Україні!',
|
'🇺🇦 Слава Україні!',
|
||||||
'🇺🇦 Slava Ukraini!',
|
'🇺🇦 Slava Ukraini!',
|
||||||
];
|
];
|
||||||
@@ -272,11 +274,6 @@ class OutputsInstructions extends Command
|
|||||||
} catch (RandomException) {
|
} catch (RandomException) {
|
||||||
$random = 0;
|
$random = 0;
|
||||||
}
|
}
|
||||||
if ($addQuotes) {
|
|
||||||
$this->line(sprintf(' "%s"', $lines[$random]));
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$this->line(sprintf(' %s', $lines[$random]));
|
$this->line(sprintf(' %s', $lines[$random]));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -26,6 +26,8 @@ namespace FireflyIII\Http\Middleware;
|
|||||||
|
|
||||||
use Closure;
|
use Closure;
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
|
use FireflyIII\Support\FireflyConfig;
|
||||||
|
use FireflyIII\Support\System\IsOldVersion;
|
||||||
use FireflyIII\Support\System\OAuthKeys;
|
use FireflyIII\Support\System\OAuthKeys;
|
||||||
use Illuminate\Database\QueryException;
|
use Illuminate\Database\QueryException;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
@@ -37,6 +39,7 @@ use Illuminate\Support\Facades\Log;
|
|||||||
*/
|
*/
|
||||||
class Installer
|
class Installer
|
||||||
{
|
{
|
||||||
|
use IsOldVersion;
|
||||||
/**
|
/**
|
||||||
* Handle an incoming request.
|
* Handle an incoming request.
|
||||||
*
|
*
|
||||||
@@ -65,7 +68,7 @@ class Installer
|
|||||||
// run installer when no tables are present,
|
// run installer when no tables are present,
|
||||||
// or when old scheme version
|
// or when old scheme version
|
||||||
// or when old firefly version
|
// or when old firefly version
|
||||||
if ($this->hasNoTables() || $this->oldDBVersion() || $this->oldVersion()) {
|
if ($this->hasNoTables() || $this->isOldVersionInstalled()) {
|
||||||
return response()->redirectTo(route('installer.index'));
|
return response()->redirectTo(route('installer.index'));
|
||||||
}
|
}
|
||||||
OAuthKeys::verifyKeysRoutine();
|
OAuthKeys::verifyKeysRoutine();
|
||||||
@@ -126,59 +129,4 @@ class Installer
|
|||||||
{
|
{
|
||||||
return false !== stripos($message, 'Base table or view not found');
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -26,6 +26,7 @@ namespace FireflyIII\Services\FireflyIIIOrg\Update;
|
|||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Events\NewVersionAvailable;
|
use FireflyIII\Events\NewVersionAvailable;
|
||||||
|
use FireflyIII\Support\System\IsOldVersion;
|
||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
use GuzzleHttp\Exception\GuzzleException;
|
use GuzzleHttp\Exception\GuzzleException;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
@@ -38,6 +39,7 @@ use function Safe\json_decode;
|
|||||||
*/
|
*/
|
||||||
class UpdateRequest implements UpdateRequestInterface
|
class UpdateRequest implements UpdateRequestInterface
|
||||||
{
|
{
|
||||||
|
use IsOldVersion;
|
||||||
public function getUpdateInformation(string $channel): array
|
public function getUpdateInformation(string $channel): array
|
||||||
{
|
{
|
||||||
Log::debug(sprintf('Now in getUpdateInformation(%s)', $channel));
|
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
|
private function parseResultDevelop(string $current, string $latest, array $information): array
|
||||||
{
|
{
|
||||||
Log::debug(sprintf('User is running develop version "%s"', $current));
|
Log::debug(sprintf('User is running develop version "%s"', $current));
|
||||||
$parts = explode('/', $current);
|
$compare = $this->compareDevelopVersions($current, $latest);
|
||||||
$return = [];
|
$return = [];
|
||||||
|
|
||||||
/** @var Carbon $devDate */
|
if (-1 === $compare) {
|
||||||
$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')));
|
|
||||||
$return['level'] = 'info';
|
$return['level'] = 'info';
|
||||||
$return['message'] = (string) trans('firefly.update_current_dev_older', ['version' => $current, 'new_version' => $latest]);
|
$return['message'] = (string) trans('firefly.update_current_dev_older', ['version' => $current, 'new_version' => $latest]);
|
||||||
|
|
||||||
return $return;
|
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['level'] = 'info';
|
||||||
$return['message'] = (string) trans('firefly.update_current_dev_newer', ['version' => $current, 'new_version' => $latest]);
|
$return['message'] = (string) trans('firefly.update_current_dev_newer', ['version' => $current, 'new_version' => $latest]);
|
||||||
|
|
||||||
|
94
app/Support/System/IsOldVersion.php
Normal file
94
app/Support/System/IsOldVersion.php
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* IsOldVersion.php
|
||||||
|
* Copyright (c) 2025 james@firefly-iii.org
|
||||||
|
*
|
||||||
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
@@ -81,7 +81,7 @@ return [
|
|||||||
'version' => 'develop/2025-09-29',
|
'version' => 'develop/2025-09-29',
|
||||||
'build_time' => 1759116036,
|
'build_time' => 1759116036,
|
||||||
'api_version' => '2.1.0', // field is no longer used.
|
'api_version' => '2.1.0', // field is no longer used.
|
||||||
'db_version' => 27,
|
'db_version' => 28,
|
||||||
|
|
||||||
// generic settings
|
// generic settings
|
||||||
'maxUploadSize' => 1073741824, // 1 GB
|
'maxUploadSize' => 1073741824, // 1 GB
|
||||||
|
Reference in New Issue
Block a user