-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,31 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
|
||
/** | ||
* Copyright since 2007 PrestaShop SA and Contributors | ||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0) | ||
* that is bundled with this package in the file LICENSE.md. | ||
* It is also available through the world-wide-web at this URL: | ||
* https://opensource.org/licenses/AFL-3.0 | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to [email protected] so we can send you a copy immediately. | ||
* | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer | ||
* versions in the future. If you wish to customize PrestaShop for your | ||
* needs please refer to https://devdocs.prestashop.com/ for more information. | ||
* | ||
* @author PrestaShop SA and Contributors <[email protected]> | ||
* @copyright Since 2007 PrestaShop SA and Contributors | ||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) | ||
*/ | ||
|
||
use PrestaShop\Module\AutoUpgrade\Commands\CheckRequirementsCommand; | ||
use Symfony\Component\Console\Application; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,14 +40,17 @@ | |
|
||
class CheckRequirementsCommand extends Command | ||
{ | ||
protected static $defaultName = 'upgrade:check-requirements'; | ||
/** | ||
* @var $defaultName string | ||
*/ | ||
protected static $defaultName = 'upgrade:check'; | ||
Check failure on line 46 in classes/Commands/CheckRequirementsCommand.php GitHub Actions / PHPStan (1.7.2.5)
Check failure on line 46 in classes/Commands/CheckRequirementsCommand.php GitHub Actions / PHPStan (1.7.2.5)
Check failure on line 46 in classes/Commands/CheckRequirementsCommand.php GitHub Actions / PHPStan (1.7.3.4)
|
||
const MODULE_CONFIG_DIR = 'autoupgrade'; | ||
|
||
protected function configure() | ||
protected function configure(): void | ||
{ | ||
$this | ||
->setDescription('Check all prerequisites for an upgrade.') | ||
->setHelp('This command allows you to check the prerequisites necessary for the proper functioning of an upgrade.') | ||
->setDescription('Check all prerequisites for an update.') | ||
->setHelp('This command allows you to check the prerequisites necessary for the proper functioning of an update.') | ||
->addArgument('admin-dir', InputArgument::REQUIRED, 'The admin directory name.'); | ||
} | ||
|
||
|
@@ -80,19 +83,12 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int | |
$moduleConfigPath | ||
); | ||
|
||
if (!$selfCheck->isModuleVersionLatest()) { | ||
$output->writeln('<warning>⚠</warning> Your current version of the module is out of date.'); | ||
} | ||
|
||
$results = $this->getRequirementsResult($selfCheck); | ||
|
||
if (!$selfCheck->isOkForUpgrade()) { | ||
$table = new Table($output); | ||
$table | ||
->setHeaders(['Requirements', 'Result']) | ||
->setRows($results); | ||
$table->render(); | ||
$requirements = $this->getFailedRequirementsList($selfCheck); | ||
|
||
if (!empty($requirements)) { | ||
foreach ($requirements as $requirement) { | ||
$output->writeln($requirement); | ||
} | ||
return ExitCode::FAIL; | ||
} else { | ||
$output->writeln('<success>✔</success> All prerequisites meet the conditions for an update.'); | ||
|
@@ -101,52 +97,66 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int | |
} | ||
} | ||
|
||
/** | ||
* @return array<array<string, string>> | ||
*/ | ||
protected function getRequirementsResult(UpgradeSelfCheck $selfCheck): array | ||
protected function getFailedRequirementsList(UpgradeSelfCheck $selfCheck): array | ||
Check failure on line 100 in classes/Commands/CheckRequirementsCommand.php GitHub Actions / PHPStan (1.7.2.5)
Check failure on line 100 in classes/Commands/CheckRequirementsCommand.php GitHub Actions / PHPStan (1.7.3.4)
|
||
{ | ||
$requirements = [ | ||
'isShopVersionMatchingVersionInDatabase' => $selfCheck->isShopVersionMatchingVersionInDatabase(), | ||
'rootDirectoryIsWritable' => $selfCheck->isRootDirectoryWritable(), | ||
'adminDirectoryIsWritable' => $selfCheck->isAdminAutoUpgradeDirectoryWritable(), | ||
'adminDirectoryWritableReport' => $selfCheck->getAdminAutoUpgradeDirectoryWritableReport(), | ||
'safeModeIsDisabled' => $selfCheck->isSafeModeDisabled(), | ||
'allowUrlFopenOrCurlIsEnabled' => $selfCheck->isFOpenOrCurlEnabled(), | ||
'zipIsEnabled' => $selfCheck->isZipEnabled(), | ||
'storeIsInMaintenance' => $selfCheck->isShopDeactivated(), | ||
'isLocalEnvironment' => $selfCheck->isLocalEnvironment(), | ||
'cachingIsDisabled' => $selfCheck->isCacheDisabled(), | ||
'maxExecutionTime' => $selfCheck->getMaxExecutionTime(), | ||
'checkApacheModRewrite' => $selfCheck->isApacheModRewriteEnabled(), | ||
'notLoadedPhpExtensions' => $selfCheck->getNotLoadedPhpExtensions(), | ||
'checkKeyGeneration' => $selfCheck->checkKeyGeneration(), | ||
'checkMemoryLimit' => $selfCheck->isMemoryLimitValid(), | ||
'checkFileUploads' => $selfCheck->isPhpFileUploadsConfigurationEnabled(), | ||
'notExistsPhpFunctions' => $selfCheck->getNotExistsPhpFunctions(), | ||
'checkPhpSessions' => $selfCheck->isPhpSessionsValid(), | ||
'missingFiles' => $selfCheck->getMissingFiles(), | ||
'notWritingDirectories' => $selfCheck->getNotWritingDirectories(), | ||
]; | ||
$requirementWarnings = $this->getRequirementWarnings($selfCheck); | ||
$requirementErrors = $this->getRequirementErrors($selfCheck); | ||
|
||
$results = []; | ||
return array_merge( | ||
$this->processRequirements($requirementWarnings, '<warning>⚠</warning>'), | ||
$this->processRequirements($requirementErrors, '<error>✘</error>') | ||
); | ||
} | ||
|
||
foreach ($requirements as $key => $value) { | ||
if ($value === false || (is_array($value) && !empty($value))) { | ||
$results[] = [$key, '<error>✘</error>']; | ||
} | ||
} | ||
private function getRequirementErrors(UpgradeSelfCheck $selfCheck): array | ||
Check failure on line 111 in classes/Commands/CheckRequirementsCommand.php GitHub Actions / PHPStan (1.7.2.5)
Check failure on line 111 in classes/Commands/CheckRequirementsCommand.php GitHub Actions / PHPStan (1.7.3.4)
|
||
{ | ||
$phpCompatibilityRange = $selfCheck->getPhpCompatibilityRange(); | ||
|
||
return [ | ||
sprintf( | ||
'Your current PHP version isn\'t compatible with your PrestaShop version (Expected: %s - %s | Current: %s)', | ||
$phpCompatibilityRange['php_min_version'], | ||
$phpCompatibilityRange['php_max_version'], | ||
$phpCompatibilityRange['php_current_version'] | ||
) => $selfCheck->getPhpRequirementsState() == UpgradeSelfCheck::PHP_REQUIREMENTS_INVALID, | ||
'Your store\'s root directory isn\'t writable. Provide write access to the user running PHP with appropriate permission & ownership.' => !$selfCheck->isRootDirectoryWritable(), | ||
'The "/admin/autoupgrade" directory isn\'t writable. Provide write access to the user running PHP with appropriate permission & ownership.' => !$selfCheck->isAdminAutoUpgradeDirectoryWritable(), | ||
'PHP\'s "Safe mode" needs to be disabled.' => !$selfCheck->isSafeModeDisabled(), | ||
'Files can\'t be downloaded. Enable PHP\'s "allow_url_fopen" option or install PHP extension "cURL".' => !$selfCheck->isFOpenOrCurlEnabled(), | ||
'Missing PHP extension "zip".' => !$selfCheck->isZipEnabled(), | ||
'Maintenance mode needs to be enabled. Enable maintenance mode and add your maintenance IP.' => !$selfCheck->isLocalEnvironment() && !$selfCheck->isShopDeactivated(), | ||
'PrestaShop\'s caching features needs to be disabled.' => !$selfCheck->isCacheDisabled(), | ||
sprintf('PHP\'s max_execution_time setting needs to have a high value or needs to be disabled entirely (current value: %s seconds)', $selfCheck->getMaxExecutionTime()) => $selfCheck->getMaxExecutionTime() !== 0, | ||
'Apache mod_rewrite needs to be enabled.' => !$selfCheck->isApacheModRewriteEnabled(), | ||
sprintf('The following PHP extension%s needs to be installed: %s', count($selfCheck->getNotLoadedPhpExtensions()) > 1 ? 's' : '', implode(' ,', $selfCheck->getNotLoadedPhpExtensions())) => !empty($selfCheck->getNotLoadedPhpExtensions()), | ||
sprintf('The following PHP function%s needs to be allowed: %s', count($selfCheck->getNotExistsPhpFunctions()) > 1 ? 's' : '', implode(' ,', $selfCheck->getNotExistsPhpFunctions())) => !empty($selfCheck->getNotExistsPhpFunctions()), | ||
'PHP memory_limit needs to be greater than 256 MB.' => !$selfCheck->isMemoryLimitValid(), | ||
'PHP file_uploads configuration needs to be enabled.' => !$selfCheck->isPhpFileUploadsConfigurationEnabled(), | ||
'Unable to generate private keys using openssl_pkey_new. Check your OpenSSL configuration, especially the path to openssl.cafile.' => !$selfCheck->checkKeyGeneration(), | ||
sprintf('It\'s not possible to write in the following folders: %s. Provide write access to the user running PHP with appropriate permission & ownership.', implode(' ,', $selfCheck->getNotWritingDirectories())) => !empty($selfCheck->getNotWritingDirectories()), | ||
'The version of PrestaShop does not match the one stored in database. Your database structure may not be up-to-date and/or the value of PS_VERSION_DB needs to be updated in the configuration table.' => !$selfCheck->isShopVersionMatchingVersionInDatabase(), | ||
]; | ||
} | ||
|
||
$phpRequirementsState = $selfCheck->getPhpRequirementsState(); | ||
private function getRequirementWarnings(UpgradeSelfCheck $selfCheck): array | ||
Check failure on line 141 in classes/Commands/CheckRequirementsCommand.php GitHub Actions / PHPStan (1.7.2.5)
Check failure on line 141 in classes/Commands/CheckRequirementsCommand.php GitHub Actions / PHPStan (1.7.3.4)
|
||
{ | ||
return [ | ||
'Your current version of the module is out of date.' => !$selfCheck->isModuleVersionLatest(), | ||
'We were unable to check your PHP compatibility with the destination PrestaShop version.' => $selfCheck->getPhpRequirementsState() == UpgradeSelfCheck::PHP_REQUIREMENTS_UNKNOWN, | ||
'Some core files have been altered, customization made on these files will be lost during the update.' => true, | ||
]; | ||
} | ||
|
||
private function processRequirements(array $requirements, string $indicator): array | ||
Check failure on line 150 in classes/Commands/CheckRequirementsCommand.php GitHub Actions / PHPStan (1.7.2.5)
Check failure on line 150 in classes/Commands/CheckRequirementsCommand.php GitHub Actions / PHPStan (1.7.2.5)
Check failure on line 150 in classes/Commands/CheckRequirementsCommand.php GitHub Actions / PHPStan (1.7.3.4)
Check failure on line 150 in classes/Commands/CheckRequirementsCommand.php GitHub Actions / PHPStan (1.7.3.4)
|
||
{ | ||
$results = []; | ||
|
||
if ($phpRequirementsState != UpgradeSelfCheck::PHP_REQUIREMENTS_VALID) { | ||
if ($phpRequirementsState == UpgradeSelfCheck::PHP_REQUIREMENTS_INVALID) { | ||
$results[] = ['phpRequirementsState', '<error>✘</error>']; | ||
} else { | ||
$results[] = ['phpRequirementsState', '<warning>⚠</warning>']; | ||
foreach ($requirements as $message => $condition) { | ||
if ($condition) { | ||
$results[] = [$message, $indicator]; | ||
} | ||
} | ||
|
||
return $results; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.