Skip to content

Commit

Permalink
Merge pull request #1057 from M0rgan01/update-checksum-compare
Browse files Browse the repository at this point in the history
[CLI] Split warning regarding modified files
  • Loading branch information
M0rgan01 authored Dec 12, 2024
2 parents c4a358f + 223e379 commit 97045a8
Show file tree
Hide file tree
Showing 18 changed files with 5,642 additions and 243 deletions.
3 changes: 2 additions & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
->in(__DIR__)
->exclude('vendor')
->exclude('node_modules')
->exclude('storybook/var/cache');
->exclude('storybook/var/cache')
->exclude('tests/fixtures/checksum-compare');

return $config;
42 changes: 38 additions & 4 deletions classes/Commands/CheckRequirementsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,44 @@ private function processRequirementWarnings(): void
foreach ($this->upgradeSelfCheck->getWarnings() as $warning => $value) {
$wording = $this->upgradeSelfCheck->getRequirementWording($warning);
$this->writeWarning($wording['message']);
if (isset($wording['list'])) {
foreach ($wording['list'] as $item) {
$this->output->writeln(' ' . $item);
}

switch ($warning) {
case UpgradeSelfCheck::CORE_TEMPERED_FILES_LIST_NOT_EMPTY:
$missingFiles = $this->upgradeSelfCheck->getCoreMissingFiles();

$this->output->writeln("\t" . count($missingFiles) . ' files are missing:');
foreach ($missingFiles as $missingFile) {
$this->output->writeln("\t\t" . $missingFile);
}

$alteredFiles = $this->upgradeSelfCheck->getCoreAlteredFiles();

$this->output->writeln("\t" . count($alteredFiles) . ' files are altered:');
foreach ($alteredFiles as $alteredFile) {
$this->output->writeln("\t\t" . $alteredFile);
}
break;
case UpgradeSelfCheck::THEME_TEMPERED_FILES_LIST_NOT_EMPTY:
$missingFiles = $this->upgradeSelfCheck->getThemeMissingFiles();

$this->output->writeln("\t" . count($missingFiles) . ' files are missing:');
foreach ($missingFiles as $missingFile) {
$this->output->writeln("\t\t" . $missingFile);
}

$alteredFiles = $this->upgradeSelfCheck->getThemeAlteredFiles();

$this->output->writeln("\t" . count($alteredFiles) . ' files are altered:');
foreach ($alteredFiles as $alteredFile) {
$this->output->writeln("\t\t" . $alteredFile);
}
break;
default:
if (isset($wording['list'])) {
foreach ($wording['list'] as $item) {
$this->output->writeln("\t" . $item);
}
}
}
}
}
Expand Down
18 changes: 0 additions & 18 deletions classes/Parameters/UpgradeFileNames.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,22 +127,6 @@ class UpgradeFileNames
*/
const FILES_FROM_ARCHIVE_LIST = 'filesFromArchive.list';

/**
* mailCustomList contains list of mails files which are customized,
* relative to original files for the current PrestaShop version.
*
* @var string
*/
const MAILS_CUSTOM_LIST = 'mails-custom.list';

/**
* tradCustomList contains list of translation files which are customized,
* relative to original files for the current PrestaShop version.
*
* @var string
*/
const TRANSLATION_FILES_CUSTOM_LIST = 'translations-custom.list';

