/** * Moves a folder. If you want to move a folder from this storage to another * one, call this method on the target storage, otherwise you will get an exception. * * @param Folder $folderToMove The folder to move. * @param Folder $targetParentFolder The target parent folder * @param string $newFolderName * @param string $conflictMode a value of the DuplicationBehavior enumeration * * @throws \Exception|\TYPO3\CMS\Core\Exception * @throws \InvalidArgumentException * @throws InvalidTargetFolderException * @return Folder */ public function moveFolder(Folder $folderToMove, Folder $targetParentFolder, $newFolderName = null, $conflictMode = DuplicationBehavior::RENAME) { // @todo add tests $originalFolder = $folderToMove->getParentFolder(); $this->assureFolderMovePermissions($folderToMove, $targetParentFolder); $sourceStorage = $folderToMove->getStorage(); $returnObject = null; $sanitizedNewFolderName = $this->driver->sanitizeFileName($newFolderName ?: $folderToMove->getName()); // @todo check if folder already exists in $targetParentFolder, handle this conflict then $this->emitPreFolderMoveSignal($folderToMove, $targetParentFolder, $sanitizedNewFolderName); // Get all file objects now so we are able to update them after moving the folder $fileObjects = $this->getAllFileObjectsInFolder($folderToMove); if ($sourceStorage === $this) { if ($this->isWithinFolder($folderToMove, $targetParentFolder)) { throw new InvalidTargetFolderException(sprintf('Cannot move folder "%s" into target folder "%s", because the target folder is already within the folder to be moved!', $folderToMove->getName(), $targetParentFolder->getName()), 1422723050); } $fileMappings = $this->driver->moveFolderWithinStorage($folderToMove->getIdentifier(), $targetParentFolder->getIdentifier(), $sanitizedNewFolderName); } else { $fileMappings = $this->moveFolderBetweenStorages($folderToMove, $targetParentFolder, $sanitizedNewFolderName); } // Update the identifier and storage of all file objects foreach ($fileObjects as $oldIdentifier => $fileObject) { $newIdentifier = $fileMappings[$oldIdentifier]; $fileObject->updateProperties(array('storage' => $this->getUid(), 'identifier' => $newIdentifier)); $this->getIndexer()->updateIndexEntry($fileObject); } $returnObject = $this->getFolder($fileMappings[$folderToMove->getIdentifier()]); $this->emitPostFolderMoveSignal($folderToMove, $targetParentFolder, $returnObject->getName(), $originalFolder); return $returnObject; }
/** * Moves a folder. If you want to move a folder from this storage to another * one, call this method on the target storage, otherwise you will get an exception. * * @param Folder $folderToMove The folder to move. * @param Folder $targetParentFolder The target parent folder * @param string $newFolderName * @param string $conflictMode How to handle conflicts; one of "overrideExistingFile", "renameNewFolder", "cancel * * @throws \Exception|\TYPO3\CMS\Core\Exception * @throws \InvalidArgumentException * @return Folder */ public function moveFolder(Folder $folderToMove, Folder $targetParentFolder, $newFolderName = NULL, $conflictMode = 'renameNewFolder') { // TODO add tests $originalFolder = $folderToMove->getParentFolder(); $this->assureFolderMovePermissions($folderToMove, $targetParentFolder); $sourceStorage = $folderToMove->getStorage(); $returnObject = NULL; $sanitizedNewFolderName = $this->driver->sanitizeFileName($newFolderName ?: $folderToMove->getName()); // TODO check if folder already exists in $targetParentFolder, handle this conflict then $this->emitPreFolderMoveSignal($folderToMove, $targetParentFolder, $sanitizedNewFolderName); // Get all file objects now so we are able to update them after moving the folder $fileObjects = $this->getAllFileObjectsInFolder($folderToMove); if ($sourceStorage === $this) { $fileMappings = $this->driver->moveFolderWithinStorage($folderToMove->getIdentifier(), $targetParentFolder->getIdentifier(), $sanitizedNewFolderName); } else { $fileMappings = $this->moveFolderBetweenStorages($folderToMove, $targetParentFolder, $sanitizedNewFolderName); } // Update the identifier and storage of all file objects foreach ($fileObjects as $oldIdentifier => $fileObject) { $newIdentifier = $fileMappings[$oldIdentifier]; $fileObject->updateProperties(array('storage' => $this->getUid(), 'identifier' => $newIdentifier)); $this->getIndexer()->updateIndexEntry($fileObject); } $returnObject = $this->getFolder($fileMappings[$folderToMove->getIdentifier()]); $this->emitPostFolderMoveSignal($folderToMove, $targetParentFolder, $returnObject->getName(), $originalFolder); return $returnObject; }