Skip to content

Commit

Permalink
Merge pull request #944 from M0rgan01/add_version_choice_save
Browse files Browse the repository at this point in the history
Improve VersionChoiceController, implement save method
  • Loading branch information
ga-devfront authored Oct 7, 2024
2 parents 89b1b9f + 89a5559 commit a4881ed
Show file tree
Hide file tree
Showing 11 changed files with 94 additions and 194 deletions.
11 changes: 8 additions & 3 deletions classes/Parameters/UpgradeConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,22 @@ class UpgradeConfiguration extends ArrayCollection
/**
* Get the name of the new release archive.
*/
public function getArchiveFilename(): string
public function getArchiveZip(): string
{
return $this->get('archive.filename');
return $this->get('archive_zip');
}

public function getArchiveXml(): string
{
return $this->get('archive_xml');
}

/**
* Get the version included in the new release.
*/
public function getArchiveVersion(): string
{
return $this->get('archive.version_num');
return $this->get('archive_version_num');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion classes/Parameters/UpgradeConfigurationStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function getDefaultData(): array
{
return array_merge(UpgradeConfiguration::PS_CONST_DEFAULT_VALUE, [
'channel' => Upgrader::DEFAULT_CHANNEL,
'archive.filename' => Upgrader::DEFAULT_FILENAME,
'archive_zip' => Upgrader::DEFAULT_FILENAME,
]);
}
}
12 changes: 6 additions & 6 deletions classes/Task/Miscellaneous/UpdateConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ public function run(): int
// update channel
if (isset($configurationData['channel'])) {
$config['channel'] = $configurationData['channel'];
$config['archive.filename'] = Upgrader::DEFAULT_FILENAME;
$config['archive_zip'] = Upgrader::DEFAULT_FILENAME;
}

if (!empty($configurationData['archive_prestashop'])) {
$file = $configurationData['archive_prestashop'];
if (!empty($configurationData['archive_zip'])) {
$file = $configurationData['archive_zip'];
$fullFilePath = $this->container->getProperty(UpgradeContainer::DOWNLOAD_PATH) . DIRECTORY_SEPARATOR . $file;
if (!file_exists($fullFilePath)) {
$this->setErrorFlag();
Expand Down Expand Up @@ -114,9 +114,9 @@ public function run(): int
}

$config['channel'] = Upgrader::CHANNEL_LOCAL;
$config['archive.filename'] = $configurationData['archive_prestashop'];
$config['archive.version_num'] = $targetVersion;
$config['archive.xml'] = $configurationData['archive_xml'];
$config['archive_zip'] = $configurationData['archive_zip'];
$config['archive_version_num'] = $targetVersion;
$config['archive_xml'] = $configurationData['archive_xml'];

$this->logger->info($this->translator->trans('Upgrade process will use archive.'));
}
Expand Down
6 changes: 3 additions & 3 deletions classes/Twig/Block/UpgradeButtonBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ public function getTemplateVars(): array
],
'archiveFiles' => $dir,
'xmlFiles' => $xml,
'archiveFileName' => $this->config->get('archive.filename'),
'xmlFileName' => $this->config->get('archive.xml'),
'archiveVersionNumber' => $this->config->get('archive.version_num'),
'archiveFileName' => $this->config->getArchiveZip(),
'xmlFileName' => $this->config->getArchiveXml(),
'archiveVersionNumber' => $this->config->getArchiveVersion(),
'downloadPath' => $this->downloadPath . DIRECTORY_SEPARATOR,
'directoryVersionNumber' => $this->config->get('directory.version_num'),
'phpVersion' => PHP_VERSION,
Expand Down
4 changes: 2 additions & 2 deletions classes/UpgradeContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ public function getProperty(string $property): string
case self::LOGS_PATH:
return $this->autoupgradeWorkDir . DIRECTORY_SEPARATOR . 'logs';
case self::ARCHIVE_FILENAME:
return $this->getUpgradeConfiguration()->getArchiveFilename();
return $this->getUpgradeConfiguration()->getArchiveZip();
case self::ARCHIVE_FILEPATH:
return $this->getProperty(self::DOWNLOAD_PATH) . DIRECTORY_SEPARATOR . $this->getProperty(self::ARCHIVE_FILENAME);
case self::PS_VERSION:
Expand Down Expand Up @@ -439,7 +439,7 @@ public function getUpgrader(): Upgrader
$this->getState()->setOriginVersion($this->getProperty(self::PS_VERSION));

if ($upgrader->getChannel() === Upgrader::CHANNEL_LOCAL) {
$archiveXml = $this->getUpgradeConfiguration()->get('archive.xml');
$archiveXml = $this->getUpgradeConfiguration()->getArchiveXml();
$this->fileLoader->addXmlMd5File($upgrader->getDestinationVersion(), $this->getProperty(self::DOWNLOAD_PATH) . DIRECTORY_SEPARATOR . $archiveXml);
}

