Skip to content

Commit

Permalink
preserve existing fal uids on rename
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc Neuhaus committed Apr 5, 2018
1 parent 82a8726 commit 4930e0c
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions Classes/Mapping/FalMapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Resource\Driver\AbstractHierarchicalFilesystemDriver;
use TYPO3\CMS\Core\Resource\Driver\LocalDriver;
use TYPO3\CMS\Core\Resource\DuplicationBehavior;
use TYPO3\CMS\Core\Resource\Exception\ExistingTargetFileNameException;
use TYPO3\CMS\Core\Resource\Exception\FolderDoesNotExistException;
use TYPO3\CMS\Core\Resource\Exception\InvalidFileNameException;
Expand Down Expand Up @@ -177,16 +178,16 @@ protected function downloadFileAndGetFileObject($objectId, array $data, Event $e
$contents = file_get_contents($tempPathAndFilename);
unlink($tempPathAndFilename);
$targetFilename = $this->sanitizeFileName(pathinfo($tempPathAndFilename, PATHINFO_BASENAME));
$file = $folder->createFile($targetFilename);
foreach($existingFileRows as $existingFileRow) {
if($existingFileRow['name'] !== $targetFilename) {
$existingFile = $storage->getFile($existingFileRow['identifier']);
try {
$storage->deleteFile($existingFile);
} catch(\Exception $e) {

if (count($existingFileRows) > 0) {
foreach($existingFileRows as $existingFileRow) {
$file = $storage->getFile($existingFileRow['identifier']);
if($existingFileRow['name'] !== $targetFilename) {
$file->rename($targetFilename, DuplicationBehavior::REPLACE);
break;
}
}
} else {
$file = $folder->createFile($targetFilename);
}
} catch (ExistingTargetFileNameException $error) {
$file = reset($this->getObjectRepository()->searchByName($folder, $targetFilename));
Expand Down

0 comments on commit 4930e0c

Please sign in to comment.