diff --git a/classes/Commands/UpdateCommand.php b/classes/Commands/UpdateCommand.php
index 46d963df1..2d838e1b6 100644
--- a/classes/Commands/UpdateCommand.php
+++ b/classes/Commands/UpdateCommand.php
@@ -29,6 +29,7 @@
use Exception;
use PrestaShop\Module\AutoUpgrade\DeveloperDocumentation;
+use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeConfiguration;
use PrestaShop\Module\AutoUpgrade\Task\ExitCode;
use PrestaShop\Module\AutoUpgrade\Task\Runner\AllUpdateTasks;
use Symfony\Component\Console\Input\InputArgument;
@@ -93,7 +94,7 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int
$controller->setOptions([
'data' => $input->getOption('data'),
'action' => $input->getOption('action'),
- 'channel' => $input->getOption('channel'),
+ UpgradeConfiguration::CHANNEL => $input->getOption('channel'),
]);
$controller->init();
$exitCode = $controller->run();
diff --git a/classes/Parameters/ConfigurationValidator.php b/classes/Parameters/ConfigurationValidator.php
index c7e2ebb28..af024b9cd 100644
--- a/classes/Parameters/ConfigurationValidator.php
+++ b/classes/Parameters/ConfigurationValidator.php
@@ -51,23 +51,23 @@ public function validate(array $array = []): array
{
$errors = [];
- $isLocal = isset($array['channel']) && $array['channel'] === Upgrader::CHANNEL_LOCAL;
+ $isLocal = isset($array[UpgradeConfiguration::CHANNEL]) && $array[UpgradeConfiguration::CHANNEL] === Upgrader::CHANNEL_LOCAL;
foreach ($array as $key => $value) {
switch ($key) {
- case 'channel':
+ case UpgradeConfiguration::CHANNEL:
$error = $this->validateChannel($value);
break;
- case 'archive_zip':
+ case UpgradeConfiguration::ARCHIVE_ZIP:
$error = $this->validateArchiveZip($value, $isLocal);
break;
- case 'archive_xml':
+ case UpgradeConfiguration::ARCHIVE_XML:
$error = $this->validateArchiveXml($value, $isLocal);
break;
- case 'PS_AUTOUP_CUSTOM_MOD_DESACT':
- case 'PS_AUTOUP_KEEP_MAILS':
- case 'PS_AUTOUP_KEEP_IMAGES':
- case 'PS_DISABLE_OVERRIDES':
+ case UpgradeConfiguration::PS_AUTOUP_CUSTOM_MOD_DESACT:
+ case UpgradeConfiguration::PS_AUTOUP_KEEP_MAILS:
+ case UpgradeConfiguration::PS_AUTOUP_KEEP_IMAGES:
+ case UpgradeConfiguration::PS_DISABLE_OVERRIDES:
$error = $this->validateBool($value, $key);
break;
}
diff --git a/classes/Parameters/LocalChannelConfigurationValidator.php b/classes/Parameters/LocalChannelConfigurationValidator.php
index 6516e809b..deb154adc 100644
--- a/classes/Parameters/LocalChannelConfigurationValidator.php
+++ b/classes/Parameters/LocalChannelConfigurationValidator.php
@@ -77,12 +77,12 @@ public function validate(array $array = []): array
$errors = [];
- $zipErrors = $this->validateZipFile($array['archive_zip']);
+ $zipErrors = $this->validateZipFile($array[UpgradeConfiguration::ARCHIVE_ZIP]);
if ($zipErrors) {
$errors[] = $zipErrors;
}
- $xmlErrors = $this->validateXmlFile($array['archive_xml']);
+ $xmlErrors = $this->validateXmlFile($array[UpgradeConfiguration::ARCHIVE_XML]);
if ($xmlErrors) {
$errors[] = $xmlErrors;
}
@@ -107,7 +107,7 @@ private function validateZipFile(string $file): ?array
if (!file_exists($fullFilePath)) {
return [
'message' => $this->translator->trans('File %s does not exist. Unable to select that channel.', [$file]),
- 'target' => 'archive_zip',
+ 'target' => UpgradeConfiguration::ARCHIVE_ZIP,
];
}
@@ -116,7 +116,7 @@ private function validateZipFile(string $file): ?array
} catch (Exception $exception) {
return [
'message' => $this->translator->trans('We couldn\'t find a PrestaShop version in the .zip file that was uploaded in your local archive. Please try again.'),
- 'target' => 'archive_zip',
+ 'target' => UpgradeConfiguration::ARCHIVE_ZIP,
];
}
@@ -133,7 +133,7 @@ private function validateXmlFile(string $file): ?array
if (!file_exists($fullXmlPath)) {
return [
'message' => $this->translator->trans('File %s does not exist. Unable to select that channel.', [$file]),
- 'target' => 'archive_xml',
+ 'target' => UpgradeConfiguration::ARCHIVE_XML,
];
}
@@ -142,7 +142,7 @@ private function validateXmlFile(string $file): ?array
} catch (Exception $exception) {
return [
'message' => $this->translator->trans('We couldn\'t find a PrestaShop version in the XML file that was uploaded in your local archive. Please try again.'),
- 'target' => 'archive_xml',
+ 'target' => UpgradeConfiguration::ARCHIVE_XML,
];
}
diff --git a/classes/Parameters/UpgradeConfiguration.php b/classes/Parameters/UpgradeConfiguration.php
index 4cc4930c9..47949fe29 100644
--- a/classes/Parameters/UpgradeConfiguration.php
+++ b/classes/Parameters/UpgradeConfiguration.php
@@ -40,25 +40,36 @@
*/
class UpgradeConfiguration extends ArrayCollection
{
+ const PS_AUTOUP_CUSTOM_MOD_DESACT = 'PS_AUTOUP_CUSTOM_MOD_DESACT';
+ const PS_AUTOUP_CHANGE_DEFAULT_THEME = 'PS_AUTOUP_CHANGE_DEFAULT_THEME';
+ const PS_AUTOUP_KEEP_MAILS = 'PS_AUTOUP_KEEP_MAILS';
+ const PS_AUTOUP_BACKUP = 'PS_AUTOUP_BACKUP';
+ const PS_AUTOUP_KEEP_IMAGES = 'PS_AUTOUP_KEEP_IMAGES';
+ const PS_DISABLE_OVERRIDES = 'PS_DISABLE_OVERRIDES';
+ const CHANNEL = 'channel';
+ const ARCHIVE_ZIP = 'archive_zip';
+ const ARCHIVE_XML = 'archive_xml';
+ const ARCHIVE_VERSION_NUM = 'archive_version_num';
+
const UPGRADE_CONST_KEYS = [
- 'PS_AUTOUP_CUSTOM_MOD_DESACT',
- 'PS_AUTOUP_CHANGE_DEFAULT_THEME',
- 'PS_AUTOUP_KEEP_MAILS',
- 'PS_AUTOUP_BACKUP',
- 'PS_AUTOUP_KEEP_IMAGES',
- 'PS_DISABLE_OVERRIDES',
- 'channel',
- 'archive_zip',
- 'archive_xml',
- 'archive_version_num',
+ self::PS_AUTOUP_CUSTOM_MOD_DESACT,
+ self::PS_AUTOUP_CHANGE_DEFAULT_THEME,
+ self::PS_AUTOUP_KEEP_MAILS,
+ self::PS_AUTOUP_BACKUP,
+ self::PS_AUTOUP_KEEP_IMAGES,
+ self::PS_DISABLE_OVERRIDES,
+ self::CHANNEL,
+ self::ARCHIVE_ZIP,
+ self::ARCHIVE_XML,
+ self::ARCHIVE_VERSION_NUM,
];
const PS_CONST_DEFAULT_VALUE = [
- 'PS_AUTOUP_CUSTOM_MOD_DESACT' => true,
- 'PS_AUTOUP_CHANGE_DEFAULT_THEME' => false,
- 'PS_AUTOUP_KEEP_MAILS' => false,
- 'PS_AUTOUP_BACKUP' => true,
- 'PS_AUTOUP_KEEP_IMAGES' => true,
+ self::PS_AUTOUP_CUSTOM_MOD_DESACT => true,
+ self::PS_AUTOUP_CHANGE_DEFAULT_THEME => false,
+ self::PS_AUTOUP_KEEP_MAILS => false,
+ self::PS_AUTOUP_BACKUP => true,
+ self::PS_AUTOUP_KEEP_IMAGES => true,
];
const DEFAULT_CHANNEL = Upgrader::CHANNEL_ONLINE;
@@ -81,7 +92,7 @@ class UpgradeConfiguration extends ArrayCollection
*/
public function getLocalChannelZip(): ?string
{
- return $this->get('archive_zip');
+ return $this->get(self::ARCHIVE_ZIP);
}
public function getChannelZip(): ?string
@@ -95,7 +106,7 @@ public function getChannelZip(): ?string
public function getLocalChannelXml(): ?string
{
- return $this->get('archive_xml');
+ return $this->get(self::ARCHIVE_XML);
}
/**
@@ -103,15 +114,17 @@ public function getLocalChannelXml(): ?string
*/
public function getLocalChannelVersion(): ?string
{
- return $this->get('archive_version_num');
+ return $this->get(self::ARCHIVE_VERSION_NUM);
}
/**
* Get channel selected on config panel (Minor, major ...).
+ *
+ * @return Upgrader::CHANNEL_*|null
*/
public function getChannel(): ?string
{
- return $this->get('channel');
+ return $this->get(self::CHANNEL);
}
/**
@@ -148,7 +161,7 @@ public function getMaxFileToBackup(): int
public function shouldBackupFilesAndDatabase(): bool
{
- return $this->computeBooleanConfiguration('PS_AUTOUP_BACKUP');
+ return $this->computeBooleanConfiguration(self::PS_AUTOUP_BACKUP);
}
/**
@@ -156,7 +169,7 @@ public function shouldBackupFilesAndDatabase(): bool
*/
public function shouldBackupImages(): bool
{
- return $this->computeBooleanConfiguration('PS_AUTOUP_KEEP_IMAGES');
+ return $this->computeBooleanConfiguration(self::PS_AUTOUP_KEEP_IMAGES);
}
/**
@@ -164,7 +177,7 @@ public function shouldBackupImages(): bool
*/
public function shouldDeactivateCustomModules(): bool
{
- return $this->computeBooleanConfiguration('PS_AUTOUP_CUSTOM_MOD_DESACT');
+ return $this->computeBooleanConfiguration(self::PS_AUTOUP_CUSTOM_MOD_DESACT);
}
/**
@@ -172,7 +185,7 @@ public function shouldDeactivateCustomModules(): bool
*/
public function shouldKeepMails(): bool
{
- return $this->computeBooleanConfiguration('PS_AUTOUP_KEEP_MAILS');
+ return $this->computeBooleanConfiguration(self::PS_AUTOUP_KEEP_MAILS);
}
/**
@@ -180,7 +193,7 @@ public function shouldKeepMails(): bool
*/
public function shouldSwitchToDefaultTheme(): bool
{
- return $this->computeBooleanConfiguration('PS_AUTOUP_CHANGE_DEFAULT_THEME');
+ return $this->computeBooleanConfiguration(self::PS_AUTOUP_CHANGE_DEFAULT_THEME);
}
private function computeBooleanConfiguration(string $const): bool
@@ -199,15 +212,15 @@ private function computeBooleanConfiguration(string $const): bool
public static function isOverrideAllowed(): bool
{
- return (bool) Configuration::get('PS_DISABLE_OVERRIDES');
+ return (bool) Configuration::get(self::PS_DISABLE_OVERRIDES);
}
public static function updateDisabledOverride(bool $value, ?int $shopId = null): void
{
if ($shopId) {
- Configuration::updateValue('PS_DISABLE_OVERRIDES', $value, false, null, (int) $shopId);
+ Configuration::updateValue(self::PS_DISABLE_OVERRIDES, $value, false, null, (int) $shopId);
} else {
- Configuration::updateGlobalValue('PS_DISABLE_OVERRIDES', $value);
+ Configuration::updateGlobalValue(self::PS_DISABLE_OVERRIDES, $value);
}
}
diff --git a/classes/Task/Miscellaneous/UpdateConfig.php b/classes/Task/Miscellaneous/UpdateConfig.php
index 0824c5a22..f839a1bb3 100644
--- a/classes/Task/Miscellaneous/UpdateConfig.php
+++ b/classes/Task/Miscellaneous/UpdateConfig.php
@@ -66,14 +66,14 @@ public function run(): int
continue;
}
// The PS_DISABLE_OVERRIDES variable must only be updated on the database side
- if ($key === 'PS_DISABLE_OVERRIDES') {
+ if ($key === UpgradeConfiguration::PS_DISABLE_OVERRIDES) {
UpgradeConfiguration::updatePSDisableOverrides((bool) $configurationData[$key]);
} else {
$config[$key] = $configurationData[$key];
}
}
- $isLocal = $config['channel'] === Upgrader::CHANNEL_LOCAL;
+ $isLocal = $config[UpgradeConfiguration::CHANNEL] === Upgrader::CHANNEL_LOCAL;
$error = $this->container->getConfigurationValidator()->validate($config);
@@ -89,7 +89,7 @@ public function run(): int
}
if ($isLocal) {
- $file = $config['archive_zip'];
+ $file = $config[UpgradeConfiguration::ARCHIVE_ZIP];
$fullFilePath = $this->container->getProperty(UpgradeContainer::DOWNLOAD_PATH) . DIRECTORY_SEPARATOR . $file;
try {
$config['archive_version_num'] = $this->container->getPrestashopVersionService()->extractPrestashopVersionFromZip($fullFilePath);
diff --git a/classes/Task/Runner/AllUpdateTasks.php b/classes/Task/Runner/AllUpdateTasks.php
index 1cc494bf3..13d4d8985 100644
--- a/classes/Task/Runner/AllUpdateTasks.php
+++ b/classes/Task/Runner/AllUpdateTasks.php
@@ -29,6 +29,7 @@
use Exception;
use PrestaShop\Module\AutoUpgrade\AjaxResponse;
+use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeConfiguration;
use PrestaShop\Module\AutoUpgrade\Task\TaskName;
use UnexpectedValueException;
@@ -61,9 +62,9 @@ public function setOptions(array $options): void
$this->step = $options['action'];
}
- if (!empty($options['channel'])) {
+ if (!empty($options[UpgradeConfiguration::CHANNEL])) {
$config = [
- 'channel' => $options['channel'],
+ UpgradeConfiguration::CHANNEL => $options[UpgradeConfiguration::CHANNEL],
];
$error = $this->container->getConfigurationValidator()->validate($config);
diff --git a/classes/Task/Update/UpdateComplete.php b/classes/Task/Update/UpdateComplete.php
index 4e1249dcf..754fe28a6 100644
--- a/classes/Task/Update/UpdateComplete.php
+++ b/classes/Task/Update/UpdateComplete.php
@@ -62,13 +62,13 @@ public function run(): int
$this->next = TaskName::TASK_COMPLETE;
- if ($this->container->getUpgradeConfiguration()->get('channel') != Upgrader::CHANNEL_LOCAL && file_exists($this->container->getFilePath()) && unlink($this->container->getFilePath())) {
+ if ($this->container->getUpgradeConfiguration()->getChannel() != Upgrader::CHANNEL_LOCAL && file_exists($this->container->getFilePath()) && unlink($this->container->getFilePath())) {
$this->logger->debug($this->translator->trans('%s removed', [$this->container->getFilePath()]));
} elseif (is_file($this->container->getFilePath())) {
$this->logger->debug('' . $this->translator->trans('Please remove %s by FTP', [$this->container->getFilePath()]) . '');
}
- if ($this->container->getUpgradeConfiguration()->get('channel') != 'directory' && file_exists($this->container->getProperty(UpgradeContainer::LATEST_PATH)) && FilesystemAdapter::deleteDirectory($this->container->getProperty(UpgradeContainer::LATEST_PATH))) {
+ if (file_exists($this->container->getProperty(UpgradeContainer::LATEST_PATH)) && FilesystemAdapter::deleteDirectory($this->container->getProperty(UpgradeContainer::LATEST_PATH))) {
$this->logger->debug($this->translator->trans('%s removed', [$this->container->getProperty(UpgradeContainer::LATEST_PATH)]));
} elseif (is_dir($this->container->getProperty(UpgradeContainer::LATEST_PATH))) {
$this->logger->debug('' . $this->translator->trans('Please remove %s by FTP', [$this->container->getProperty(UpgradeContainer::LATEST_PATH)]) . '');
diff --git a/classes/Twig/Form/BackupOptionsForm.php b/classes/Twig/Form/BackupOptionsForm.php
index 49cb14558..8c2a332d0 100644
--- a/classes/Twig/Form/BackupOptionsForm.php
+++ b/classes/Twig/Form/BackupOptionsForm.php
@@ -27,6 +27,7 @@
namespace PrestaShop\Module\AutoUpgrade\Twig\Form;
+use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeConfiguration;
use PrestaShop\Module\AutoUpgrade\UpgradeTools\Translator;
class BackupOptionsForm
@@ -52,7 +53,7 @@ public function __construct(Translator $translator, FormRenderer $formRenderer)
$this->formRenderer = $formRenderer;
$this->fields = [
- 'PS_AUTOUP_BACKUP' => [
+ UpgradeConfiguration::PS_AUTOUP_BACKUP => [
'title' => $this->translator->trans('Back up my files and database'),
'cast' => 'intval',
'validation' => 'isBool',
@@ -62,7 +63,7 @@ public function __construct(Translator $translator, FormRenderer $formRenderer)
'Automatically back up your database and files in order to restore your shop if needed. This is experimental: you should still perform your own manual backup for safety.'
),
],
- 'PS_AUTOUP_KEEP_IMAGES' => [
+ UpgradeConfiguration::PS_AUTOUP_KEEP_IMAGES => [
'title' => $this->translator->trans(
'Back up my images'
),
diff --git a/classes/Twig/Form/FormRenderer.php b/classes/Twig/Form/FormRenderer.php
index 1c0de56d5..ea3849fdd 100644
--- a/classes/Twig/Form/FormRenderer.php
+++ b/classes/Twig/Form/FormRenderer.php
@@ -73,7 +73,7 @@ public function render(string $name, array $fields, string $tabname): string
$required = !empty($field['required']);
$disabled = !empty($field['disabled']);
- if ($key === 'PS_DISABLE_OVERRIDES') {
+ if ($key === UpgradeConfiguration::PS_DISABLE_OVERRIDES) {
// values fetched from configuration in database
$val = UpgradeConfiguration::isOverrideAllowed();
} else {
diff --git a/classes/Twig/Form/UpgradeOptionsForm.php b/classes/Twig/Form/UpgradeOptionsForm.php
index fbf715b56..c8b805ea0 100644
--- a/classes/Twig/Form/UpgradeOptionsForm.php
+++ b/classes/Twig/Form/UpgradeOptionsForm.php
@@ -27,6 +27,7 @@
namespace PrestaShop\Module\AutoUpgrade\Twig\Form;
+use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeConfiguration;
use PrestaShop\Module\AutoUpgrade\UpgradeTools\Translator;
class UpgradeOptionsForm
@@ -52,7 +53,7 @@ public function __construct(Translator $translator, FormRenderer $formRenderer)
$this->formRenderer = $formRenderer;
$this->fields = [
- 'PS_AUTOUP_CUSTOM_MOD_DESACT' => [
+ UpgradeConfiguration::PS_AUTOUP_CUSTOM_MOD_DESACT => [
'title' => $translator->trans('Disable non-native modules'),
'cast' => 'intval',
'validation' => 'isBool',
@@ -61,7 +62,7 @@ public function __construct(Translator $translator, FormRenderer $formRenderer)
'As non-native modules can experience some compatibility issues, we recommend to disable them by default.') . '
' .
$translator->trans('Keeping them enabled might prevent you from loading the "Modules" page properly after the upgrade.'),
],
- 'PS_DISABLE_OVERRIDES' => [
+ UpgradeConfiguration::PS_DISABLE_OVERRIDES => [
'title' => $translator->trans('Disable all overrides'),
'cast' => 'intval',
'validation' => 'isBool',
@@ -69,7 +70,7 @@ public function __construct(Translator $translator, FormRenderer $formRenderer)
'desc' => $translator->trans('Enable or disable all classes and controllers overrides.'),
],
- 'PS_AUTOUP_CHANGE_DEFAULT_THEME' => [
+ UpgradeConfiguration::PS_AUTOUP_CHANGE_DEFAULT_THEME => [
'title' => $translator->trans('Switch to the default theme'),
'cast' => 'intval',
'validation' => 'isBool',
@@ -78,7 +79,7 @@ public function __construct(Translator $translator, FormRenderer $formRenderer)
'desc' => $translator->trans('This will change your theme: your shop will then use the default theme of the version of PrestaShop you are upgrading to.'),
],
- 'PS_AUTOUP_KEEP_MAILS' => [
+ UpgradeConfiguration::PS_AUTOUP_KEEP_MAILS => [
'title' => $translator->trans('Keep the customized email templates'),
'cast' => 'intval',
'validation' => 'isBool',
diff --git a/classes/UpgradePage.php b/classes/UpgradePage.php
index 942a2a586..47882397f 100644
--- a/classes/UpgradePage.php
+++ b/classes/UpgradePage.php
@@ -269,7 +269,7 @@ private function getJsParams(string $ajaxResult): array
return [
'psBaseUri' => __PS_BASE_URI__,
'_PS_MODE_DEV_' => (defined('_PS_MODE_DEV_') && true == _PS_MODE_DEV_),
- 'PS_AUTOUP_BACKUP' => $this->config->shouldBackupFilesAndDatabase(),
+ UpgradeConfiguration::PS_AUTOUP_BACKUP => $this->config->shouldBackupFilesAndDatabase(),
'adminDir' => $adminDir,
'adminUrl' => __PS_BASE_URI__ . $adminDir,
'token' => $this->token,
@@ -277,7 +277,7 @@ private function getJsParams(string $ajaxResult): array
'ajaxUpgradeTabExists' => file_exists($this->autoupgradePath . DIRECTORY_SEPARATOR . 'ajax-upgradetab.php'),
'currentIndex' => $this->currentIndex,
'tab' => 'AdminSelfUpgrade',
- 'channel' => $this->config->get('channel'),
+ UpgradeConfiguration::CHANNEL => $this->config->getChannel(),
'autoupgrade' => [
'version' => $this->upgradeSelfCheck->getModuleVersion(),
],
diff --git a/controllers/admin/AdminSelfUpgradeController.php b/controllers/admin/AdminSelfUpgradeController.php
index 67db72af2..0cce62d01 100644
--- a/controllers/admin/AdminSelfUpgradeController.php
+++ b/controllers/admin/AdminSelfUpgradeController.php
@@ -197,7 +197,7 @@ public function __construct()
private function _setFields()
{
$this->_fieldsBackupOptions = [
- 'PS_AUTOUP_BACKUP' => [
+ UpgradeConfiguration::PS_AUTOUP_BACKUP => [
'title' => $this->trans('Back up my files and database'),
'cast' => 'intval',
'validation' => 'isBool',
@@ -205,7 +205,7 @@ private function _setFields()
'type' => 'bool',
'desc' => $this->trans('Automatically back up your database and files in order to restore your shop if needed. This is experimental: you should still perform your own manual backup for safety.'),
],
- 'PS_AUTOUP_KEEP_IMAGES' => [
+ UpgradeConfiguration::PS_AUTOUP_KEEP_IMAGES => [
'title' => $this->trans('Back up my images'),
'cast' => 'intval',
'validation' => 'isBool',
@@ -215,7 +215,7 @@ private function _setFields()
],
];
$this->_fieldsUpgradeOptions = [
- 'PS_AUTOUP_CUSTOM_MOD_DESACT' => [
+ UpgradeConfiguration::PS_AUTOUP_CUSTOM_MOD_DESACT => [
'title' => $this->trans('Disable non-native modules'),
'cast' => 'intval',
'validation' => 'isBool',
@@ -223,14 +223,14 @@ private function _setFields()
'desc' => $this->trans('As non-native modules can experience some compatibility issues, we recommend to disable them by default.') . '
' .
$this->trans('Keeping them enabled might prevent you from loading the "Modules" page properly after the upgrade.'),
],
- 'PS_DISABLE_OVERRIDES' => [
+ UpgradeConfiguration::PS_DISABLE_OVERRIDES => [
'title' => $this->trans('Disable all overrides'),
'cast' => 'intval',
'validation' => 'isBool',
'type' => 'bool',
'desc' => $this->trans('Enable or disable all classes and controllers overrides.'),
],
- 'PS_AUTOUP_CHANGE_DEFAULT_THEME' => [
+ UpgradeConfiguration::PS_AUTOUP_CHANGE_DEFAULT_THEME => [
'title' => $this->trans('Switch to the default theme'),
'cast' => 'intval',
'validation' => 'isBool',
@@ -238,7 +238,7 @@ private function _setFields()
'type' => 'bool',
'desc' => $this->trans('This will change your theme: your shop will then use the default theme of the version of PrestaShop you are upgrading to.'),
],
- 'PS_AUTOUP_KEEP_MAILS' => [
+ UpgradeConfiguration::PS_AUTOUP_KEEP_MAILS => [
'title' => $this->trans('Keep the customized email templates'),
'cast' => 'intval',
'validation' => 'isBool',
@@ -398,7 +398,7 @@ private function handleCustomSubmitAutoUpgradeForm()
continue;
}
// The PS_DISABLE_OVERRIDES variable must only be updated on the database side
- if ($key === 'PS_DISABLE_OVERRIDES') {
+ if ($key === UpgradeConfiguration::PS_DISABLE_OVERRIDES) {
UpgradeConfiguration::updatePSDisableOverrides((bool) $_POST[$key]);
} else {
$config[$key] = $_POST[$key];
diff --git a/controllers/admin/self-managed/UpdatePageVersionChoiceController.php b/controllers/admin/self-managed/UpdatePageVersionChoiceController.php
index ed98edc32..75f0a535c 100644
--- a/controllers/admin/self-managed/UpdatePageVersionChoiceController.php
+++ b/controllers/admin/self-managed/UpdatePageVersionChoiceController.php
@@ -29,6 +29,7 @@
use Exception;
use PrestaShop\Module\AutoUpgrade\AjaxResponseBuilder;
+use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeConfiguration;
use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeFileNames;
use PrestaShop\Module\AutoUpgrade\Router\Routes;
use PrestaShop\Module\AutoUpgrade\Services\DistributionApiService;
@@ -46,9 +47,9 @@ class UpdatePageVersionChoiceController extends AbstractPageController
const CURRENT_STEP = UpdateSteps::STEP_VERSION_CHOICE;
const FORM_NAME = 'version_choice';
const FORM_FIELDS = [
- 'channel' => 'channel',
- 'archive_zip' => 'archive_zip',
- 'archive_xml' => 'archive_xml',
+ UpgradeConfiguration::CHANNEL => UpgradeConfiguration::CHANNEL,
+ UpgradeConfiguration::ARCHIVE_ZIP => UpgradeConfiguration::ARCHIVE_ZIP,
+ UpgradeConfiguration::ARCHIVE_XML => UpgradeConfiguration::ARCHIVE_XML,
];
const FORM_OPTIONS = [
'online_value' => Upgrader::CHANNEL_ONLINE,
@@ -214,7 +215,7 @@ public function save(): JsonResponse
if (empty($errors)) {
if ($isLocal) {
- $file = $requestConfig['archive_zip'];
+ $file = $requestConfig[UpgradeConfiguration::ARCHIVE_ZIP];
$fullFilePath = $this->upgradeContainer->getProperty(UpgradeContainer::DOWNLOAD_PATH) . DIRECTORY_SEPARATOR . $file;
$requestConfig['archive_version_num'] = $this->upgradeContainer->getPrestashopVersionService()->extractPrestashopVersionFromZip($fullFilePath);
}
diff --git a/tests/unit/AnalyticsTest.php b/tests/unit/AnalyticsTest.php
index 69d905f04..ef8b1182d 100644
--- a/tests/unit/AnalyticsTest.php
+++ b/tests/unit/AnalyticsTest.php
@@ -37,13 +37,13 @@ public function testProperties()
->setDestinationVersion('8.8.808')
->setRestoreName('V1.2.3_blablabla-🐶');
$upgradeConfiguration = (new UpgradeConfiguration([
- 'PS_AUTOUP_CUSTOM_MOD_DESACT' => 0,
- 'PS_AUTOUP_CHANGE_DEFAULT_THEME' => 1,
- 'PS_AUTOUP_KEEP_MAILS' => 0,
- 'PS_AUTOUP_BACKUP' => 1,
- 'PS_AUTOUP_KEEP_IMAGES' => 0,
- 'channel' => 'major',
- 'archive_zip' => 'zip.zip',
+ UpgradeConfiguration::PS_AUTOUP_CUSTOM_MOD_DESACT => 0,
+ UpgradeConfiguration::PS_AUTOUP_CHANGE_DEFAULT_THEME => 1,
+ UpgradeConfiguration::PS_AUTOUP_KEEP_MAILS => 0,
+ UpgradeConfiguration::PS_AUTOUP_BACKUP => 1,
+ UpgradeConfiguration::PS_AUTOUP_KEEP_IMAGES => 0,
+ UpgradeConfiguration::CHANNEL => 'major',
+ UpgradeConfiguration::ARCHIVE_ZIP => 'zip.zip',
]));
$analytics = new Analytics(
diff --git a/tests/unit/Parameters/ConfigurationValidatorTest.php b/tests/unit/Parameters/ConfigurationValidatorTest.php
index e6ad8d806..c60304cf8 100644
--- a/tests/unit/Parameters/ConfigurationValidatorTest.php
+++ b/tests/unit/Parameters/ConfigurationValidatorTest.php
@@ -28,6 +28,7 @@
use PHPUnit\Framework\TestCase;
use PrestaShop\Module\AutoUpgrade\Parameters\ConfigurationValidator;
+use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeConfiguration;
use PrestaShop\Module\AutoUpgrade\UpgradeTools\Translator;
class ConfigurationValidatorTest extends TestCase
@@ -48,10 +49,10 @@ protected function setUp()
public function testValidateChannelSuccess()
{
- $result = $this->validator->validate(['channel' => 'online']);
+ $result = $this->validator->validate([UpgradeConfiguration::CHANNEL => 'online']);
$this->assertEmpty($result);
- $result = $this->validator->validate(['channel' => 'local']);
+ $result = $this->validator->validate([UpgradeConfiguration::CHANNEL => 'local']);
$this->assertEmpty($result);
}
@@ -59,57 +60,57 @@ public function testValidateChannelFail()
{
$channel = 'toto';
- $result = $this->validator->validate(['channel' => $channel]);
+ $result = $this->validator->validate([UpgradeConfiguration::CHANNEL => $channel]);
$this->assertEquals([
[
'message' => 'Unknown channel ' . $channel,
- 'target' => 'channel',
+ 'target' => UpgradeConfiguration::CHANNEL,
],
], $result);
}
public function testValidateZipSuccess()
{
- $result = $this->validator->validate(['archive_zip' => 'prestashop.zip']);
+ $result = $this->validator->validate([UpgradeConfiguration::ARCHIVE_ZIP => 'prestashop.zip']);
$this->assertEmpty($result);
- $result = $this->validator->validate(['channel' => 'local', 'archive_zip' => 'prestashop.zip']);
+ $result = $this->validator->validate([UpgradeConfiguration::CHANNEL => 'local', UpgradeConfiguration::ARCHIVE_ZIP => 'prestashop.zip']);
$this->assertEmpty($result);
- $result = $this->validator->validate(['channel' => 'online', 'archive_zip' => '']);
+ $result = $this->validator->validate([UpgradeConfiguration::CHANNEL => 'online', UpgradeConfiguration::ARCHIVE_ZIP => '']);
$this->assertEmpty($result);
}
public function testValidateZipFail()
{
- $result = $this->validator->validate(['channel' => 'local', 'archive_zip' => '']);
+ $result = $this->validator->validate([UpgradeConfiguration::CHANNEL => 'local', UpgradeConfiguration::ARCHIVE_ZIP => '']);
$this->assertEquals([
[
'message' => 'No zip archive provided',
- 'target' => 'archive_zip',
+ 'target' => UpgradeConfiguration::ARCHIVE_ZIP,
],
], $result);
}
public function testValidateXmlSuccess()
{
- $result = $this->validator->validate(['archive_xml' => 'prestashop.xml']);
+ $result = $this->validator->validate([UpgradeConfiguration::ARCHIVE_XML => 'prestashop.xml']);
$this->assertEmpty($result);
- $result = $this->validator->validate(['channel' => 'local', 'archive_xml' => 'prestashop.xml']);
+ $result = $this->validator->validate([UpgradeConfiguration::CHANNEL => 'local', UpgradeConfiguration::ARCHIVE_XML => 'prestashop.xml']);
$this->assertEmpty($result);
- $result = $this->validator->validate(['channel' => 'online', 'archive_xml' => '']);
+ $result = $this->validator->validate([UpgradeConfiguration::CHANNEL => 'online', UpgradeConfiguration::ARCHIVE_XML => '']);
$this->assertEmpty($result);
}
public function testValidateXmlFail()
{
- $result = $this->validator->validate(['channel' => 'local', 'archive_xml' => '']);
+ $result = $this->validator->validate([UpgradeConfiguration::CHANNEL => 'local', UpgradeConfiguration::ARCHIVE_XML => '']);
$this->assertEquals([
[
'message' => 'No xml archive provided',
- 'target' => 'archive_xml',
+ 'target' => UpgradeConfiguration::ARCHIVE_XML,
],
], $result);
}
@@ -119,26 +120,26 @@ public function testValidateBoolSuccess()
$validValues = ['1', '0', 'true', 'false', 'on', 'off'];
foreach ($validValues as $value) {
- $result = $this->validator->validate(['PS_AUTOUP_CUSTOM_MOD_DESACT' => $value]);
+ $result = $this->validator->validate([UpgradeConfiguration::PS_AUTOUP_CUSTOM_MOD_DESACT => $value]);
$this->assertEmpty($result);
}
}
public function testValidateBoolFail()
{
- $result = $this->validator->validate(['PS_AUTOUP_CUSTOM_MOD_DESACT' => 'toto']);
+ $result = $this->validator->validate([UpgradeConfiguration::PS_AUTOUP_CUSTOM_MOD_DESACT => 'toto']);
$this->assertEquals([
[
- 'message' => 'Value must be a boolean for PS_AUTOUP_CUSTOM_MOD_DESACT',
- 'target' => 'PS_AUTOUP_CUSTOM_MOD_DESACT',
+ 'message' => 'Value must be a boolean for ' . UpgradeConfiguration::PS_AUTOUP_CUSTOM_MOD_DESACT,
+ 'target' => UpgradeConfiguration::PS_AUTOUP_CUSTOM_MOD_DESACT,
],
], $result);
- $result = $this->validator->validate(['PS_AUTOUP_CUSTOM_MOD_DESACT' => '']);
+ $result = $this->validator->validate([UpgradeConfiguration::PS_AUTOUP_CUSTOM_MOD_DESACT => '']);
$this->assertEquals([
[
- 'message' => 'Value must be a boolean for PS_AUTOUP_CUSTOM_MOD_DESACT',
- 'target' => 'PS_AUTOUP_CUSTOM_MOD_DESACT',
+ 'message' => 'Value must be a boolean for ' . UpgradeConfiguration::PS_AUTOUP_CUSTOM_MOD_DESACT,
+ 'target' => UpgradeConfiguration::PS_AUTOUP_CUSTOM_MOD_DESACT,
],
], $result);
}
@@ -146,19 +147,19 @@ public function testValidateBoolFail()
public function testValidateMultipleInputFail()
{
$result = $this->validator->validate([
- 'channel' => 'local',
- 'archive_zip' => '',
- 'archive_xml' => '',
+ UpgradeConfiguration::CHANNEL => 'local',
+ UpgradeConfiguration::ARCHIVE_ZIP => '',
+ UpgradeConfiguration::ARCHIVE_XML => '',
]);
$this->assertEquals([
[
'message' => 'No zip archive provided',
- 'target' => 'archive_zip',
+ 'target' => UpgradeConfiguration::ARCHIVE_ZIP,
],
[
'message' => 'No xml archive provided',
- 'target' => 'archive_xml',
+ 'target' => UpgradeConfiguration::ARCHIVE_XML,
],
], $result);
}
diff --git a/tests/unit/Parameters/LocalChannelConfigurationValidatorTest.php b/tests/unit/Parameters/LocalChannelConfigurationValidatorTest.php
index b70f85020..7a927a632 100644
--- a/tests/unit/Parameters/LocalChannelConfigurationValidatorTest.php
+++ b/tests/unit/Parameters/LocalChannelConfigurationValidatorTest.php
@@ -2,6 +2,7 @@
use PHPUnit\Framework\TestCase;
use PrestaShop\Module\AutoUpgrade\Parameters\LocalChannelConfigurationValidator;
+use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeConfiguration;
use PrestaShop\Module\AutoUpgrade\UpgradeContainer;
class LocalChannelConfigurationValidatorTest extends TestCase
@@ -26,51 +27,51 @@ protected function setUp(): void
public function testValidateReturnsErrorIfZipFileDoesNotExist()
{
- $data = ['archive_zip' => 'non_existent.zip', 'archive_xml' => 'versioned_8.1.0.xml'];
+ $data = [UpgradeConfiguration::ARCHIVE_ZIP => 'non_existent.zip', UpgradeConfiguration::ARCHIVE_XML => 'versioned_8.1.0.xml'];
$result = $this->validator->validate($data);
$this->assertSame([
- 'message' => 'File ' . $data['archive_zip'] . ' does not exist. Unable to select that channel.',
- 'target' => 'archive_zip',
+ 'message' => 'File ' . $data[UpgradeConfiguration::ARCHIVE_ZIP] . ' does not exist. Unable to select that channel.',
+ 'target' => UpgradeConfiguration::ARCHIVE_ZIP,
], $result[0]);
}
public function testValidateReturnsErrorIfNotVersionedZipFile()
{
- $data = ['archive_zip' => 'not_versioned_8.2.0.zip', 'archive_xml' => 'versioned_8.1.0.xml'];
+ $data = [UpgradeConfiguration::ARCHIVE_ZIP => 'not_versioned_8.2.0.zip', UpgradeConfiguration::ARCHIVE_XML => 'versioned_8.1.0.xml'];
$result = $this->validator->validate($data);
$this->assertSame([
'message' => 'We couldn\'t find a PrestaShop version in the .zip file that was uploaded in your local archive. Please try again.',
- 'target' => 'archive_zip',
+ 'target' => UpgradeConfiguration::ARCHIVE_ZIP,
], $result[0]);
}
public function testValidateReturnsErrorIfXmlFileDoesNotExist()
{
- $data = ['archive_zip' => 'versioned_8.2.0.zip', 'archive_xml' => 'non_existent.xml'];
+ $data = [UpgradeConfiguration::ARCHIVE_ZIP => 'versioned_8.2.0.zip', UpgradeConfiguration::ARCHIVE_XML => 'non_existent.xml'];
$result = $this->validator->validate($data);
$this->assertSame([
- 'message' => 'File ' . $data['archive_xml'] . ' does not exist. Unable to select that channel.',
- 'target' => 'archive_xml',
+ 'message' => 'File ' . $data[UpgradeConfiguration::ARCHIVE_XML] . ' does not exist. Unable to select that channel.',
+ 'target' => UpgradeConfiguration::ARCHIVE_XML,
], $result[0]);
}
public function testValidateReturnsErrorIfNotVersionedXmlFile()
{
- $data = ['archive_zip' => 'versioned_8.2.0.zip', 'archive_xml' => 'not_versioned_8.2.0.xml'];
+ $data = [UpgradeConfiguration::ARCHIVE_ZIP => 'versioned_8.2.0.zip', UpgradeConfiguration::ARCHIVE_XML => 'not_versioned_8.2.0.xml'];
$result = $this->validator->validate($data);
$this->assertSame([
'message' => 'We couldn\'t find a PrestaShop version in the XML file that was uploaded in your local archive. Please try again.',
- 'target' => 'archive_xml',
+ 'target' => UpgradeConfiguration::ARCHIVE_XML,
], $result[0]);
}
public function testValidateReturnsErrorIfVersionsDoNotMatch()
{
- $data = ['archive_zip' => 'versioned_8.2.0.zip', 'archive_xml' => 'versioned_8.1.0.xml'];
+ $data = [UpgradeConfiguration::ARCHIVE_ZIP => 'versioned_8.2.0.zip', UpgradeConfiguration::ARCHIVE_XML => 'versioned_8.1.0.xml'];
$result = $this->validator->validate($data);
$this->assertSame([
@@ -80,7 +81,7 @@ public function testValidateReturnsErrorIfVersionsDoNotMatch()
public function testValidatePassesWithValidFiles()
{
- $data = ['archive_zip' => 'versioned_8.2.0.zip', 'archive_xml' => 'versioned_8.2.0.xml'];
+ $data = [UpgradeConfiguration::ARCHIVE_ZIP => 'versioned_8.2.0.zip', UpgradeConfiguration::ARCHIVE_XML => 'versioned_8.2.0.xml'];
$result = $this->validator->validate($data);
$this->assertEmpty($result);
diff --git a/tests/unit/UpgradeContainer/FilesystemAdapterTest.php b/tests/unit/UpgradeContainer/FilesystemAdapterTest.php
index b583e980c..9400f8fda 100644
--- a/tests/unit/UpgradeContainer/FilesystemAdapterTest.php
+++ b/tests/unit/UpgradeContainer/FilesystemAdapterTest.php
@@ -26,6 +26,7 @@
*/
use PHPUnit\Framework\TestCase;
+use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeConfiguration;
use PrestaShop\Module\AutoUpgrade\UpgradeContainer;
class FilesystemAdapterTest extends TestCase
@@ -76,7 +77,7 @@ public function testListFilesInDirForUpgrade()
public function testListFilesInDirForBackupWithImages()
{
- $this->container->getUpgradeConfiguration()->set('PS_AUTOUP_KEEP_IMAGES', true);
+ $this->container->getUpgradeConfiguration()->set(UpgradeConfiguration::PS_AUTOUP_KEEP_IMAGES, true);
$expected = $this->loadFixtureAndAddPrefixToFilePaths(
__DIR__ . '/../../fixtures/listOfFiles-backup-with-images.json',
self::$pathToFakeShop
@@ -93,7 +94,7 @@ public function testListFilesInDirForBackupWithImages()
public function testListFilesInDirForBackupWithoutImages()
{
- $this->container->getUpgradeConfiguration()->set('PS_AUTOUP_KEEP_IMAGES', false);
+ $this->container->getUpgradeConfiguration()->set(UpgradeConfiguration::PS_AUTOUP_KEEP_IMAGES, false);
$expected = $this->loadFixtureAndAddPrefixToFilePaths(
__DIR__ . '/../../fixtures/listOfFiles-backup-without-images.json',
self::$pathToFakeShop
@@ -110,7 +111,7 @@ public function testListFilesInDirForBackupWithoutImages()
public function testListFilesInDirForRestoreWithImages()
{
- $this->container->getUpgradeConfiguration()->set('PS_AUTOUP_KEEP_IMAGES', true);
+ $this->container->getUpgradeConfiguration()->set(UpgradeConfiguration::PS_AUTOUP_KEEP_IMAGES, true);
$expected = $this->loadFixtureAndAddPrefixToFilePaths(
__DIR__ . '/../../fixtures/listOfFiles-restore-with-images.json',
self::$pathToFakeShop
@@ -127,7 +128,7 @@ public function testListFilesInDirForRestoreWithImages()
public function testListFilesInDirForRestoreWithoutImages()
{
- $this->container->getUpgradeConfiguration()->set('PS_AUTOUP_KEEP_IMAGES', false);
+ $this->container->getUpgradeConfiguration()->set(UpgradeConfiguration::PS_AUTOUP_KEEP_IMAGES, false);
$expected = $this->loadFixtureAndAddPrefixToFilePaths(
__DIR__ . '/../../fixtures/listOfFiles-restore-without-images.json',
self::$pathToFakeShop