Skip to content

Commit 92a74b7

Browse files
authored
Merge pull request #1663 from ga-devfront/refacto/config-files
Refacto config files
2 parents 8f4ebce + ac5cced commit 92a74b7

80 files changed

Lines changed: 2066 additions & 898 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/upgrade-cli.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ jobs:
9393
\"channel\":\"${{ matrix.UPGRADE_CHANNEL }}\",
9494
\"archive_zip\":\"prestashop_${{ matrix.PS_VERSION_END }}.zip\",
9595
\"archive_xml\":\"prestashop_${{ matrix.PS_VERSION_END }}.xml\",
96-
\"PS_AUTOUP_CUSTOM_MOD_DESACT\":\"true\",
96+
\"disable_non_native_modules\":\"true\",
9797
\"PS_AUTOUP_CHANGE_DEFAULT_THEME\":\"false\",
98-
\"PS_AUTOUP_KEEP_IMAGES\":\"true\",
99-
\"PS_DISABLE_OVERRIDES\":\"true\"
98+
\"keep_images\":\"true\",
99+
\"disable_overrides\":\"true\"
100100
}' > modules/autoupgrade/config.json"
101101
102102
- name: Update online

README.md

Lines changed: 231 additions & 136 deletions
Large diffs are not rendered by default.

