From e90efd375973435440cf58549bb6d141e7338ca7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20D?= Date: Thu, 24 Jan 2019 14:13:34 +0100 Subject: [PATCH] * [FIX] Upgrade not needed when updating between v3 releases. Thanks to @vmarion89 for the feedback. Closes #1210 --- app/modules/api/Init.php | 4 +++- .../web/Controllers/UpgradeController.php | 24 +++++++++++++------ app/modules/web/Init.php | 5 +++- lib/SP/Services/Install/Installer.php | 4 ++-- lib/SP/Services/Upgrade/UpgradeUtil.php | 20 ++++++++++++++++ 5 files changed, 46 insertions(+), 11 deletions(-) diff --git a/app/modules/api/Init.php b/app/modules/api/Init.php index 69b18623..cf3150e5 100644 --- a/app/modules/api/Init.php +++ b/app/modules/api/Init.php @@ -141,9 +141,11 @@ final class Init extends ModuleBase */ private function checkUpgrade() { + UpgradeUtil::fixAppUpgrade($this->configData, $this->config); + if ($this->configData->getUpgradeKey() || (UpgradeDatabaseService::needsUpgrade($this->configData->getDatabaseVersion()) || - UpgradeAppService::needsUpgrade(UpgradeUtil::fixVersionNumber($this->configData->getAppVersion()))) + UpgradeAppService::needsUpgrade($this->configData->getAppVersion())) ) { $this->config->generateUpgradeKey(); diff --git a/app/modules/web/Controllers/UpgradeController.php b/app/modules/web/Controllers/UpgradeController.php index eef3a4eb..49e4c677 100644 --- a/app/modules/web/Controllers/UpgradeController.php +++ b/app/modules/web/Controllers/UpgradeController.php @@ -30,7 +30,6 @@ use SP\Modules\Web\Controllers\Helpers\LayoutHelper; use SP\Modules\Web\Controllers\Traits\JsonTrait; use SP\Services\Upgrade\UpgradeAppService; use SP\Services\Upgrade\UpgradeDatabaseService; -use SP\Services\Upgrade\UpgradeUtil; /** * Class UpgradeController @@ -64,14 +63,19 @@ final class UpgradeController extends ControllerBase public function upgradeAction() { if ($this->request->analyzeBool('chkConfirm', false) === false) { - return $this->returnJsonResponse(JsonResponse::JSON_ERROR, __u('The updating need to be confirmed')); + return $this->returnJsonResponse( + JsonResponse::JSON_ERROR, + __u('The updating need to be confirmed') + ); } if ($this->request->analyzeString('key') !== $this->configData->getUpgradeKey()) { - return $this->returnJsonResponse(JsonResponse::JSON_ERROR, __u('Wrong security code')); + return $this->returnJsonResponse( + JsonResponse::JSON_ERROR, + __u('Wrong security code') + ); } - try { $dbVersion = $this->configData->getDatabaseVersion(); $dbVersion = empty($dbVersion) ? '0.0' : $dbVersion; @@ -81,15 +85,21 @@ final class UpgradeController extends ControllerBase ->upgrade($dbVersion, $this->configData); } - if (UpgradeAppService::needsUpgrade(UpgradeUtil::fixVersionNumber($this->configData->getAppVersion()))) { + $appVersion = $this->configData->getAppVersion(); + + if (UpgradeAppService::needsUpgrade($appVersion)) { $this->dic->get(UpgradeAppService::class) - ->upgrade(UpgradeUtil::fixVersionNumber($this->configData->getAppVersion()), $this->configData); + ->upgrade($appVersion, $this->configData); } $this->configData->setUpgradeKey(null); $this->config->saveConfig($this->configData, false); - return $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Application successfully updated'), [__u('You will be redirected to log in within 5 seconds')]); + return $this->returnJsonResponse( + JsonResponse::JSON_SUCCESS, + __u('Application successfully updated'), + [__u('You will be redirected to log in within 5 seconds')] + ); } catch (\Exception $e) { processException($e); diff --git a/app/modules/web/Init.php b/app/modules/web/Init.php index 34af7383..c4e064b8 100644 --- a/app/modules/web/Init.php +++ b/app/modules/web/Init.php @@ -280,12 +280,15 @@ final class Init extends ModuleBase /** * Comprobar si es necesario actualizar componentes + * @throws \SP\Storage\File\FileException */ private function checkUpgrade() { + UpgradeUtil::fixAppUpgrade($this->configData, $this->config); + return $this->configData->getUpgradeKey() || (UpgradeDatabaseService::needsUpgrade($this->configData->getDatabaseVersion()) || - UpgradeAppService::needsUpgrade(UpgradeUtil::fixVersionNumber($this->configData->getAppVersion()))); + UpgradeAppService::needsUpgrade($this->configData->getAppVersion())); } /** diff --git a/lib/SP/Services/Install/Installer.php b/lib/SP/Services/Install/Installer.php index 8d3f1f8a..97c1206a 100644 --- a/lib/SP/Services/Install/Installer.php +++ b/lib/SP/Services/Install/Installer.php @@ -54,9 +54,9 @@ final class Installer extends Service /** * sysPass' version and build number */ - const VERSION = [3, 0, 2]; + const VERSION = [3, 0, 3]; const VERSION_TEXT = '3.0'; - const BUILD = 19012401; + const BUILD = 19012402; /** * @var DatabaseSetupInterface diff --git a/lib/SP/Services/Upgrade/UpgradeUtil.php b/lib/SP/Services/Upgrade/UpgradeUtil.php index 17625689..3470814a 100644 --- a/lib/SP/Services/Upgrade/UpgradeUtil.php +++ b/lib/SP/Services/Upgrade/UpgradeUtil.php @@ -25,7 +25,9 @@ namespace SP\Services\Upgrade; use SP\Config\Config; +use SP\Config\ConfigData; use SP\Util\PasswordUtil; +use SP\Util\VersionUtil; /** * Class UpgradeUtil @@ -76,4 +78,22 @@ final class UpgradeUtil $configData->setMaintenance(true); $config->saveConfig($configData, false); } + + /** + * @param ConfigData $configData + * @param Config $config + * @throws \SP\Storage\File\FileException + */ + public static function fixAppUpgrade(ConfigData $configData, Config $config) + { + // Fixes bug in 3.0.X version where some updates weren't applied + // when upgrading from v2 + // $dbVersion is always '' when upgrading from v2 + if (!empty($configData->getDatabaseVersion()) + && empty($configData->getAppVersion()) + ) { + $configData->setAppVersion(VersionUtil::getVersionStringNormalized()); + $config->saveConfig($configData, false); + } + } } \ No newline at end of file