Skip to content

Commit

Permalink
Improve default configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Morgan Pichat committed Oct 18, 2024
1 parent 8eda85a commit 308423b
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 27 deletions.
8 changes: 6 additions & 2 deletions classes/Commands/UpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int

// in the case of commands containing the update status, it is not necessary to update the configuration
// also we do not want to repeat the update of the config in the recursive commands
if (!$input->hasOption('data')) {
if ($input->getOption('data') === null) {
$configPath = $input->getOption('config-file-path');
$exitCode = $this->loadConfiguration($configPath, $this->upgradeContainer);
if ($exitCode !== ExitCode::SUCCESS) {
Expand Down Expand Up @@ -118,6 +118,10 @@ private function chainCommand(OutputInterface $output): int
{
$lastInfo = $this->logger->getLastInfo();

if (!$lastInfo) {
return ExitCode::SUCCESS;
}

if (strpos($lastInfo, 'bin/console update:start') !== false) {
if (preg_match('/--action=(\S+)/', $lastInfo, $actionMatches)) {
$action = $actionMatches[1];
Expand All @@ -133,7 +137,7 @@ private function chainCommand(OutputInterface $output): int

return ExitCode::FAIL;
}
$new_string = str_replace('INFO - $ ', '', $this->logger->getLastInfo());
$new_string = str_replace('INFO - $ ', '', $lastInfo);
$decorationParam = $output->isDecorated() ? ' --ansi' : '';
system('php ' . $new_string . $decorationParam, $exitCode);

Expand Down
4 changes: 2 additions & 2 deletions classes/Log/CliLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class CliLogger extends Logger
protected $err;

/**
* @var string
* @var ?string
*/
protected $lastInfo;

Expand Down Expand Up @@ -160,7 +160,7 @@ private function formatLog(int $level, string $message): string
/**
* {@inheritdoc}
*/
public function getLastInfo(): string
public function getLastInfo(): ?string
{
return $this->lastInfo;
}
Expand Down
7 changes: 1 addition & 6 deletions classes/Log/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,8 @@ public function getInfos(): array
* Return the last message stored with the INFO level.
* Equivalent of the old $next_desc
* Used during upgrade. Will be displayed on the top left panel.
*
* @return string Stores the main information about the current step
*/
public function getLastInfo(): string
{
return '';
}
abstract public function getLastInfo(): ?string;

public function updateLogsPath(string $logsPath): void
{
Expand Down
6 changes: 3 additions & 3 deletions classes/Log/WebLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class WebLogger extends Logger
/** @var string[] */
protected $severeMessages = [];

/** @var string */
protected $lastInfo = '';
/** @var ?string */
protected $lastInfo;

/**
* {@inheritdoc}
Expand All @@ -65,7 +65,7 @@ public function getInfos(): array
/**
* {@inheritdoc}
*/
public function getLastInfo(): string
public function getLastInfo(): ?string
{
return $this->lastInfo;
}
Expand Down
24 changes: 19 additions & 5 deletions classes/Parameters/UpgradeConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

use Configuration;
use Doctrine\Common\Collections\ArrayCollection;
use PrestaShop\Module\AutoUpgrade\Upgrader;
use Shop;
use UnexpectedValueException;

Expand Down Expand Up @@ -60,6 +61,9 @@ class UpgradeConfiguration extends ArrayCollection
'PS_AUTOUP_KEEP_IMAGES' => 1,
];

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

/**
* Performance settings, if your server has a low memory size, lower these values.
*
Expand Down Expand Up @@ -138,39 +142,49 @@ public function getMaxFileToBackup(): int

public function shouldBackupFilesAndDatabase(): bool
{
return filter_var($this->get('PS_AUTOUP_BACKUP'), FILTER_VALIDATE_BOOLEAN);
$currentValue = filter_var($this->get('PS_AUTOUP_BACKUP'), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);

return $currentValue ?? self::PS_CONST_DEFAULT_VALUE['PS_AUTOUP_BACKUP'];
}

/**
* @return bool True if the autoupgrade module backup should include the images
*/
public function shouldBackupImages(): bool
{
return filter_var($this->get('PS_AUTOUP_KEEP_IMAGES'), FILTER_VALIDATE_BOOLEAN);
$currentValue = filter_var($this->get('PS_AUTOUP_KEEP_IMAGES'), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);

return $currentValue ?? self::PS_CONST_DEFAULT_VALUE['PS_AUTOUP_KEEP_IMAGES'];
}

/**
* @return bool True if non-native modules must be disabled during upgrade
*/
public function shouldDeactivateCustomModules(): bool
{
return filter_var($this->get('PS_AUTOUP_CUSTOM_MOD_DESACT'), FILTER_VALIDATE_BOOLEAN);
$currentValue = filter_var($this->get('PS_AUTOUP_CUSTOM_MOD_DESACT'), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);

return $currentValue ?? self::PS_CONST_DEFAULT_VALUE['PS_AUTOUP_CUSTOM_MOD_DESACT'];
}

/**
* @return bool true if we should keep the merchant emails untouched
*/
public function shouldKeepMails(): bool
{
return filter_var($this->get('PS_AUTOUP_KEEP_MAILS'), FILTER_VALIDATE_BOOLEAN);
$currentValue = filter_var($this->get('PS_AUTOUP_KEEP_MAILS'), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);

return $currentValue ?? self::PS_CONST_DEFAULT_VALUE['PS_AUTOUP_KEEP_MAILS'];
}

/**
* @return bool True if we have to set the native theme by default
*/
public function shouldSwitchToDefaultTheme(): bool
{
return filter_var($this->get('PS_AUTOUP_CHANGE_DEFAULT_THEME'), FILTER_VALIDATE_BOOLEAN);
$currentValue = filter_var($this->get('PS_AUTOUP_CHANGE_DEFAULT_THEME'), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);

return $currentValue ?? self::PS_CONST_DEFAULT_VALUE['PS_AUTOUP_CHANGE_DEFAULT_THEME'];
}

public static function isOverrideAllowed(): bool
Expand Down
2 changes: 1 addition & 1 deletion classes/Task/Miscellaneous/UpdateConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function run(): int

$this->container->getUpgradeConfiguration()->validate($config);

if ($config['channel'] === Upgrader::CHANNEL_LOCAL) {
if (isset($config['channel']) && $config['channel'] === Upgrader::CHANNEL_LOCAL) {
$file = $config['archive_zip'];
$fullFilePath = $this->container->getProperty(UpgradeContainer::DOWNLOAD_PATH) . DIRECTORY_SEPARATOR . $file;
if (!file_exists($fullFilePath)) {
Expand Down
15 changes: 11 additions & 4 deletions classes/Task/Update/Download.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,17 @@ public function run(): int
$report = '';
$relative_download_path = str_replace(_PS_ROOT_DIR_, '', $this->container->getProperty(UpgradeContainer::DOWNLOAD_PATH));
if (\ConfigurationTest::test_dir($relative_download_path, false, $report)) {
$res = $upgrader->downloadLast(
$this->container->getProperty(UpgradeContainer::DOWNLOAD_PATH),
$this->container->getProperty(UpgradeContainer::ARCHIVE_FILENAME)
);
$archiveFileName = $this->container->getUpgradeConfiguration()->getArchiveZip();
if ($archiveFileName) {
$res = $upgrader->downloadLast(
$this->container->getProperty(UpgradeContainer::DOWNLOAD_PATH),
$archiveFileName
);
} else {
$res = $upgrader->downloadLast(
$this->container->getProperty(UpgradeContainer::DOWNLOAD_PATH)
);
}
if ($res) {
$md5file = md5_file(realpath($this->container->getProperty(UpgradeContainer::ARCHIVE_FILEPATH)));
if ($md5file == $upgrader->getOnlineDestinationRelease()->getZipMd5()) {
Expand Down
6 changes: 2 additions & 4 deletions classes/Upgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ class Upgrader
const CHANNEL_LOCAL = 'local';

const DEFAULT_CHECK_VERSION_DELAY_HOURS = 12;
const DEFAULT_CHANNEL = self::CHANNEL_ONLINE;
const DEFAULT_FILENAME = 'prestashop.zip';

/** @var self::CHANNEL_* */
private $channel;
Expand All @@ -64,7 +62,7 @@ public function __construct(
) {
$this->currentPsVersion = $currentPsVersion;
$this->phpVersionResolverService = $phpRequirementService;
$this->channel = $upgradeConfiguration->getChannel() ?? self::DEFAULT_CHANNEL;
$this->channel = $upgradeConfiguration->getChannel() ?? UpgradeConfiguration::DEFAULT_CHANNEL;
$this->upgradeConfiguration = $upgradeConfiguration;
}

Expand All @@ -79,7 +77,7 @@ public function __construct(
*
* @TODO ftp if copy is not possible (safe_mode for example)
*/
public function downloadLast(string $dest, ?string $filename = self::DEFAULT_FILENAME): bool
public function downloadLast(string $dest, string $filename = UpgradeConfiguration::DEFAULT_FILENAME): bool

Check failure on line 80 in classes/Upgrader.php

View workflow job for this annotation

GitHub Actions / PHPStan (1.7.2.5)

PHPDoc tag @param for parameter $filename with type string|null is not subtype of native type string.

Check failure on line 80 in classes/Upgrader.php

View workflow job for this annotation

GitHub Actions / PHPStan (1.7.3.4)

PHPDoc tag @param for parameter $filename with type string|null is not subtype of native type string.

Check failure on line 80 in classes/Upgrader.php

View workflow job for this annotation

GitHub Actions / PHPStan (1.7.4.4)

PHPDoc tag @param for parameter $filename with type string|null is not subtype of native type string.

Check failure on line 80 in classes/Upgrader.php

View workflow job for this annotation

GitHub Actions / PHPStan (1.7.5.1)

PHPDoc tag @param for parameter $filename with type string|null is not subtype of native type string.

Check failure on line 80 in classes/Upgrader.php

View workflow job for this annotation

GitHub Actions / PHPStan (1.7.6)

PHPDoc tag @param for parameter $filename with type string|null is not subtype of native type string.

Check failure on line 80 in classes/Upgrader.php

View workflow job for this annotation

GitHub Actions / PHPStan (1.7.7)

PHPDoc tag @param for parameter $filename with type string|null is not subtype of native type string.

Check failure on line 80 in classes/Upgrader.php

View workflow job for this annotation

GitHub Actions / PHPStan (1.7.8)

PHPDoc tag @param for parameter $filename with type string|null is not subtype of native type string.
{
if ($this->onlineDestinationRelease === null) {
$this->getOnlineDestinationRelease();
Expand Down

0 comments on commit 308423b

Please sign in to comment.