_dev/src/ts/appUI/dialogs/StartBackupDialog.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export default class StartBackupDialog extends DialogAbstract {
4848
await api.post(form.dataset.routeToSubmit!, new FormData(form));
4949

5050
analytics.track('[SUE] Backup configured', {
51-
backup_images: !!dataOptions.get('PS_AUTOUP_KEEP_IMAGES')
51+
backup_images: !!dataOptions.get('keep_images')
5252
});
5353

5454
this.dispatchDialogContainerOkEvent(event);

_dev/src/ts/appUI/pages/UpdatePageUpdateOptions.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ export default class UpdatePageUpdateOptions extends StepPage {
6868
const data = new FormData(this.#form);
6969

7070
analytics.track('[SUE] Update options configured', {
71-
disable_all_overrides: !!data.get('PS_DISABLE_OVERRIDES'),
72-
disable_non_native_modules: !!data.get('PS_AUTOUP_CUSTOM_MOD_DESACT'),
73-
regenerate_customized_email_templates: !!data.get('PS_AUTOUP_REGEN_EMAIL')
71+
disable_all_overrides: !!data.get('disable_overrides'),
72+
disable_non_native_modules: !!data.get('disable_non_native_modules'),
73+
regenerate_customized_email_templates: !!data.get('regenerate_email_templates')
7474
});
7575

7676
await api.post(this.#form.dataset.routeToSubmit!, data);

classes/AjaxResponse.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
namespace PrestaShop\Module\AutoUpgrade;
2323

2424
use PrestaShop\Module\AutoUpgrade\Log\Logger;
25-
use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeConfiguration;
25+
use PrestaShop\Module\AutoUpgrade\Parameters\UpdateConfiguration;
2626
use PrestaShop\Module\AutoUpgrade\State\AbstractState;
2727

2828
/**
@@ -63,9 +63,9 @@ class AjaxResponse
6363
const RESPONSE_FORMAT = 'json';
6464

6565
/**
66-
* @var UpgradeConfiguration
66+
* @var UpdateConfiguration
6767
*/
68-
private $upgradeConfiguration;
68+
private $updateConfiguration;
6969

7070
/**
7171
* @var Logger
@@ -101,7 +101,7 @@ public function getResponse(): array
101101
$this->state->export(),
102102
[
103103
'typeResult' => self::RESPONSE_FORMAT,
104-
'config' => $this->upgradeConfiguration->toArray(),
104+
'config' => $this->updateConfiguration->toArray(),
105105
]
106106
),
107107
];
@@ -145,9 +145,9 @@ public function getNextParams(): array
145145
return $this->nextParams;
146146
}
147147

148-
public function getUpgradeConfiguration(): UpgradeConfiguration
148+
public function getUpdateConfiguration(): UpdateConfiguration
149149
{
150-
return $this->upgradeConfiguration;
150+
return $this->updateConfiguration;
151151
}
152152

153153
// SETTERS
@@ -183,9 +183,9 @@ public function setNextParams(array $nextParams): AjaxResponse
183183
return $this;
184184
}
185185

186-
public function setUpgradeConfiguration(UpgradeConfiguration $upgradeConfiguration): AjaxResponse
186+
public function setUpdateConfiguration(UpdateConfiguration $updateConfiguration): AjaxResponse
187187
{
188-
$this->upgradeConfiguration = $upgradeConfiguration;
188+
$this->updateConfiguration = $updateConfiguration;
189189

190190
return $this;
191191
}

classes/Analytics.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121

2222
namespace PrestaShop\Module\AutoUpgrade;
2323

24-
use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeConfiguration;
24+
use PrestaShop\Module\AutoUpgrade\Parameters\BackupConfiguration;
25+
use PrestaShop\Module\AutoUpgrade\Parameters\UpdateConfiguration;
2526
use PrestaShop\Module\AutoUpgrade\State\RestoreState;
2627
use PrestaShop\Module\AutoUpgrade\State\UpdateState;
2728

@@ -48,10 +49,15 @@ class Analytics
4849
private $properties;
4950

5051
/**
51-
* @var UpgradeConfiguration
52+
* @var UpdateConfiguration
5253
*/
5354
private $updateConfiguration;
5455

56+
/**
57+
* @var BackupConfiguration
58+
*/
59+
private $backupConfiguration;
60+
5561
/**
5662
* @var array{'restore': RestoreState, 'update': UpdateState}
5763
*/
@@ -67,13 +73,15 @@ class Analytics
6773
* @param array{'restore': RestoreState, 'update': UpdateState} $states
6874
*/
6975
public function __construct(
70-
UpgradeConfiguration $updateConfiguration,
76+
UpdateConfiguration $updateConfiguration,
77+
BackupConfiguration $backupConfiguration,
7178
Environment $environment,
7279
array $states,
7380
string $anonymousUserId,
7481
array $options
7582
) {
7683
$this->updateConfiguration = $updateConfiguration;
84+
$this->backupConfiguration = $backupConfiguration;
7785
$this->states = $states;
7886

7987
$this->anonymousId = $anonymousUserId;
@@ -122,7 +130,7 @@ public function getProperties($type): array
122130
switch ($type) {
123131
case self::WITH_BACKUP_PROPERTIES:
124132
$additionalProperties = [
125-
'backup_images' => $this->updateConfiguration->shouldBackupImages(),
133+
'backup_images' => $this->backupConfiguration->shouldBackupImages(),
126134
];
127135
$upgradeProperties = $this->properties[self::WITH_BACKUP_PROPERTIES] ?? [];
128136
$additionalProperties = array_merge($upgradeProperties, $additionalProperties);

classes/Commands/AbstractCommand.php

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
use PrestaShop\Module\AutoUpgrade\ErrorHandler;
2727
use PrestaShop\Module\AutoUpgrade\Log\CliLogger;
2828
use PrestaShop\Module\AutoUpgrade\Log\Logger;
29+
use PrestaShop\Module\AutoUpgrade\Parameters\Loader\AbstractConfigurationLoader;
2930
use PrestaShop\Module\AutoUpgrade\Task\ExitCode;
30-
use PrestaShop\Module\AutoUpgrade\Task\Miscellaneous\UpdateConfig;
3131
use PrestaShop\Module\AutoUpgrade\UpgradeContainer;
3232
use Symfony\Component\Console\Command\Command;
3333
use Symfony\Component\Console\Input\InputInterface;
@@ -98,16 +98,9 @@ protected function setupEnvironment(InputInterface $input, OutputInterface $outp
9898
/**
9999
* @throws Exception
100100
*/
101-
protected function loadConfiguration(?string $configPath): int
101+
protected function loadConfiguration(AbstractConfigurationLoader $loader, ?string $configPath): int
102102
{
103-
$updateConfiguration = $this->upgradeContainer->getUpdateConfiguration();
104-
if (!$updateConfiguration->hasAllTheShopConfiguration()) {
105-
$this->upgradeContainer->initPrestaShopCore();
106-
$this->upgradeContainer->getPrestaShopConfiguration()->fillInUpdateConfiguration($updateConfiguration);
107-
}
108-
$this->upgradeContainer->getConfigurationStorage()->save($updateConfiguration);
109-
110-
$controller = new UpdateConfig($this->upgradeContainer);
103+
$loader->initialize($this->upgradeContainer);
111104

112105
$configurationData = [];
113106

@@ -134,12 +127,27 @@ protected function loadConfiguration(?string $configPath): int
134127
if (!empty($configurationData)) {
135128
$this->logger->debug('Following configuration will be used for the process: ' . json_encode($configurationData));
136129

137-
$controller->inputCliParameters($configurationData);
138-
$controller->init();
139-
140-
return $controller->run();
130+
try {
131+
return $loader->load($configurationData);
132+
} catch (Exception $e) {
133+
return ExitCode::FAIL;
134+
}
141135
}
142136

143137
return ExitCode::SUCCESS;
144138
}
139+
140+
/**
141+
* @param InputInterface $input
142+
* @param array<string, string> $options
143+
*/
144+
protected function processConsoleInputConfiguration(InputInterface $input, array $options): void
145+
{
146+
foreach ($options as $configKey => $optionName) {
147+
$optionValue = $input->getOption($optionName);
148+
if ($optionValue !== null) {
149+
$this->consoleInputConfiguration[$configKey] = $optionValue;
150+
}
151+
}
152+
}
145153
}

classes/Commands/CheckModulesCommand.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
use Exception;
2525
use PrestaShop\Module\AutoUpgrade\Models\Module\Marketplace\ModuleUpgradeCompatibility;
26-
use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeConfiguration;
26+
use PrestaShop\Module\AutoUpgrade\Parameters\UpdateConfiguration;
2727
use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeFileNames;
2828
use PrestaShop\Module\AutoUpgrade\Services\PhpVersionResolverService;
2929
use PrestaShop\Module\AutoUpgrade\Task\ExitCode;
@@ -50,7 +50,7 @@ protected function configure(): void
5050
'channel',
5151
null,
5252
InputOption::VALUE_REQUIRED,
53-
"Select which update channel to use ('" . UpgradeConfiguration::CHANNEL_LOCAL . "' / '" . UpgradeConfiguration::CHANNEL_ONLINE_RECOMMENDED . "' / '" . UpgradeConfiguration::CHANNEL_ONLINE . "')"
53+
"Select which update channel to use ('" . UpdateConfiguration::CHANNEL_LOCAL . "' / '" . UpdateConfiguration::CHANNEL_ONLINE_RECOMMENDED . "' / '" . UpdateConfiguration::CHANNEL_ONLINE . "')"
5454
)
5555
->addOption('zip', null, InputOption::VALUE_REQUIRED, 'Sets the archive zip file for a local channel.')
5656
->addOption('xml', null, InputOption::VALUE_REQUIRED, 'Sets the archive xml file for a local update.')
@@ -69,9 +69,9 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int
6969
$this->upgradeContainer->getFileStorage()->clean(UpgradeFileNames::UPDATE_CONFIG_FILENAME);
7070

7171
$options = [
72-
UpgradeConfiguration::ARCHIVE_ZIP => 'zip',
73-
UpgradeConfiguration::ARCHIVE_XML => 'xml',
74-
UpgradeConfiguration::CHANNEL => 'channel',
72+
UpdateConfiguration::ARCHIVE_ZIP => 'zip',
73+
UpdateConfiguration::ARCHIVE_XML => 'xml',
74+
UpdateConfiguration::CHANNEL => 'channel',
7575
];
7676
foreach ($options as $configKey => $optionName) {
7777
$optionValue = $input->getOption($optionName);
@@ -81,7 +81,8 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int
8181
}
8282

8383
$configPath = $input->getOption('config-file-path');
84-
$exitCode = $this->loadConfiguration($configPath);
84+
$loader = $this->upgradeContainer->getUpdateConfigurationLoader();
85+
$exitCode = $this->loadConfiguration($loader, $configPath);
8586
if ($exitCode !== ExitCode::SUCCESS) {
8687
return $exitCode;
8788
}
@@ -92,7 +93,7 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int
9293
$config = $this->upgradeContainer->getUpdateConfiguration();
9394
$channel = $config->getChannelOrDefault();
9495

95-
if ($channel === UpgradeConfiguration::CHANNEL_ONLINE_RECOMMENDED || $channel === UpgradeConfiguration::CHANNEL_ONLINE) {
96+
if ($channel === UpdateConfiguration::CHANNEL_ONLINE_RECOMMENDED || $channel === UpdateConfiguration::CHANNEL_ONLINE) {
9697
$targetPsVersion = $this->upgradeContainer->getUpgrader()->getOnlineDestinationVersionForChannel($channel);
9798
} else {
9899
$zip = $config->getChannelZip();
@@ -146,6 +147,8 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int
146147
} catch (Exception $e) {
147148
$this->logger->error("An error occurred during the check process:\n" . $e);
148149
throw $e;
150+
} finally {
151+
$this->upgradeContainer->getFileStorage()->clean(UpgradeFileNames::UPDATE_CONFIG_FILENAME);
149152
}
150153
}
151154

classes/Commands/CheckNewVersionCommand.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
use Exception;
2525
use PrestaShop\Module\AutoUpgrade\Exceptions\DistributionApiException;
2626
use PrestaShop\Module\AutoUpgrade\Exceptions\ProcessException;
27-
use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeConfiguration;
27+
use PrestaShop\Module\AutoUpgrade\Parameters\UpdateConfiguration;
2828
use PrestaShop\Module\AutoUpgrade\Services\LocalVersionFilesService;
2929
use PrestaShop\Module\AutoUpgrade\Task\ExitCode;
3030
use PrestaShop\Module\AutoUpgrade\UpgradeContainer;
@@ -70,7 +70,7 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int
7070
$updateType = VersionUtils::getUpdateType($currentVersion, $localVersion);
7171
$zipFiles = 'Zip: ' . implode(', ', $files[LocalVersionFilesService::TYPE_ZIP]) . "\n";
7272
$xmlFiles = 'Xml: ' . implode(', ', $files[LocalVersionFilesService::TYPE_XML]);
73-
$rows[] = [$localVersion, UpgradeConfiguration::CHANNEL_LOCAL, $updateType, $zipFiles . $xmlFiles];
73+
$rows[] = [$localVersion, UpdateConfiguration::CHANNEL_LOCAL, $updateType, $zipFiles . $xmlFiles];
7474
}
7575

7676
// sort by newest
@@ -86,13 +86,13 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int
8686
if ($onlineMaxRelease && ($onlineRecommendedRelease === null || $onlineMaxRelease->getVersion() !== $onlineRecommendedRelease->getVersion())) {
8787
$destinationVersion = $onlineMaxRelease->getVersion();
8888
$updateType = VersionUtils::getUpdateType($currentVersion, $destinationVersion);
89-
array_unshift($rows, [$destinationVersion, UpgradeConfiguration::CHANNEL_ONLINE, $updateType, $onlineMaxRelease->getReleaseNoteUrl()]);
89+
array_unshift($rows, [$destinationVersion, UpdateConfiguration::CHANNEL_ONLINE, $updateType, $onlineMaxRelease->getReleaseNoteUrl()]);
9090
}
9191

9292
if ($onlineRecommendedRelease) {
9393
$destinationVersion = $onlineRecommendedRelease->getVersion();
9494
$updateType = VersionUtils::getUpdateType($currentVersion, $destinationVersion);
95-
array_unshift($rows, [$destinationVersion, UpgradeConfiguration::CHANNEL_ONLINE_RECOMMENDED, $updateType, $onlineRecommendedRelease->getReleaseNoteUrl()]);
95+
array_unshift($rows, [$destinationVersion, UpdateConfiguration::CHANNEL_ONLINE_RECOMMENDED, $updateType, $onlineRecommendedRelease->getReleaseNoteUrl()]);
9696
}
9797

9898
$table = new Table($output);

classes/Commands/CheckRequirementsCommand.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
use Exception;
2525
use PrestaShop\Module\AutoUpgrade\Exceptions\DistributionApiException;
2626
use PrestaShop\Module\AutoUpgrade\Exceptions\ProcessException;
27-
use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeConfiguration;
27+
use PrestaShop\Module\AutoUpgrade\Parameters\UpdateConfiguration;
2828
use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeFileNames;
2929
use PrestaShop\Module\AutoUpgrade\Task\ExitCode;
3030
use PrestaShop\Module\AutoUpgrade\UpgradeSelfCheck;
@@ -48,7 +48,7 @@ protected function configure(): void
4848
->setDescription('Check all prerequisites for an update.')
4949
->setHelp('This command allows you to check the prerequisites necessary for the proper functioning of an update.')
5050
->addOption('config-file-path', null, InputOption::VALUE_REQUIRED, 'Configuration file location for update.')
51-
->addOption('channel', null, InputOption::VALUE_REQUIRED, "Selects what update to run ('" . UpgradeConfiguration::CHANNEL_LOCAL . "' / '" . UpgradeConfiguration::CHANNEL_ONLINE_RECOMMENDED . "' / '" . UpgradeConfiguration::CHANNEL_ONLINE . "')")
51+
->addOption('channel', null, InputOption::VALUE_REQUIRED, "Selects what update to run ('" . UpdateConfiguration::CHANNEL_LOCAL . "' / '" . UpdateConfiguration::CHANNEL_ONLINE_RECOMMENDED . "' / '" . UpdateConfiguration::CHANNEL_ONLINE . "')")
5252
->addOption('zip', null, InputOption::VALUE_REQUIRED, 'Sets the archive zip file for a local update.')
5353
->addOption('xml', null, InputOption::VALUE_REQUIRED, 'Sets the archive xml file for a local update.')
5454
->addArgument('admin-dir', InputArgument::REQUIRED, 'The admin directory name.');
@@ -65,9 +65,9 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int
6565
$this->output = $output;
6666

6767
$options = [
68-
UpgradeConfiguration::ARCHIVE_ZIP => 'zip',
69-
UpgradeConfiguration::ARCHIVE_XML => 'xml',
70-
UpgradeConfiguration::CHANNEL => 'channel',
68+
UpdateConfiguration::ARCHIVE_ZIP => 'zip',
69+
UpdateConfiguration::ARCHIVE_XML => 'xml',
70+
UpdateConfiguration::CHANNEL => 'channel',
7171
];
7272
foreach ($options as $configKey => $optionName) {
7373
$optionValue = $input->getOption($optionName);
@@ -77,7 +77,8 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int
7777
}
7878

7979
$configPath = $input->getOption('config-file-path');
80-
$exitCode = $this->loadConfiguration($configPath);
80+
$loader = $this->upgradeContainer->getUpdateConfigurationLoader();
81+
$exitCode = $this->loadConfiguration($loader, $configPath);
8182
if ($exitCode !== ExitCode::SUCCESS) {
8283
return $exitCode;
8384
}
@@ -99,6 +100,8 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int
99100
} catch (Exception $e) {
100101
$this->logger->error("An error occurred during the check requirements process:\n" . $e);
101102
throw $e;
103+
} finally {
104+
$this->upgradeContainer->getFileStorage()->clean(UpgradeFileNames::UPDATE_CONFIG_FILENAME);
102105
}
103106
}
104107

0 commit comments

Comments
 (0)