[TASK] Return ProcessedFile instead of File if possible 53/27753/9
authorSteffen Ritter <info@rs-websystems.de>
Thu, 20 Feb 2014 12:16:55 +0000 (13:16 +0100)
committerMarkus Klein <klein.t3@mfc-linz.at>
Tue, 11 Mar 2014 09:21:18 +0000 (10:21 +0100)
You can query the FAL-API for files by their filename. If the file resides
in the processing-folder of a storage it is a valid file to the storage.
Therefore creating a file-object and indexing it would be a valid thing.

Since this is not intended additionally to the storage the ResourceFactory
must know about that, too. This change implements this awareness, so there
is no way to create a FileObject for files which reside within the
processing folder.
In 6.0 and 6.1 there has been a dirty workaround for that by marking those
files as not indexable which was removed silently when introducing the new
indexer.

Releases: 6.2
Resolves: #54234
Change-Id: I274c47717560a6efc175fa94aacc4770a578fd3f
Reviewed-on: https://review.typo3.org/27753
Reviewed-by: Frans Saris
Tested-by: Frans Saris
Reviewed-by: Markus Klein
Tested-by: Markus Klein
typo3/sysext/core/Classes/Resource/ProcessedFileRepository.php
typo3/sysext/core/Classes/Resource/ResourceFactory.php
typo3/sysext/core/Classes/Resource/ResourceStorage.php
typo3/sysext/core/ext_tables.sql

index 4f75693..a49e9e1 100644 (file)
@@ -108,6 +108,27 @@ class ProcessedFileRepository extends AbstractRepository {
        }
 
        /**
+        * @param ResourceStorage $storage
+        * @param string $identifier
+        *
+        * @return null|ProcessedFile
+        */
+       public function findByStorageAndIdentifier(ResourceStorage $storage, $identifier) {
+               $processedFileObject = NULL;
+               if ($storage->hasFile($identifier)) {
+                       $databaseRow = $this->databaseConnection->exec_SELECTgetSingleRow(
+                               '*',
+                               $this->table,
+                               'storage = ' . (int)$storage->getUid() .
+                               ' AND identifier = ' . $this->databaseConnection->fullQuoteStr($identifier, $this->table)
+                       );
+                       if ($databaseRow) {
+                               $processedFileObject = $this->createDomainObject($databaseRow);
+                       }
+               }
+               return $processedFileObject;
+       }
+       /**
         * Adds a processedfile object in the database
         *
         * @param ProcessedFile $processedFile
index 0d5a1f6..305181c 100644 (file)
@@ -393,19 +393,27 @@ class ResourceFactory implements \TYPO3\CMS\Core\SingletonInterface {
        }
 
        /**
+        * Gets an file object from storage by file identifier
+        * If the file is outside of the process folder it gets indexed and returned as file object afterwards
+        * If the file is within processing folder the file object will be directly returned
+        *
         * @param int $storageUid
         * @param string $fileIdentifier
-        *
-        * @return File
+        * @return File|ProcessedFile
         */
        public function getFileObjectByStorageAndIdentifier($storageUid, &$fileIdentifier) {
                $storage = $this->getStorageObject($storageUid, array(), $fileIdentifier);
-               $fileData = $this->getFileIndexRepository()->findOneByStorageUidAndIdentifier($storage->getUid(), $fileIdentifier);
-               if ($fileData === FALSE) {
-                       $fileObject = $this->getIndexer($storage)->createIndexEntry($fileIdentifier);
+               if (!$storage->isWithinProcessingFolder($fileIdentifier)) {
+                       $fileData = $this->getFileIndexRepository()->findOneByStorageUidAndIdentifier($storage->getUid(), $fileIdentifier);
+                       if ($fileData === FALSE) {
+                               $fileObject = $this->getIndexer($storage)->createIndexEntry($fileIdentifier);
+                       } else {
+                               $fileObject = $this->getFileObject($fileData['uid'], $fileData);
+                       }
                } else {
-                       $fileObject = $this->getFileObject($fileData['uid'], $fileData);
+                       $fileObject = $this->getProcessedFileRepository()->findByStorageAndIdentifier($storage, $fileIdentifier);
                }
+
                return $fileObject;
        }
 
@@ -605,6 +613,15 @@ class ResourceFactory implements \TYPO3\CMS\Core\SingletonInterface {
        }
 
        /**
+        * Returns an instance of the ProcessedFileRepository
+        *
+        * @return ProcessedFileRepository
+        */
+       protected function getProcessedFileRepository() {
+               return GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\ProcessedFileRepository');
+       }
+
+       /**
         * Returns an instance of the Indexer
         *
         * @return \TYPO3\CMS\Core\Resource\Index\Indexer
index 9284cf5..c584566 100644 (file)
@@ -2061,6 +2061,14 @@ class ResourceStorage {
        }
 
        /**
+        * @param string $identifier
+        * @return bool
+        */
+       public function isWithinProcessingFolder($identifier) {
+               return $this->driver->isWithin($this->getProcessingFolder()->getIdentifier(), $identifier);
+       }
+
+       /**
         * Returns the folders on the root level of the storage
         * or the first mount point of this storage for this user
         *
index 2a4a210..894b0fa 100644 (file)
@@ -181,7 +181,7 @@ CREATE TABLE pages (
   KEY t3ver_oid (t3ver_oid,t3ver_wsid),
   KEY parent (pid,deleted,sorting),
   KEY alias (alias),
-  KEY determineSiteRoot (deleted,hidden,is_siteroot),
+  KEY determineSiteRoot (deleted,hidden,is_siteroot)
 );
 
 #
@@ -352,7 +352,7 @@ CREATE TABLE sys_file_metadata (
        PRIMARY KEY (uid),
        KEY file (file),
        KEY t3ver_oid (t3ver_oid,t3ver_wsid),
-       KEY fal_filelist (l10n_parent,sys_language_uid),
+       KEY fal_filelist (l10n_parent,sys_language_uid)
 );
 
 
@@ -380,7 +380,8 @@ CREATE TABLE sys_file_processedfile (
        height int(11) DEFAULT '0',
 
        PRIMARY KEY (uid),
-       KEY combined_1 (original,task_type,configurationsha1)
+       KEY combined_1 (original,task_type,configurationsha1),
+       KEY identifier (storage,identifier)
 );
 
 #
@@ -687,7 +688,7 @@ CREATE TABLE sys_category (
        KEY parent (pid),
        KEY t3ver_oid (t3ver_oid,t3ver_wsid),
        KEY category_parent (parent),
-       KEY category_list (pid,deleted,sys_language_uid),
+       KEY category_list (pid,deleted,sys_language_uid)
 );
 
 #