Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions classes/UpgradeTools/CoreUpgrader/CoreUpgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -703,9 +703,6 @@ protected function cleanXmlFiles(): void
{
$files = [
$this->container->getProperty(UpgradeContainer::PS_ADMIN_PATH) . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . 'default' . DIRECTORY_SEPARATOR . 'template' . DIRECTORY_SEPARATOR . 'controllers' . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . 'header.tpl',
_PS_ROOT_DIR_ . '/app/cache/dev/class_index.php',
_PS_ROOT_DIR_ . '/app/cache/prod/class_index.php',
_PS_ROOT_DIR_ . '/cache/class_index.php',
_PS_ROOT_DIR_ . '/config/xml/blog-fr.xml',
_PS_ROOT_DIR_ . '/config/xml/default_country_modules_list.xml',
_PS_ROOT_DIR_ . '/config/xml/modules_list.xml',
Expand All @@ -714,8 +711,6 @@ protected function cleanXmlFiles(): void
_PS_ROOT_DIR_ . '/config/xml/tab_modules_list.xml',
_PS_ROOT_DIR_ . '/config/xml/trusted_modules_list.xml',
_PS_ROOT_DIR_ . '/config/xml/untrusted_modules_list.xml',
_PS_ROOT_DIR_ . '/var/cache/dev/class_index.php',
_PS_ROOT_DIR_ . '/var/cache/prod/class_index.php',
];
foreach ($files as $path) {
if ($this->fileSystem->exists($path)) {
Expand Down
27 changes: 18 additions & 9 deletions classes/UpgradeTools/FilesystemAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@

namespace PrestaShop\Module\AutoUpgrade\UpgradeTools;

use CallbackFilterIterator;
use FilesystemIterator;
use IteratorIterator;
use RecursiveCallbackFilterIterator;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
Expand Down Expand Up @@ -242,17 +244,24 @@ public function clearDirectory(string $folderToClear): bool
{
$hasDeletedItems = false;

if ($this->filesystem->exists($folderToClear)) {
foreach (scandir($folderToClear) as $item) {
if ($item !== '.' && $item !== '..' && $item !== 'index.php') {
$path = $folderToClear . DIRECTORY_SEPARATOR . $item;
$this->filesystem->remove($path);
if (!$this->filesystem->exists($folderToClear)) {
return $hasDeletedItems;
}

$hasDeletedItems = true;
}
}
$directory = new FilesystemIterator(
$folderToClear, FilesystemIterator::SKIP_DOTS | FilesystemIterator::CURRENT_AS_FILEINFO
);
$filter = new CallbackFilterIterator($directory, function ($current) {
return $current->getFilename() !== 'index.php';
});
$iterator = new IteratorIterator($filter);

foreach ($iterator as $file) {
$this->filesystem->remove($file);
}

return $hasDeletedItems;
clearstatcache();

return (bool) iterator_count($iterator);
}
}