Commit fea0bdcf authored by Oliver Hader's avatar Oliver Hader Committed by Susanne Moog
Browse files

[BUGFIX] Consider all elements in typo3temp/assets/ when clearing

Only first level elements were considered when clearing assets in
typo3temp/assets/ using corresponding functionality in maintenance
section of the TYPO3 install tool.

Resolves: #89569
Releases: master, 9.5
Change-Id: I9237aa3c6200b57cf4da256531b25062f52708ee
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/62179


Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Tested-by: Susanne Moog's avatarSusanne Moog <look@susi.dev>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Daniel Goerz's avatarDaniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Susanne Moog's avatarSusanne Moog <look@susi.dev>
parent 4e880df6
...@@ -114,7 +114,7 @@ class Typo3tempFileService ...@@ -114,7 +114,7 @@ class Typo3tempFileService
} }
/** /**
* Clear files in a typo3temp/assets/ folder (not _processed_!) * Clears files and folders in a typo3temp/assets/ folder (not _processed_!)
* *
* @param string $folderName * @param string $folderName
* @return bool TRUE if all went well * @return bool TRUE if all went well
...@@ -139,9 +139,14 @@ class Typo3tempFileService ...@@ -139,9 +139,14 @@ class Typo3tempFileService
); );
} }
$finder = new Finder(); // first remove directories
$files = $finder->files()->in($basePath)->depth(0)->sortByName(); foreach ((new Finder())->directories()->in($basePath)->depth(0) as $directory) {
foreach ($files as $file) { /** @var SplFileInfo $directory */
GeneralUtility::rmdir($directory->getPathname(), true);
}
// then remove files directly in the main dir
foreach ((new Finder())->files()->in($basePath)->depth(0) as $file) {
/** @var SplFileInfo $file */ /** @var SplFileInfo $file */
$path = $file->getPathname(); $path = $file->getPathname();
@unlink($path); @unlink($path);
......
<?php
declare(strict_types = 1);
namespace TYPO3\CMS\Install\Tests\Functional\Service;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Install\Service\Typo3tempFileService;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
/**
* Test case
*/
class Typo3tempFileServiceTest extends FunctionalTestCase
{
/**
* @var string
*/
private $directoryName;
/**
* @var string
*/
private $directoryPath;
protected function setUp(): void
{
parent::setUp();
$this->directoryName = uniqid('test');
$this->directoryPath = $this->instancePath . '/typo3temp/assets/' . $this->directoryName;
}
protected function tearDown(): void
{
parent::tearDown();
GeneralUtility::rmdir($this->directoryPath, true);
unset($this->directoryName, $this->directoryPath);
}
/**
* @test
*/
public function clearAssetsFolderDetectsNonExistingFolder()
{
$this->expectException(\RuntimeException::class);
$this->expectExceptionCode(1501781454);
$subject = new Typo3tempFileService();
$subject->clearAssetsFolder('/typo3temp/assets/' . $this->directoryName);
}
/**
* @test
*/
public function clearAssetsFolderClearsFolder()
{
GeneralUtility::mkdir_deep($this->directoryPath . '/a/b');
file_put_contents($this->directoryPath . '/c.css', '/* test */');
file_put_contents($this->directoryPath . '/a/b/c.css', '/* test */');
file_put_contents($this->directoryPath . '/a/b/d.css', '/* test */');
$subject = new Typo3tempFileService();
$subject->clearAssetsFolder('/typo3temp/assets/' . $this->directoryName);
self::assertDirectoryNotExists($this->directoryPath . '/a');
self::assertDirectoryExists($this->directoryPath);
self::assertFileNotExists($this->directoryPath . '/c.css');
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment