Skip to content

Commit

Permalink
Improve UpgradeConfiguration naming
Browse files Browse the repository at this point in the history
  • Loading branch information
Morgan Pichat authored and ga-devfront committed Oct 24, 2024
1 parent 4f27e21 commit 349e60c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 15 deletions.
17 changes: 13 additions & 4 deletions classes/Parameters/UpgradeConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class UpgradeConfiguration extends ArrayCollection
];

const DEFAULT_CHANNEL = Upgrader::CHANNEL_ONLINE;
const DEFAULT_FILENAME = 'prestashop.zip';
const ONLINE_CHANNEL_ZIP = 'prestashop.zip';

/**
* Performance settings, if your server has a low memory size, lower these values.
Expand All @@ -82,20 +82,29 @@ class UpgradeConfiguration extends ArrayCollection
/**
* Get the name of the new release archive.
*/
public function getArchiveZip(): ?string
public function getLocalChannelZip(): ?string
{
return $this->get('archive_zip');
}

public function getArchiveXml(): ?string
public function getChannelZip(): ?string
{
if ($this->getChannel() === Upgrader::CHANNEL_LOCAL) {
$this->getLocalChannelZip();
}

return self::ONLINE_CHANNEL_ZIP;
}

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

/**
* Get the version included in the new release.
*/
public function getArchiveVersion(): ?string
public function getLocalChannelVersion(): ?string
{
return $this->get('archive_version_num');
}
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->getArchiveZip(),
'xmlFileName' => $this->config->getArchiveXml(),
'archiveVersionNumber' => $this->config->getArchiveVersion(),
'archiveFileName' => $this->config->getLocalChannelZip(),
'xmlFileName' => $this->config->getLocalChannelXml(),
'archiveVersionNumber' => $this->config->getLocalChannelVersion(),
'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()->getArchiveZip() ? $this->getUpgradeConfiguration()->getArchiveZip() : UpgradeConfiguration::DEFAULT_FILENAME;
return $this->getUpgradeConfiguration()->getChannelZip();
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()->getArchiveXml();
$archiveXml = $this->getUpgradeConfiguration()->getLocalChannelXml();
$this->fileLoader->addXmlMd5File($upgrader->getDestinationVersion(), $this->getProperty(self::DOWNLOAD_PATH) . DIRECTORY_SEPARATOR . $archiveXml);
}

Expand Down
4 changes: 2 additions & 2 deletions classes/Upgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function __construct(
*
* @TODO ftp if copy is not possible (safe_mode for example)
*/
public function downloadLast(string $dest, string $filename = UpgradeConfiguration::DEFAULT_FILENAME): bool
public function downloadLast(string $dest, string $filename): bool
{
if ($this->onlineDestinationRelease === null) {
$this->getOnlineDestinationRelease();
Expand Down Expand Up @@ -146,7 +146,7 @@ public function getOnlineDestinationRelease(): ?PrestashopRelease
public function getDestinationVersion(): ?string
{
if ($this->channel === self::CHANNEL_LOCAL) {
return $this->upgradeConfiguration->getArchiveVersion();
return $this->upgradeConfiguration->getLocalChannelVersion();
} else {
return $this->getOnlineDestinationRelease() ? $this->getOnlineDestinationRelease()->getVersion() : null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,17 @@ protected function getParams(): array
'form_options' => self::FORM_OPTIONS,
'current_values' => [
self::FORM_FIELDS['channel'] => $currentChannel,
self::FORM_FIELDS['archive_zip'] => $upgradeConfiguration->getArchiveZip(),
self::FORM_FIELDS['archive_xml'] => $upgradeConfiguration->getArchiveXml(),
self::FORM_FIELDS['archive_zip'] => $upgradeConfiguration->getLocalChannelZip(),
self::FORM_FIELDS['archive_xml'] => $upgradeConfiguration->getLocalChannelXml(),
],
]
);

if ($currentChannel === self::FORM_OPTIONS['online_value'] ||
(
$currentChannel === self::FORM_OPTIONS['local_value']
&& in_array($upgradeConfiguration->getArchiveZip(), $archiveRepository->getZipLocalArchive())
&& in_array($upgradeConfiguration->getArchiveXml(), $archiveRepository->getXmlLocalArchive())
&& in_array($upgradeConfiguration->getLocalChannelZip(), $archiveRepository->getZipLocalArchive())
&& in_array($upgradeConfiguration->getLocalChannelXml(), $archiveRepository->getXmlLocalArchive())
)
) {
$params[$currentChannel . '_requirements'] = $this->getRequirements();
Expand Down

0 comments on commit 349e60c

Please sign in to comment.