From 71c6ee6ce83e6c449ca606cd3d6cc23855b8038a Mon Sep 17 00:00:00 2001 From: Michael Oehlhof Date: Sat, 4 Apr 2015 15:43:09 +0200 Subject: [PATCH] [!!!][TASK] FAL: Use file drivers correctly in Folder::getSubfolder This patch extends the API of the DriverInterface. The Folder::getSubfolder() function now asks for the correct folder. The getFolderInFolder($folderName, $folder) function is added to ResourceStorage and the getFolderInFolder and getFileInFolder functions are added to the DriverInterface. Resolves: #65305 Resolves: #59475 Resolves: #59473 Releases: master Change-Id: Ib3e8e76ebf4ce43a442dab610c882d7a075a791f Reviewed-on: http://review.typo3.org/38479 Reviewed-by: Markus Klein Reviewed-by: Benjamin Mack Tested-by: Benjamin Mack Tested-by: Markus Klein --- .../Resource/Driver/DriverInterface.php | 18 ++++++++++++ .../Classes/Resource/Driver/LocalDriver.php | 11 +++++++ typo3/sysext/core/Classes/Resource/Folder.php | 6 ++-- .../core/Classes/Resource/ResourceStorage.php | 29 ++++++++++++++++++- ...ng-65305-AddFunctionsToDriverInterface.rst | 27 +++++++++++++++++ 5 files changed, 86 insertions(+), 5 deletions(-) create mode 100644 typo3/sysext/core/Documentation/Changelog/master/Breaking-65305-AddFunctionsToDriverInterface.rst diff --git a/typo3/sysext/core/Classes/Resource/Driver/DriverInterface.php b/typo3/sysext/core/Classes/Resource/Driver/DriverInterface.php index d34e8735a128..e310359137bc 100644 --- a/typo3/sysext/core/Classes/Resource/Driver/DriverInterface.php +++ b/typo3/sysext/core/Classes/Resource/Driver/DriverInterface.php @@ -394,6 +394,15 @@ interface DriverInterface { */ public function getFolderInfoByIdentifier($folderIdentifier); + /** + * Returns the identifier of a file inside the folder + * + * @param string $fileName + * @param string $folderIdentifier + * @return string file identifier + */ + public function getFileInFolder($fileName, $folderIdentifier); + /** * Returns a list of files inside the specified path * @@ -412,6 +421,15 @@ interface DriverInterface { */ public function getFilesInFolder($folderIdentifier, $start = 0, $numberOfItems = 0, $recursive = FALSE, array $filenameFilterCallbacks = array(), $sort = '', $sortRev = FALSE); + /** + * Returns the identifier of a folder inside the folder + * + * @param string $folderName The name of the target folder + * @param string $folderIdentifier + * @return string folder identifier + */ + public function getFolderInFolder($folderName, $folderIdentifier); + /** * Returns a list of folders inside the specified path * diff --git a/typo3/sysext/core/Classes/Resource/Driver/LocalDriver.php b/typo3/sysext/core/Classes/Resource/Driver/LocalDriver.php index 5f75ef80d04c..56b2ea6988a1 100644 --- a/typo3/sysext/core/Classes/Resource/Driver/LocalDriver.php +++ b/typo3/sysext/core/Classes/Resource/Driver/LocalDriver.php @@ -424,6 +424,17 @@ class LocalDriver extends AbstractHierarchicalFilesystemDriver { return TRUE; } + /** + * Returns a file inside the specified path + * + * @param string $fileName + * @param string $folderIdentifier + * @return string File Identifier + */ + public function getFileInFolder($fileName, $folderIdentifier) { + return $this->canonicalizeAndCheckFileIdentifier($folderIdentifier . '/' . $fileName); + } + /** * Returns a list of files inside the specified path * diff --git a/typo3/sysext/core/Classes/Resource/Folder.php b/typo3/sysext/core/Classes/Resource/Folder.php index e864e66bc46b..6bb4bd25e1ce 100644 --- a/typo3/sysext/core/Classes/Resource/Folder.php +++ b/typo3/sysext/core/Classes/Resource/Folder.php @@ -14,6 +14,7 @@ namespace TYPO3\CMS\Core\Resource; * The TYPO3 project - inspiring people to share! */ +use TYPO3\CMS\Core\Resource\Exception\InsufficientFolderAccessPermissionsException; use TYPO3\CMS\Core\Utility\PathUtility; /** @@ -238,10 +239,7 @@ class Folder implements FolderInterface { if (!$this->storage->hasFolderInFolder($name, $this)) { throw new \InvalidArgumentException('Folder "' . $name . '" does not exist in "' . $this->identifier . '"', 1329836110); } - /** @var $factory ResourceFactory */ - $factory = ResourceFactory::getInstance(); - $folderObject = $factory->createFolderObject($this->storage, $this->identifier . $name . '/', $name); - return $folderObject; + return $this->storage->getFolderInFolder($name, $this); } /** diff --git a/typo3/sysext/core/Classes/Resource/ResourceStorage.php b/typo3/sysext/core/Classes/Resource/ResourceStorage.php index 86a7e89a0146..cc473e8cb359 100644 --- a/typo3/sysext/core/Classes/Resource/ResourceStorage.php +++ b/typo3/sysext/core/Classes/Resource/ResourceStorage.php @@ -1312,6 +1312,18 @@ class ResourceStorage implements ResourceStorageInterface { return $this->driver->getParentFolderIdentifierOfIdentifier($fileIdentifier); } + /** + * Get file from folder + * + * @param string $fileName + * @param Folder $folder + * @return NULL|File|ProcessedFile + */ + public function getFileInFolder($fileName, Folder $folder) { + $identifier = $this->driver->getFileInFolder($fileName, $folder->getIdentifier()); + return $this->getFileFactory()->getFileObjectByStorageAndIdentifier($this->getUid(), $identifier); + } + /** * @param Folder $folder * @param int $start @@ -1982,6 +1994,21 @@ class ResourceStorage implements ResourceStorageInterface { return $result; } + /** + * Returns the Identifier for a folder within a given folder. + * + * @param string $folderName The name of the target folder + * @param string $folder + * @param bool $returnInaccessibleFolderObject + * @return Folder|InaccessibleFolder + * @throws \Exception + * @throws Exception\InsufficientFolderAccessPermissionsException + */ + public function getFolderInFolder($folderName, $folder, $returnInaccessibleFolderObject = FALSE) { + $folderIdentifier = $this->driver->getFolderInFolder($folderName, $folder); + return $this->getFolder($folderIdentifier, $returnInaccessibleFolderObject); + } + /** * @param Folder $folder * @param int $start @@ -2096,7 +2123,7 @@ class ResourceStorage implements ResourceStorageInterface { * @param string $identifier * @param bool $returnInaccessibleFolderObject * - * @return Folder + * @return Folder|InaccessibleFolder * @throws \Exception * @throws Exception\InsufficientFolderAccessPermissionsException */ diff --git a/typo3/sysext/core/Documentation/Changelog/master/Breaking-65305-AddFunctionsToDriverInterface.rst b/typo3/sysext/core/Documentation/Changelog/master/Breaking-65305-AddFunctionsToDriverInterface.rst new file mode 100644 index 000000000000..46fc987de146 --- /dev/null +++ b/typo3/sysext/core/Documentation/Changelog/master/Breaking-65305-AddFunctionsToDriverInterface.rst @@ -0,0 +1,27 @@ +==================================================== +Breaking - #65305: DriverInterface has been extended +==================================================== + +Description +=========== + +The getFolderInFolder and getFileInFolder functions were added to the DriverInterface. + + +Impact +====== + +Any FAL driver extension will stop working. + + +Affected Installations +====================== + +Any installation with a custom FAL driver, like WebDAV or Dropbox. + + +Migration +========= + +The functions getFolderInFolder and getFileInFolder must be added to the custom FAL driver. +A Non-hierarchical driver needs to throw a "not implemented" exception when calling these functions. -- 2.20.1