Skip to content

Commit

Permalink
[BUGFIX] Fall back to default folder when user-specific upload folder…
Browse files Browse the repository at this point in the history
… does not exist

When the userTSconfig options.defaultUserFolder = 1:/my-folder/ does not exist,
Backend users now fall back to the first selected user folder.

A test is added to show that the fallback to the default storage works.

Resolves: #86815
Releases: master, 10.4
Change-Id: Ia88a9020adb4ba522e10e3a6059189500d9a407f
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/64552
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Daniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Reviewed-by: Oliver Hader <oliver.hader@typo3.org>
Reviewed-by: Daniel Goerz <daniel.goerz@posteo.de>
  • Loading branch information
bmack authored and ervaude committed Jun 29, 2020
1 parent b1e781e commit b0edb4e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
Expand Up @@ -1967,8 +1967,13 @@ public function getDefaultUploadFolder($pid = null, $table = null, $field = null
{
$uploadFolder = $this->getTSConfig()['options.']['defaultUploadFolder'] ?? '';
if ($uploadFolder) {
$uploadFolder = GeneralUtility::makeInstance(ResourceFactory::class)->getFolderObjectFromCombinedIdentifier($uploadFolder);
} else {
try {
$uploadFolder = GeneralUtility::makeInstance(ResourceFactory::class)->getFolderObjectFromCombinedIdentifier($uploadFolder);
} catch (Exception\FolderDoesNotExistException $e) {
$uploadFolder = null;
}
}
if (empty($uploadFolder)) {
foreach ($this->getFileStorages() as $storage) {
if ($storage->isDefault() && $storage->isWritable()) {
try {
Expand Down
Expand Up @@ -19,6 +19,8 @@

use TYPO3\CMS\Core\Authentication\AuthenticationService;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;

/**
Expand Down Expand Up @@ -105,4 +107,25 @@ public function returnWebmountsFilterOutInaccessiblePages(): void
self::assertContains('40', $result, 'Accessible db mount page, child of a not accessible page is not shown');
self::assertEquals(['1', '40'], $result);
}

/**
* @test
*/
public function getDefaultUploadFolderFallsBackToDefaultStorage(): void
{
$this->importDataSet('PACKAGE:typo3/testing-framework/Resources/Core/Functional/Fixtures/sys_file_storage.xml');
$path = 'user_upload/some-folder-that-does-not-exist';
$fullPathToStorageBase = Environment::getPublicPath() . '/fileadmin/' . $path;
GeneralUtility::rmdir($fullPathToStorageBase);
// Skip access permissions, as this is not checked here
$this->subject->user['admin'] = 1;
$this->subject->user['TSconfig'] = 'options.defaultUploadFolder = 1:/' . $path;
$this->subject->fetchGroupData();
$folder = $this->subject->getDefaultUploadFolder();
self::assertEquals('/user_upload/', $folder->getIdentifier());
// Now create the folder and check again
GeneralUtility::mkdir_deep($fullPathToStorageBase);
$folder = $this->subject->getDefaultUploadFolder();
self::assertEquals('/' . $path . '/', $folder->getIdentifier());
}
}

0 comments on commit b0edb4e

Please sign in to comment.