Validate version using build_time.

This commit is contained in:
James Cole
2025-10-11 06:45:16 +02:00
parent cbf7aef0c1
commit 1fe0aebacb
2 changed files with 18 additions and 33 deletions

View File

@@ -34,6 +34,7 @@ use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Log;
use Illuminate\View\View; use Illuminate\View\View;
use Laravel\Passport\Passport; use Laravel\Passport\Passport;
use phpseclib3\Crypt\RSA; use phpseclib3\Crypt\RSA;
@@ -81,8 +82,10 @@ class InstallController extends Controller
public function index() public function index()
{ {
app('view')->share('FF_VERSION', config('firefly.version')); app('view')->share('FF_VERSION', config('firefly.version'));
// index will set FF3 version. // index will set FF3 version.
FireflyConfig::set('ff3_version', (string) config('firefly.version')); FireflyConfig::set('ff3_version', (string) config('firefly.version'));
FireflyConfig::set('ff3_build_time', (int) config('firefly.build_time'));
return view('install.index'); return view('install.index');
} }
@@ -98,18 +101,18 @@ class InstallController extends Controller
'errorMessage' => null, '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); $indexes = array_keys($this->upgradeCommands);
if (array_key_exists($requestIndex, $indexes)) { if (array_key_exists($requestIndex, $indexes)) {
$command = $indexes[$requestIndex]; $command = $indexes[$requestIndex];
$parameters = $this->upgradeCommands[$command]; $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 { try {
$result = $this->executeCommand($command, $parameters); $result = $this->executeCommand($command, $parameters);
} catch (FireflyException $e) { } catch (FireflyException $e) {
app('log')->error($e->getMessage()); Log::error($e->getMessage());
app('log')->error($e->getTraceAsString()); Log::error($e->getTraceAsString());
if (str_contains($e->getMessage(), 'open_basedir restriction in effect')) { if (str_contains($e->getMessage(), 'open_basedir restriction in effect')) {
$this->lastError = self::BASEDIR_ERROR; $this->lastError = self::BASEDIR_ERROR;
} }
@@ -134,7 +137,7 @@ class InstallController extends Controller
*/ */
private function executeCommand(string $command, array $args): bool 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 { try {
if ('generate-keys' === $command) { if ('generate-keys' === $command) {
@@ -142,7 +145,7 @@ class InstallController extends Controller
} }
if ('generate-keys' !== $command) { if ('generate-keys' !== $command) {
Artisan::call($command, $args); Artisan::call($command, $args);
app('log')->debug(Artisan::output()); Log::debug(Artisan::output());
} }
} catch (Exception $e) { // intentional generic exception } catch (Exception $e) { // intentional generic exception
throw new FireflyException($e->getMessage(), 0, $e); throw new FireflyException($e->getMessage(), 0, $e);

View File

@@ -43,8 +43,8 @@ trait IsOldVersion
return 0; return 0;
} }
$currentDate = Carbon::createFromFormat('!Y-m-d', $currentParts[1]); $currentDate = Carbon::createFromFormat('!Y-m-d', $currentParts[1]);
$latestDate = Carbon::createFromFormat('!Y-m-d', $latestParts[1]); $latestDate = Carbon::createFromFormat('!Y-m-d', $latestParts[1]);
if ($currentDate->lt($latestDate)) { if ($currentDate->lt($latestDate)) {
Log::debug(sprintf('This current version is older, current = %s, latest version %s.', $current, $latest)); 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 protected function isOldVersionInstalled(): bool
{ {
// version compare thing. // version compare thing.
$configVersion = (string)config('firefly.version'); $configBuildTime = (int)config('firefly.build_time');
$dbVersion = (string)FireflyConfig::getFresh('ff3_version', '1.0')->data; $dbBuildTime = (int)FireflyConfig::getFresh('ff3_build_time', 123)->data;
$compare = 0; $configTime = Carbon::createFromTimestamp($configBuildTime, config('app.timezone'));
// compare develop to develop $dbTime = Carbon::createFromTimestamp($dbBuildTime, config('app.timezone'));
if (str_starts_with($configVersion, 'develop') && str_starts_with($dbVersion, 'develop')) { if ($dbBuildTime < $configBuildTime) {
$compare = $this->compareDevelopVersions($configVersion, $dbVersion); 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'),));
}
// user has develop installed, goes to normal version.
if (!str_starts_with($configVersion, 'develop') && str_starts_with($dbVersion, 'develop')) {
return true; 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'),));
// 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; return false;
} }
} }