diff --git a/classes/Commands/CheckRequirementsCommand.php b/classes/Commands/CheckRequirementsCommand.php index 90c706fac4..e014fe0fcf 100644 --- a/classes/Commands/CheckRequirementsCommand.php +++ b/classes/Commands/CheckRequirementsCommand.php @@ -31,8 +31,6 @@ use PrestaShop\Module\AutoUpgrade\Exceptions\DistributionApiException; use PrestaShop\Module\AutoUpgrade\Exceptions\UpgradeException; use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeConfiguration; -use PrestaShop\Module\AutoUpgrade\Services\DistributionApiService; -use PrestaShop\Module\AutoUpgrade\Services\PhpVersionResolverService; use PrestaShop\Module\AutoUpgrade\Task\ExitCode; use PrestaShop\Module\AutoUpgrade\UpgradeContainer; use PrestaShop\Module\AutoUpgrade\UpgradeSelfCheck; @@ -46,8 +44,6 @@ class CheckRequirementsCommand extends AbstractCommand /** @var string */ protected static $defaultName = 'update:check-requirements'; const MODULE_CONFIG_DIR = 'autoupgrade'; - /** @var UpgradeSelfCheck */ - private $upgradeSelfCheck; /** @var OutputInterface */ private $output; /** @var int */ @@ -96,26 +92,6 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int $this->upgradeContainer->initPrestaShopCore(); $this->upgradeContainer->getState()->initDefault($this->upgradeContainer->getProperty(UpgradeContainer::PS_VERSION), $this->upgradeContainer->getUpgrader()->getDestinationVersion()); - $distributionApiService = new DistributionApiService(); - $phpVersionResolverService = new PhpVersionResolverService( - $distributionApiService, - $this->upgradeContainer->getFileLoader(), - $this->upgradeContainer->getState()->getCurrentVersion() - ); - - $this->upgradeSelfCheck = new UpgradeSelfCheck( - $this->upgradeContainer->getUpgrader(), - $this->upgradeContainer->getState(), - $this->upgradeContainer->getUpgradeConfiguration(), - $this->upgradeContainer->getPrestaShopConfiguration(), - $this->upgradeContainer->getTranslator(), - $phpVersionResolverService, - $this->upgradeContainer->getChecksumCompare(), - _PS_ROOT_DIR_, - _PS_ADMIN_DIR_, - $moduleConfigPath - ); - $output->writeln('Result of prerequisite checks:'); $this->exitCode = ExitCode::SUCCESS; $this->processRequirementWarnings(); @@ -137,8 +113,8 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int */ private function processRequirementErrors(): void { - foreach ($this->upgradeSelfCheck->getErrors() as $error => $value) { - $wording = $this->upgradeSelfCheck->getRequirementWording($error); + foreach ($this->upgradeContainer->getUpgradeSelfCheck()->getErrors() as $error => $value) { + $wording = $this->upgradeContainer->getUpgradeSelfCheck()->getRequirementWording($error); $this->writeError($wording['message']); if (isset($wording['list'])) { foreach ($wording['list'] as $item) { @@ -154,20 +130,20 @@ private function processRequirementErrors(): void */ private function processRequirementWarnings(): void { - foreach ($this->upgradeSelfCheck->getWarnings() as $warning => $value) { - $wording = $this->upgradeSelfCheck->getRequirementWording($warning); + foreach ($this->upgradeContainer->getUpgradeSelfCheck()->getWarnings() as $warning => $value) { + $wording = $this->upgradeContainer->getUpgradeSelfCheck()->getRequirementWording($warning); $this->writeWarning($wording['message']); switch ($warning) { case UpgradeSelfCheck::CORE_TEMPERED_FILES_LIST_NOT_EMPTY: - $missingFiles = $this->upgradeSelfCheck->getCoreMissingFiles(); + $missingFiles = $this->upgradeContainer->getUpgradeSelfCheck()->getCoreMissingFiles(); $this->output->writeln("\t" . count($missingFiles) . ' files are missing:'); foreach ($missingFiles as $missingFile) { $this->output->writeln("\t\t" . $missingFile); } - $alteredFiles = $this->upgradeSelfCheck->getCoreAlteredFiles(); + $alteredFiles = $this->upgradeContainer->getUpgradeSelfCheck()->getCoreAlteredFiles(); $this->output->writeln("\t" . count($alteredFiles) . ' files are altered:'); foreach ($alteredFiles as $alteredFile) { @@ -175,14 +151,14 @@ private function processRequirementWarnings(): void } break; case UpgradeSelfCheck::THEME_TEMPERED_FILES_LIST_NOT_EMPTY: - $missingFiles = $this->upgradeSelfCheck->getThemeMissingFiles(); + $missingFiles = $this->upgradeContainer->getUpgradeSelfCheck()->getThemeMissingFiles(); $this->output->writeln("\t" . count($missingFiles) . ' files are missing:'); foreach ($missingFiles as $missingFile) { $this->output->writeln("\t\t" . $missingFile); } - $alteredFiles = $this->upgradeSelfCheck->getThemeAlteredFiles(); + $alteredFiles = $this->upgradeContainer->getUpgradeSelfCheck()->getThemeAlteredFiles(); $this->output->writeln("\t" . count($alteredFiles) . ' files are altered:'); foreach ($alteredFiles as $alteredFile) { diff --git a/classes/UpgradeContainer.php b/classes/UpgradeContainer.php index 10aa912c67..ca6a5a7f62 100644 --- a/classes/UpgradeContainer.php +++ b/classes/UpgradeContainer.php @@ -227,6 +227,21 @@ class UpgradeContainer */ private $prestashopVersionService; + /** + * @var UpgradeSelfCheck + */ + private $upgradeSelfCheck; + + /** + * @var PhpVersionResolverService + */ + private $phpVersionResolverService; + + /** + * @var DistributionApiService + */ + private $distributionApiService; + /** * AdminSelfUpgrade::$autoupgradePath * Ex.: /var/www/html/PrestaShop/admin-dev/autoupgrade. @@ -685,33 +700,60 @@ public function getUpgradeConfigurationStorage(): UpgradeConfigurationStorage return new UpgradeConfigurationStorage($this->getProperty(self::WORKSPACE_PATH) . DIRECTORY_SEPARATOR); } + public function getDistributionApiService(): DistributionApiService + { + if (null !== $this->distributionApiService) { + return $this->distributionApiService; + } + + $this->distributionApiService = new DistributionApiService(); + + return $this->distributionApiService; + } + /** * @throws Exception */ - public function getUpgradeSelfCheck(): UpgradeSelfCheck + public function getPhpVersionResolverService(): PhpVersionResolverService { - $this->initPrestaShopCore(); - $state = $this->getState(); + if (null !== $this->phpVersionResolverService) { + return $this->phpVersionResolverService; + } - $distributionApiService = new DistributionApiService(); - $phpVersionResolverService = new PhpVersionResolverService( - $distributionApiService, + $this->phpVersionResolverService = new PhpVersionResolverService( + $this->getDistributionApiService(), $this->getFileLoader(), - $state->getCurrentVersion() + $this->getState()->getCurrentVersion() ); - return new UpgradeSelfCheck( + return $this->phpVersionResolverService; + } + + /** + * @throws Exception + */ + public function getUpgradeSelfCheck(): UpgradeSelfCheck + { + if (null !== $this->upgradeSelfCheck) { + return $this->upgradeSelfCheck; + } + + $this->initPrestaShopCore(); + + $this->upgradeSelfCheck = new UpgradeSelfCheck( $this->getUpgrader(), - $state, + $this->getState(), $this->getUpgradeConfiguration(), $this->getPrestaShopConfiguration(), $this->getTranslator(), - $phpVersionResolverService, + $this->getPhpVersionResolverService(), $this->getChecksumCompare(), _PS_ROOT_DIR_, _PS_ADMIN_DIR_, $this->getProperty(UpgradeContainer::WORKSPACE_PATH) ); + + return $this->upgradeSelfCheck; } /** diff --git a/controllers/admin/AdminSelfUpgradeController.php b/controllers/admin/AdminSelfUpgradeController.php index e4e5d75f8a..cceb9415a3 100644 --- a/controllers/admin/AdminSelfUpgradeController.php +++ b/controllers/admin/AdminSelfUpgradeController.php @@ -29,12 +29,9 @@ use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeConfiguration; use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeFileNames; use PrestaShop\Module\AutoUpgrade\Router\Router; -use PrestaShop\Module\AutoUpgrade\Services\DistributionApiService; -use PrestaShop\Module\AutoUpgrade\Services\PhpVersionResolverService; use PrestaShop\Module\AutoUpgrade\Tools14; use PrestaShop\Module\AutoUpgrade\UpgradeContainer; use PrestaShop\Module\AutoUpgrade\UpgradePage; -use PrestaShop\Module\AutoUpgrade\UpgradeSelfCheck; use Symfony\Component\HttpFoundation\Request; class AdminSelfUpgradeController extends ModuleAdminController @@ -485,30 +482,13 @@ public function initContent() } $upgrader = $this->upgradeContainer->getUpgrader(); - $distributionApiService = new DistributionApiService(); - $phpVersionResolverService = new PhpVersionResolverService( - $distributionApiService, - $this->upgradeContainer->getFileLoader(), - $this->upgradeContainer->getState()->getCurrentVersion() - ); - $upgradeSelfCheck = new UpgradeSelfCheck( - $upgrader, - $this->upgradeContainer->getState(), - $this->upgradeContainer->getUpgradeConfiguration(), - $this->upgradeContainer->getPrestaShopConfiguration(), - $this->upgradeContainer->getTranslator(), - $phpVersionResolverService, - $this->upgradeContainer->getChecksumCompare(), - $this->prodRootDir, - $this->adminDir, - $this->autoupgradePath - ); + $response = new AjaxResponse($this->upgradeContainer->getState(), $this->upgradeContainer->getLogger()); $this->content = (new UpgradePage( $this->upgradeContainer->getUpgradeConfiguration(), $this->upgradeContainer->getTwig(), $this->upgradeContainer->getTranslator(), - $upgradeSelfCheck, + $this->upgradeContainer->getUpgradeSelfCheck(), $upgrader, $backupFinder, $this->autoupgradePath,