Expand Down
2 changes: 1 addition & 1 deletion classes/Upgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public function getOnlineDestinationRelease(): ?PrestashopRelease
public function getDestinationVersion(): ?string
{
if ($this->channel === self::CHANNEL_LOCAL) {
return $this->upgradeConfiguration->get('archive.version_num');
return $this->upgradeConfiguration->getArchiveVersion();
} else {
return $this->getOnlineDestinationRelease() ? $this->getOnlineDestinationRelease()->getVersion() : null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,15 @@

namespace PrestaShop\Module\AutoUpgrade\Controller;

use Exception;
use PrestaShop\Module\AutoUpgrade\Router\Routes;
use PrestaShop\Module\AutoUpgrade\Services\DistributionApiService;
use PrestaShop\Module\AutoUpgrade\Services\PhpVersionResolverService;
use PrestaShop\Module\AutoUpgrade\Task\Miscellaneous\UpdateConfig;
use PrestaShop\Module\AutoUpgrade\Twig\UpdateSteps;
use PrestaShop\Module\AutoUpgrade\UpgradeContainer;
use PrestaShop\Module\AutoUpgrade\Upgrader;
use PrestaShop\Module\AutoUpgrade\UpgradeSelfCheck;
use PrestaShop\Module\AutoUpgrade\VersionUtils;
use Symfony\Component\HttpFoundation\JsonResponse;
use Twig\Error\LoaderError;
Expand All @@ -41,7 +48,7 @@ class UpdatePageVersionChoiceController extends AbstractPageController
const CURRENT_ROUTE = Routes::UPDATE_PAGE_VERSION_CHOICE;
const CURRENT_STEP = UpdateSteps::STEP_VERSION_CHOICE;
const FORM_FIELDS = [
'canal_choice' => 'canal_choice',
'channel' => 'channel',
'archive_zip' => 'archive_zip',
'archive_xml' => 'archive_xml',
];
Expand Down Expand Up @@ -124,8 +131,63 @@ protected function getParams(): array
);
}

public function save()
/**
* @throws Exception
*/
public function save(): string
{
$channel = $this->request->get(self::FORM_FIELDS['canal_choice']);

$controller = new UpdateConfig($this->upgradeContainer);
$controller->init();
$controller->run();

$distributionApiService = new DistributionApiService();
$phpVersionResolverService = new PhpVersionResolverService(
$distributionApiService,
$this->upgradeContainer->getFileLoader(),
$this->upgradeContainer->getState()->getOriginVersion()
);

$upgradeSelfCheck = new UpgradeSelfCheck(
$this->upgradeContainer->getUpgrader(),
$this->upgradeContainer->getPrestaShopConfiguration(),
$this->upgradeContainer->getTranslator(),
$phpVersionResolverService,
$this->upgradeContainer->getChecksumCompare(),
_PS_ROOT_DIR_,
_PS_ADMIN_DIR_,
$this->upgradeContainer->getProperty(UpgradeContainer::WORKSPACE_PATH),
$this->upgradeContainer->getState()->getOriginVersion()
);

$warnings = $upgradeSelfCheck->getWarnings();
foreach ($warnings as $warning) {
$warnings[$warning] = $upgradeSelfCheck->getRequirementWording($warning);
}

$errors = $upgradeSelfCheck->getErrors();
foreach ($errors as $error) {
$errors[$error] = $upgradeSelfCheck->getRequirementWording($error);
}

$params = [
'requirementsOk' => empty($errors),
'warnings' => $warnings,
'errors' => $errors,
];

if ($channel === Upgrader::CHANNEL_LOCAL) {
return $this->twig->render(
'@ModuleAutoUpgrade/components/radio-card-archive.html.twig',
$params
);
}

return $this->twig->render(
'@ModuleAutoUpgrade/components/radio-card-online.html.twig',
$params
);
}

public function submit()
Expand Down
2 changes: 1 addition & 1 deletion js/upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ $(document).ready(function () {
return false;
}
params.channel = "local";
params.archive_prestashop = archive_prestashop;
params.archive_zip = archive_prestashop;
params.archive_xml = archive_xml;
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/AnalyticsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function testProperties()
'PS_AUTOUP_BACKUP' => 1,
'PS_AUTOUP_KEEP_IMAGES' => 0,
'channel' => 'major',
'archive.filename' => 'zip.zip',
'archive_zip' => 'zip.zip',
]));

$analytics = new Analytics(
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Progress/CompletionCalculatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private function getCompletionCalculator(bool $withBackup): CompletionCalculator
'skip_backup' => !$withBackup,
'PS_AUTOUP_KEEP_IMAGES' => 0,
'channel' => 'major',
'archive.filename' => 'zip.zip',
'archive_zip' => 'zip.zip',
])
);
}
Expand Down
Loading

0 comments on commit a4881ed

Please sign in to comment.