[!!!][TASK] FAL: Use file drivers correctly in Folder::getSubfolder 79/38479/11
authorMichael Oehlhof <typo3@oehlhof.de>
Sat, 4 Apr 2015 13:43:09 +0000 (15:43 +0200)
committerMarkus Klein <markus.klein@typo3.org>
Sat, 20 Jun 2015 11:24:41 +0000 (13:24 +0200)
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 <markus.klein@typo3.org>
Reviewed-by: Benjamin Mack <benni@typo3.org>
Tested-by: Benjamin Mack <benni@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
typo3/sysext/core/Classes/Resource/Driver/DriverInterface.php
typo3/sysext/core/Classes/Resource/Driver/LocalDriver.php
typo3/sysext/core/Classes/Resource/Folder.php
typo3/sysext/core/Classes/Resource/ResourceStorage.php
typo3/sysext/core/Documentation/Changelog/master/Breaking-65305-AddFunctionsToDriverInterface.rst [new file with mode: 0644]

index d34e873..e310359 100644 (file)
@@ -395,6 +395,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
         *
         * @param string $folderIdentifier
@@ -413,6 +422,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
         *
         * @param string $folderIdentifier
index 5f75ef8..56b2ea6 100644 (file)
@@ -425,6 +425,17 @@ class LocalDriver extends AbstractHierarchicalFilesystemDriver {
        }
 
        /**
+        * 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
         *
         * @param string $folderIdentifier
index e864e66..6bb4bd2 100644 (file)
@@ -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);
        }
 
        /**
index 86a7e89..cc473e8 100644 (file)
@@ -1313,6 +1313,18 @@ class ResourceStorage implements ResourceStorageInterface {
        }
 
        /**
+        * 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
         * @param int $maxNumberOfItems
@@ -1983,6 +1995,21 @@ class ResourceStorage implements ResourceStorageInterface {
        }
 
        /**
+        * 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
         * @param int $maxNumberOfItems
@@ -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 (file)
index 0000000..46fc987
--- /dev/null
@@ -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.