[BUGFIX] getFileIndexRecordsForFolder only works for hierarchical path 57/26357/3
authorSteffen Ritter <info@rs-websystems.de>
Thu, 12 Dec 2013 16:08:21 +0000 (17:08 +0100)
committerSteffen Ritter <info@rs-websystems.de>
Sat, 21 Dec 2013 10:02:49 +0000 (11:02 +0100)
The method FileRepository::getFileIndexRecordsForFolder
retrieves the Index Records for files in a given folder using a
LIKE-query. This basically checks if the identifier of the a
folder is part of the identifier of the file.

This concept has several drawbacks. First not all storages are
hierarchical, second this will fail if there is a different
directory seperator than / and finally this fetches records
for the folder recursively which may result in a huge amount of
data if for example the root folder of an storage is queried.

In addition the method resides in the FileRepository while it
retrieves IndexRecords - which is a different concern.

This change introduces the function within the
FileIndexRepository and uses the folder_hash (introduced in
https://review.typo3.org/23398) to query for the files.

The old method is deprecated now, calls the new method and
all core-usages of the old function have been rewritten to
use the new functionality.

Releases: 6.2
Resolves: #53687
Change-Id: Icabf2350192c93951f2277f3aa7468fe958bfabf
Reviewed-on: https://review.typo3.org/26357
Reviewed-by: Frans Saris
Tested-by: Frans Saris
Reviewed-by: Steffen Ritter
Tested-by: Steffen Ritter
typo3/sysext/core/Classes/Resource/FileRepository.php
typo3/sysext/core/Classes/Resource/Index/FileIndexRepository.php
typo3/sysext/core/Classes/Resource/ResourceStorage.php
typo3/sysext/core/Classes/Resource/Service/IndexerService.php
typo3/sysext/core/ext_tables.sql

index 60fcd10..f1965e1 100644 (file)
@@ -129,24 +129,11 @@ class FileRepository extends AbstractRepository {
         *
         * @param Folder $folder
         * @return array
+        * @deprecated since 6.2 - will be removed 2 versions later
         */
        public function getFileIndexRecordsForFolder(Folder $folder) {
-               $identifier = $folder->getIdentifier();
-               $storage = $folder->getStorage()->getUid();
-               $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
-                       '*',
-                       $this->table,
-                       sprintf('storage=%u AND missing = 0 AND identifier LIKE %s AND NOT identifier LIKE %s',
-                                       $storage,
-                                       $GLOBALS['TYPO3_DB']->fullQuoteStr($GLOBALS['TYPO3_DB']->escapeStrForLike($identifier, $this->table) . '%', $this->table),
-                                       $GLOBALS['TYPO3_DB']->fullQuoteStr($GLOBALS['TYPO3_DB']->escapeStrForLike($identifier, $this->table) . '%/%', $this->table)
-                       ),
-                       '',
-                       '',
-                       '',
-                       'identifier'
-               );
-               return (array) $rows;
+               GeneralUtility::logDeprecatedFunction();
+               return $this->getFileIndexRepository()->findByFolder($folder);
        }
 
        /**
index e468ebc..f6c82fa 100644 (file)
@@ -177,6 +177,25 @@ class FileIndexRepository implements SingletonInterface {
        }
 
        /**
+        * Find all records for files in a Folder
+        *
+        * @param \TYPO3\CMS\Core\Resource\Folder $folder
+        * @return array|NULL
+        */
+       public function findByFolder(\TYPO3\CMS\Core\Resource\Folder $folder) {
+               $resultRows = $this->getDatabase()->exec_SELECTgetRows(
+                       implode(',', $this->fields),
+                       $this->table,
+                       'folder_hash = ' . $this->getDatabase()->fullQuoteStr($folder->getHashedIdentifier(), $this->table) .
+                               ' AND storage  = ' . (int)$folder->getStorage()->getUid(),
+                       '',
+                       '',
+                       '',
+                       'identifier'
+               );
+               return $resultRows;
+       }
+       /**
         * Adds a file to the index
         *
         * @param File $file
index 5d736a1..4f84ba6 100644 (file)
@@ -1328,7 +1328,7 @@ class ResourceStorage {
                $folder = $this->getFolder($path);
                $rows = array();
                if ($loadIndexRecords) {
-                       $rows = $this->getFileRepository()->getFileIndexRecordsForFolder($folder);
+                       $rows = $this->getFileIndexRepository()->findByFolder($folder);
                }
                $filters = $useFilters == TRUE ? $this->fileAndFolderNameFilters : array();
                $items = $this->driver->getFileList($path, $start, $numberOfItems, $filters, $rows, $recursive);
index 604edaf..d50c625 100644 (file)
@@ -206,7 +206,8 @@ class IndexerService implements \TYPO3\CMS\Core\SingletonInterface {
                }
 
                // check for deleted files (file not found during indexing are marked as missing)
-               foreach ($this->getRepository()->getFileIndexRecordsForFolder($folder) as $file) {
+               $fileIndexRecords = $this->getFileIndexRepository()->findByFolder($folder);
+               foreach ($fileIndexRecords as $file) {
                        if (!in_array($file['identifier'], $fileIdentifiers)) {
                                /** @var $fileObject File */
                                $fileObject = $this->getRepository()->findByIdentifier($file['uid']);
index b2e8455..f6c4185 100644 (file)
@@ -306,6 +306,7 @@ CREATE TABLE sys_file (
 
        PRIMARY KEY (uid),
        KEY sel01 (storage,identifier_hash),
+       KEY folder (storage,folder_hash),
        KEY tstamp (tstamp),
        KEY lastindex (last_indexed),
        KEY sha1 (sha1(40))