Skip to content

Commit

Permalink
[BUGFIX] Consider all elements in typo3temp/assets/ when clearing
Browse files Browse the repository at this point in the history
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: TYPO3com <noreply@typo3.com>
Tested-by: Benni Mack <benni@typo3.org>
Tested-by: Susanne Moog <look@susi.dev>
Reviewed-by: Benni Mack <benni@typo3.org>
Reviewed-by: Daniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Susanne Moog <look@susi.dev>
  • Loading branch information
ohader authored and susannemoog committed Nov 9, 2019
1 parent 4e880df commit fea0bdc
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 4 deletions.
13 changes: 9 additions & 4 deletions typo3/sysext/install/Classes/Service/Typo3tempFileService.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function clearProcessedFiles(int $storageUid): int
}

/**
* Clear files in a typo3temp/assets/ folder (not _processed_!)
* Clears files and folders in a typo3temp/assets/ folder (not _processed_!)
*
* @param string $folderName
* @return bool TRUE if all went well
Expand All @@ -139,9 +139,14 @@ public function clearAssetsFolder(string $folderName)
);
}

$finder = new Finder();
$files = $finder->files()->in($basePath)->depth(0)->sortByName();
foreach ($files as $file) {
// first remove directories
foreach ((new Finder())->directories()->in($basePath)->depth(0) as $directory) {
/** @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 */
$path = $file->getPathname();
@unlink($path);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?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');
}
}

0 comments on commit fea0bdc

Please sign in to comment.