Skip to content

Commit

Permalink
Fix fileDifferences cache
Browse files Browse the repository at this point in the history
  • Loading branch information
M0rgan01 committed Dec 17, 2024
1 parent 2015ff9 commit c5f595c
Showing 1 changed file with 40 additions and 18 deletions.
58 changes: 40 additions & 18 deletions classes/Xml/ChecksumCompare.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ class ChecksumCompare
* @var string
*/
private $adminPath;

private const CATEGORY_MAIL = 'mail';
private const CATEGORY_TRANSLATION = 'translation';
private const CATEGORY_CORE = 'core';
private const CATEGORY_THEME = 'themes';

private const FILE_MISSING = 'missing';
private const FILE_ALTERED = 'altered';
/**
* @var array{
* 'mail':array{'missing':string[],'altered':string[]},
Expand All @@ -57,21 +65,21 @@ class ChecksumCompare
* }|false
*/
private $fileDifferences = [
'mail' => [
'missing' => [],
'altered' => [],
self::CATEGORY_MAIL => [
self::FILE_MISSING => [],
self::FILE_ALTERED => [],
],
'translation' => [
'missing' => [],
'altered' => [],
self::CATEGORY_TRANSLATION => [
self::FILE_MISSING => [],
self::FILE_ALTERED => [],
],
'core' => [
'missing' => [],
'altered' => [],
self::CATEGORY_CORE => [
self::FILE_MISSING => [],
self::FILE_ALTERED => [],
],
'themes' => [
'missing' => [],
'altered' => [],
self::CATEGORY_THEME => [
self::FILE_MISSING => [],
self::FILE_ALTERED => [],
],
];

Expand Down Expand Up @@ -116,7 +124,21 @@ public function getFilesDiffBetweenVersions(string $version1, ?string $version2)
*/
public function getTamperedFilesOnShop(string $version)
{
if (is_array($this->fileDifferences) && count($this->fileDifferences['core']['altered']) == 0) {
if (is_array($this->fileDifferences)) {
$useCache = false;

foreach ($this->fileDifferences as $section) {
foreach ([self::FILE_MISSING, self::FILE_ALTERED] as $key) {
if (!empty($section[$key])) {
$useCache = true;
}
}
}

if ($useCache) {
return $this->fileDifferences;
}

$checksum = $this->fileLoader->getXmlMd5File($version);
if (!$checksum) {
$this->fileDifferences = false;
Expand Down Expand Up @@ -250,15 +272,15 @@ protected function md5FileAsArray(SimpleXMLElement $node, string $dir = '/')
*/
protected function addFileDifferences(string $path, bool $isDeletedFile = false): void
{
$key = $isDeletedFile ? 'missing' : 'altered';
$key = $isDeletedFile ? self::FILE_MISSING : self::FILE_ALTERED;

$categories = [
'mail' => ['mails/'],
'translation' => [
self::CATEGORY_MAIL => ['mails/'],
self::CATEGORY_TRANSLATION => [
'/en.php', '/fr.php', '/es.php', '/it.php', '/de.php',
'translations/',
],
'themes' => ['themes/'],
self::CATEGORY_THEME => ['themes/'],
];

foreach ($categories as $category => $patterns) {
Expand All @@ -271,7 +293,7 @@ protected function addFileDifferences(string $path, bool $isDeletedFile = false)
}
}

$this->fileDifferences['core'][$key][] = $path;
$this->fileDifferences[self::CATEGORY_CORE][$key][] = $path;
}

protected function compareChecksum(string $filepath, string $md5sum): bool
Expand Down

0 comments on commit c5f595c

Please sign in to comment.