/**
* Module Sources Providers are classes that fetching & compute data
* from the filesystem or an external resource like an API.
Expand All @@ -167,8 +151,6 @@ class UpgradeFileNames
'FILES_TO_UPGRADE_LIST' => self::FILES_TO_UPGRADE_LIST,
'DB_TABLES_TO_CLEAN_LIST' => self::DB_TABLES_TO_CLEAN_LIST,
'FILES_TO_REMOVE_LIST' => self::FILES_TO_REMOVE_LIST,
'MAILS_CUSTOM_LIST' => self::MAILS_CUSTOM_LIST,
'TRANSLATION_FILES_CUSTOM_LIST' => self::TRANSLATION_FILES_CUSTOM_LIST,
'MODULES_TO_UPGRADE_LIST' => self::MODULES_TO_UPGRADE_LIST,
'MODULE_SOURCE_PROVIDER_CACHE_LOCAL' => self::MODULE_SOURCE_PROVIDER_CACHE_LOCAL,
'MODULE_SOURCE_PROVIDER_CACHE_COMPOSER' => self::MODULE_SOURCE_PROVIDER_CACHE_COMPOSER,
Expand Down
80 changes: 0 additions & 80 deletions classes/Task/Miscellaneous/CheckFilesVersion.php

This file was deleted.

1 change: 0 additions & 1 deletion classes/Task/TaskName.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ class TaskName
const TASK_UNZIP = 'Unzip';

// MISC
const TASK_CHECK_FILES_VERSION = 'CheckFilesVersion';
const TASK_COMPARE_RELEASES = 'CompareReleases';
const TASK_UPDATE_CONFIG = 'UpdateConfig';
}
4 changes: 3 additions & 1 deletion classes/UpgradeContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,9 @@ public function getChecksumCompare(): ChecksumCompare

$this->checksumCompare = new ChecksumCompare(
$this->getFileLoader(),
$this->getFilesystemAdapter()
$this->getFilesystemAdapter(),
$this->getProperty(self::PS_ROOT_PATH),
$this->getProperty(self::PS_ADMIN_PATH)
);

return $this->checksumCompare;
Expand Down
74 changes: 66 additions & 8 deletions classes/UpgradeSelfCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ class UpgradeSelfCheck
// Warnings const
const MODULE_VERSION_IS_OUT_OF_DATE = 17;
const PHP_COMPATIBILITY_UNKNOWN = 18;
const TEMPERED_FILES_LIST_NOT_EMPTY = 19;
const CORE_TEMPERED_FILES_LIST_NOT_EMPTY = 19;
const THEME_TEMPERED_FILES_LIST_NOT_EMPTY = 20;

public function __construct(
Upgrader $upgrader,
Expand Down Expand Up @@ -186,7 +187,8 @@ public function getWarnings(): array
{
$warnings = [
self::MODULE_VERSION_IS_OUT_OF_DATE => !$this->isModuleVersionLatest(),
self::TEMPERED_FILES_LIST_NOT_EMPTY => !empty($this->getTamperedFiles()),
self::CORE_TEMPERED_FILES_LIST_NOT_EMPTY => !empty($this->getCoreAlteredFiles()) || !empty($this->getCoreMissingFiles()),
self::THEME_TEMPERED_FILES_LIST_NOT_EMPTY => !empty($this->getThemeAlteredFiles()) || !empty($this->getThemeMissingFiles()),
];

if ($this->upgradeConfiguration->isChannelLocal()) {
Expand Down Expand Up @@ -363,10 +365,36 @@ public function getRequirementWording(int $requirement, bool $isWebVersion = fal
),
];

case self::TEMPERED_FILES_LIST_NOT_EMPTY:
case self::CORE_TEMPERED_FILES_LIST_NOT_EMPTY:
if ($isWebVersion) {
// TODO the link must be integrated when implementing the modal in the web part
$params = [
'[1]' => '<a class="" href="" target="">',
'[/1]' => '</a>',
];
$message = $this->translator->trans('Some core files have been altered or removed. Any changes made to these files may be overwritten during the update. [1]See the list of alterations.[/1]', $params);
} else {
$message = $this->translator->trans('Some core files have been altered or removed. Any changes made to these files may be overwritten during the update.');
}

return [
'message' => $this->translator->trans('Some core files have been altered, customization made on these files will be lost during the update: '),
'list' => $this->getTamperedFiles(),
'message' => $message,
];

case self::THEME_TEMPERED_FILES_LIST_NOT_EMPTY:
if ($isWebVersion) {
// TODO the link must be integrated when implementing the modal in the web part
$params = [
'[1]' => '<a class="" href="" target="">',
'[/1]' => '</a>',
];
$message = $this->translator->trans('Some theme files have been altered or removed. Any changes made to these files may be overwritten during the update. [1]See the list of alterations.[/1]', $params);
} else {
$message = $this->translator->trans('Some theme files have been altered or removed. Any changes made to these files may be overwritten during the update.');
}

return [
'message' => $message,
];

default:
Expand All @@ -379,11 +407,41 @@ public function getRequirementWording(int $requirement, bool $isWebVersion = fal
/**
* @return string[]
*/
public function getTamperedFiles(): array
public function getCoreMissingFiles(): array
{
$missingFiles = $this->checksumCompare->getTamperedFilesOnShop($this->state->getCurrentVersion());

return array_merge($missingFiles['core']['missing'], $missingFiles['mail']['missing']);
}

/**
* @return string[]
*/
public function getCoreAlteredFiles(): array
{
$alteredFiles = $this->checksumCompare->getTamperedFilesOnShop($this->state->getCurrentVersion());

return array_merge($alteredFiles['core']['altered'], $alteredFiles['mail']['altered']);
}

/**
* @return string[]
*/
public function getThemeMissingFiles(): array
{
$missingFiles = $this->checksumCompare->getTamperedFilesOnShop($this->state->getCurrentVersion());

return $missingFiles['themes']['missing'];
}

/**
* @return string[]
*/
public function getThemeAlteredFiles(): array
{
$tamperedFiles = $this->checksumCompare->getTamperedFilesOnShop($this->state->getCurrentVersion());
$alteredFiles = $this->checksumCompare->getTamperedFilesOnShop($this->state->getCurrentVersion());

return array_merge($tamperedFiles['core'], $tamperedFiles['mail']);
return $alteredFiles['themes']['altered'];
}

public function isFOpenOrCurlEnabled(): bool
Expand Down
3 changes: 0 additions & 3 deletions classes/UpgradeTools/TaskRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
use PrestaShop\Module\AutoUpgrade\Task\Backup\BackupDatabase;
use PrestaShop\Module\AutoUpgrade\Task\Backup\BackupFiles;
use PrestaShop\Module\AutoUpgrade\Task\Backup\BackupInitialization;
use PrestaShop\Module\AutoUpgrade\Task\Miscellaneous\CheckFilesVersion;
use PrestaShop\Module\AutoUpgrade\Task\Miscellaneous\CompareReleases;
use PrestaShop\Module\AutoUpgrade\Task\Miscellaneous\UpdateConfig;
use PrestaShop\Module\AutoUpgrade\Task\NullTask;
Expand All @@ -58,8 +57,6 @@ public static function get(string $step, UpgradeContainer $container): AbstractT
{
switch ($step) {
// MISCELLANEOUS (upgrade configuration, checks etc.)
case TaskName::TASK_CHECK_FILES_VERSION:
return new CheckFilesVersion($container);
case TaskName::TASK_COMPARE_RELEASES:
return new CompareReleases($container);
case TaskName::TASK_UPDATE_CONFIG:
Expand Down
Loading

0 comments on commit 97045a8

Please sign in to comment.