From 533ce665af6e08a2b1b33d39a273070047c2ae70 Mon Sep 17 00:00:00 2001 From: Clemente Raposo Date: Fri, 31 Dec 2021 15:04:07 +0000 Subject: [PATCH] Add Upgrade Finalize Stage - Split upgrade into 2 stages: install, finalize -- This is required as the container needs to be re-loaded before running the final step - From now on 2 commands will need to be executed --- config/core_services.yaml | 6 ++ .../Command/UpgradeFinalizeCommand.php | 93 +++++++++++++++++++ .../Service/Upgrade/Steps/CheckPackage.php | 9 ++ .../Upgrade/Steps/CheckPermissions.php | 9 ++ .../Upgrade/Steps/ClearSymfonyCache.php | 11 ++- .../Service/Upgrade/Steps/ExtractPackage.php | 9 ++ .../Upgrade/Steps/InstallUpgradePackage.php | 9 ++ .../Upgrade/Steps/LegacyPostUpgrade.php | 11 ++- .../Service/Upgrade/Steps/RunMigrations.php | 11 ++- .../Upgrade/UpgradeFinalizeHandler.php | 58 ++++++++++++ .../UpgradeFinalizeHandlerInterface.php | 39 ++++++++ .../Service/Upgrade/UpgradeHandler.php | 12 ++- .../Service/Upgrade/UpgradeStepInterface.php | 6 ++ 13 files changed, 279 insertions(+), 4 deletions(-) create mode 100644 core/backend/Install/Command/UpgradeFinalizeCommand.php create mode 100644 core/backend/Install/Service/Upgrade/UpgradeFinalizeHandler.php create mode 100644 core/backend/Install/Service/Upgrade/UpgradeFinalizeHandlerInterface.php diff --git a/config/core_services.yaml b/config/core_services.yaml index 509f2816d..6c86561ec 100644 --- a/config/core_services.yaml +++ b/config/core_services.yaml @@ -217,6 +217,12 @@ services: - !tagged { tag: 'app.upgrade.step' } - '@monolog.logger.upgrade' + App\Install\Service\Upgrade\UpgradeFinalizeHandler: + # inject all services tagged with app.upgrade.step as first argument + arguments: + - !tagged { tag: 'app.upgrade.step' } + - '@monolog.logger.upgrade' + App\Install\Service\LegacyMigration\LegacyMigrationHandler: # inject all services tagged with app.legacy.migration.step as first argument arguments: diff --git a/core/backend/Install/Command/UpgradeFinalizeCommand.php b/core/backend/Install/Command/UpgradeFinalizeCommand.php new file mode 100644 index 000000000..2f3d757c6 --- /dev/null +++ b/core/backend/Install/Command/UpgradeFinalizeCommand.php @@ -0,0 +1,93 @@ +. + * + * In accordance with Section 7(b) of the GNU Affero General Public License + * version 3, these Appropriate Legal Notices must retain the display of the + * "Supercharged by SuiteCRM" logo. If the display of the logos is not reasonably + * feasible for technical reasons, the Appropriate Legal Notices must display + * the words "Supercharged by SuiteCRM". + */ + +namespace App\Install\Command; + +use App\Engine\Service\ProcessSteps\ProcessStepExecutorInterface; +use App\Install\Service\Upgrade\UpgradeFinalizeHandlerInterface; + +/** + * Class UpgradeFinalizeCommand + * @package App\Install\Command + */ +class UpgradeFinalizeCommand extends BaseStepExecutorCommand +{ + /** + * @var string + */ + protected static $defaultName = 'suitecrm:app:upgrade-finalize'; + + /** + * @var UpgradeFinalizeHandlerInterface + */ + protected $handler; + + /** + * UpgradeFinalizeCommand constructor. + * @param UpgradeFinalizeHandlerInterface $handler + */ + public function __construct(UpgradeFinalizeHandlerInterface $handler) + { + $this->handler = $handler; + + $this->initSession = true; + + parent::__construct(); + } + + protected function configure(): void + { + parent::configure(); + + $this->setDescription('Finalize the application upgrade') + ->setHelp('This command will finalize the upgrade of the SuiteCRM 8 and legacy application'); + } + + /** + * @inheritDoc + */ + protected function getContext(array $arguments): array + { + return []; + } + + /** + * @inheritDoc + */ + protected function getTitle(): string + { + return 'SuiteCRM Finalize Upgrade '; + } + + /** + * @inheritDoc + */ + protected function getHandler(): ProcessStepExecutorInterface + { + return $this->handler; + } +} diff --git a/core/backend/Install/Service/Upgrade/Steps/CheckPackage.php b/core/backend/Install/Service/Upgrade/Steps/CheckPackage.php index 84a8c4357..bec165e4b 100644 --- a/core/backend/Install/Service/Upgrade/Steps/CheckPackage.php +++ b/core/backend/Install/Service/Upgrade/Steps/CheckPackage.php @@ -42,6 +42,7 @@ class CheckPackage implements UpgradeStepInterface public const HANDLER_KEY = 'check-package'; public const POSITION = 300; + public const STAGE = 'upgrade-install'; /** * @var UpgradePackageHandler @@ -73,6 +74,14 @@ class CheckPackage implements UpgradeStepInterface return self::POSITION; } + /** + * @inheritDoc + */ + public function getStage(): string + { + return self::STAGE; + } + /** * @inheritDoc */ diff --git a/core/backend/Install/Service/Upgrade/Steps/CheckPermissions.php b/core/backend/Install/Service/Upgrade/Steps/CheckPermissions.php index b55edd45d..9d064d54e 100644 --- a/core/backend/Install/Service/Upgrade/Steps/CheckPermissions.php +++ b/core/backend/Install/Service/Upgrade/Steps/CheckPermissions.php @@ -42,6 +42,7 @@ class CheckPermissions implements UpgradeStepInterface public const HANDLER_KEY = 'check-permissions'; public const POSITION = 500; + public const STAGE = 'upgrade-install'; /** * @var UpgradePackageHandler @@ -73,6 +74,14 @@ class CheckPermissions implements UpgradeStepInterface return self::POSITION; } + /** + * @inheritDoc + */ + public function getStage(): string + { + return self::STAGE; + } + /** * @inheritDoc */ diff --git a/core/backend/Install/Service/Upgrade/Steps/ClearSymfonyCache.php b/core/backend/Install/Service/Upgrade/Steps/ClearSymfonyCache.php index 2c7829aee..92548ca5b 100644 --- a/core/backend/Install/Service/Upgrade/Steps/ClearSymfonyCache.php +++ b/core/backend/Install/Service/Upgrade/Steps/ClearSymfonyCache.php @@ -42,7 +42,8 @@ class ClearSymfonyCache implements UpgradeStepInterface use ProcessStepTrait; public const HANDLER_KEY = 'clear-symfony-cache'; - public const POSITION = 900; + public const POSITION = 800; + public const STAGE = 'upgrade-install'; /** * @var CacheBridge @@ -74,6 +75,14 @@ class ClearSymfonyCache implements UpgradeStepInterface return self::POSITION; } + /** + * @inheritDoc + */ + public function getStage(): string + { + return self::STAGE; + } + /** * @inheritDoc * @throws Exception diff --git a/core/backend/Install/Service/Upgrade/Steps/ExtractPackage.php b/core/backend/Install/Service/Upgrade/Steps/ExtractPackage.php index 219b364c2..52451130e 100644 --- a/core/backend/Install/Service/Upgrade/Steps/ExtractPackage.php +++ b/core/backend/Install/Service/Upgrade/Steps/ExtractPackage.php @@ -42,6 +42,7 @@ class ExtractPackage implements UpgradeStepInterface public const HANDLER_KEY = 'extract-package'; public const POSITION = 400; + public const STAGE = 'upgrade-install'; /** * @var UpgradePackageHandler @@ -73,6 +74,14 @@ class ExtractPackage implements UpgradeStepInterface return self::POSITION; } + /** + * @inheritDoc + */ + public function getStage(): string + { + return self::STAGE; + } + /** * @inheritDoc */ diff --git a/core/backend/Install/Service/Upgrade/Steps/InstallUpgradePackage.php b/core/backend/Install/Service/Upgrade/Steps/InstallUpgradePackage.php index fdfb1b9c6..a0cdc6e6e 100644 --- a/core/backend/Install/Service/Upgrade/Steps/InstallUpgradePackage.php +++ b/core/backend/Install/Service/Upgrade/Steps/InstallUpgradePackage.php @@ -42,6 +42,7 @@ class InstallUpgradePackage implements UpgradeStepInterface public const HANDLER_KEY = 'install-upgrade-package'; public const POSITION = 600; + public const STAGE = 'upgrade-install'; /** * @var UpgradePackageHandler @@ -73,6 +74,14 @@ class InstallUpgradePackage implements UpgradeStepInterface return self::POSITION; } + /** + * @inheritDoc + */ + public function getStage(): string + { + return self::STAGE; + } + /** * @inheritDoc */ diff --git a/core/backend/Install/Service/Upgrade/Steps/LegacyPostUpgrade.php b/core/backend/Install/Service/Upgrade/Steps/LegacyPostUpgrade.php index 9a9ba13e5..3521f2de8 100644 --- a/core/backend/Install/Service/Upgrade/Steps/LegacyPostUpgrade.php +++ b/core/backend/Install/Service/Upgrade/Steps/LegacyPostUpgrade.php @@ -41,7 +41,8 @@ class LegacyPostUpgrade implements UpgradeStepInterface use ProcessStepTrait; public const HANDLER_KEY = 'legacy-post-upgrade'; - public const POSITION = 800; + public const POSITION = 700; + public const STAGE = 'upgrade-finalize'; /** * @var PostUpgradeHandler @@ -73,6 +74,14 @@ class LegacyPostUpgrade implements UpgradeStepInterface return self::POSITION; } + /** + * @inheritDoc + */ + public function getStage(): string + { + return self::STAGE; + } + /** * @inheritDoc */ diff --git a/core/backend/Install/Service/Upgrade/Steps/RunMigrations.php b/core/backend/Install/Service/Upgrade/Steps/RunMigrations.php index d89488167..ec5f7914e 100644 --- a/core/backend/Install/Service/Upgrade/Steps/RunMigrations.php +++ b/core/backend/Install/Service/Upgrade/Steps/RunMigrations.php @@ -42,7 +42,8 @@ class RunMigrations implements UpgradeStepInterface use ProcessStepTrait; public const HANDLER_KEY = 'run-migrations'; - public const POSITION = 700; + public const POSITION = 900; + public const STAGE = 'upgrade-finalize'; /** * @var MigrationBridge @@ -74,6 +75,14 @@ class RunMigrations implements UpgradeStepInterface return self::POSITION; } + /** + * @inheritDoc + */ + public function getStage(): string + { + return self::STAGE; + } + /** * @inheritDoc * @throws Exception diff --git a/core/backend/Install/Service/Upgrade/UpgradeFinalizeHandler.php b/core/backend/Install/Service/Upgrade/UpgradeFinalizeHandler.php new file mode 100644 index 000000000..ccc47f4f0 --- /dev/null +++ b/core/backend/Install/Service/Upgrade/UpgradeFinalizeHandler.php @@ -0,0 +1,58 @@ +. + * + * In accordance with Section 7(b) of the GNU Affero General Public License + * version 3, these Appropriate Legal Notices must retain the display of the + * "Supercharged by SuiteCRM" logo. If the display of the logos is not reasonably + * feasible for technical reasons, the Appropriate Legal Notices must display + * the words "Supercharged by SuiteCRM". + */ + +namespace App\Install\Service\Upgrade; + +use App\Engine\Service\ProcessSteps\ProcessStepExecutor; +use Psr\Log\LoggerInterface; + +class UpgradeFinalizeHandler extends ProcessStepExecutor implements UpgradeFinalizeHandlerInterface +{ + /** + * UpgradeHandler constructor. + * @param iterable $handlers + * @param LoggerInterface $upgradeLogger + */ + public function __construct( + iterable $handlers, + LoggerInterface $upgradeLogger + ) { + $this->logger = $upgradeLogger; + + $upgradeFinalizeHandlers = []; + + /**@var $handlers UpgradeStepInterface[] */ + foreach ($handlers as $handler) { + if ($handler->getStage() === 'upgrade-finalize') { + $upgradeFinalizeHandlers[] = $handler; + } + } + + $this->initSteps($upgradeFinalizeHandlers, $this->logger); + } + +} diff --git a/core/backend/Install/Service/Upgrade/UpgradeFinalizeHandlerInterface.php b/core/backend/Install/Service/Upgrade/UpgradeFinalizeHandlerInterface.php new file mode 100644 index 000000000..b5022b8a6 --- /dev/null +++ b/core/backend/Install/Service/Upgrade/UpgradeFinalizeHandlerInterface.php @@ -0,0 +1,39 @@ +. + * + * In accordance with Section 7(b) of the GNU Affero General Public License + * version 3, these Appropriate Legal Notices must retain the display of the + * "Supercharged by SuiteCRM" logo. If the display of the logos is not reasonably + * feasible for technical reasons, the Appropriate Legal Notices must display + * the words "Supercharged by SuiteCRM". + */ + +namespace App\Install\Service\Upgrade; + +use App\Engine\Service\ProcessSteps\ProcessStepExecutorInterface; + +/** + * Interface UpgradeFinalizeHandlerInterface + * Used to allow extensibility + * @package App\Install\Service\Upgrade + */ +interface UpgradeFinalizeHandlerInterface extends ProcessStepExecutorInterface +{ +} diff --git a/core/backend/Install/Service/Upgrade/UpgradeHandler.php b/core/backend/Install/Service/Upgrade/UpgradeHandler.php index 9a6f3d016..67a3b11b9 100644 --- a/core/backend/Install/Service/Upgrade/UpgradeHandler.php +++ b/core/backend/Install/Service/Upgrade/UpgradeHandler.php @@ -42,7 +42,17 @@ class UpgradeHandler extends ProcessStepExecutor implements UpgradeHandlerInterf LoggerInterface $upgradeLogger ) { $this->logger = $upgradeLogger; - $this->initSteps($handlers, $this->logger); + + $upgradeInstallHandlers = []; + + /**@var $handlers UpgradeStepInterface[] */ + foreach ($handlers as $handler) { + if ($handler->getStage() === 'upgrade-install') { + $upgradeInstallHandlers[] = $handler; + } + } + + $this->initSteps($upgradeInstallHandlers, $this->logger); } } diff --git a/core/backend/Install/Service/Upgrade/UpgradeStepInterface.php b/core/backend/Install/Service/Upgrade/UpgradeStepInterface.php index b5fec2781..de5c50b33 100644 --- a/core/backend/Install/Service/Upgrade/UpgradeStepInterface.php +++ b/core/backend/Install/Service/Upgrade/UpgradeStepInterface.php @@ -37,4 +37,10 @@ use App\Engine\Model\ProcessStepInterface; interface UpgradeStepInterface extends ProcessStepInterface { + /** + * Get stage + * @return string + */ + public function getStage(): string; + }