[BUGFIX] Files to FileStorage relations are now recorded in sys_refindex 86/36486/3
authoralinafleser <afleser@arxia.com>
Fri, 30 Jan 2015 11:59:48 +0000 (13:59 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Sat, 31 Jan 2015 10:16:24 +0000 (11:16 +0100)
When a file (sys_file) is added/modified/deleted,
the relation to the file storage (sys_file_storage)
is recorded and updated in sys_refindex

Resolves: #64631
Related: #50871
Releases: master, 6.2
Change-Id: If95fac13c5530041948b3f9c896ebb390c31956a
Reviewed-on: http://review.typo3.org/36486
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/core/Classes/Resource/Index/FileIndexRepository.php

index 4d90b3c..67622d0 100644 (file)
@@ -18,6 +18,7 @@ namespace TYPO3\CMS\Core\Resource\Index;
 use TYPO3\CMS\Core\SingletonInterface;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Resource\File;
+use TYPO3\CMS\Core\Database\ReferenceIndex;
 
 /**
  * Repository Class as an abstraction layer to sys_file
@@ -222,6 +223,7 @@ class FileIndexRepository implements SingletonInterface {
                $data['tstamp'] = time();
                $this->getDatabaseConnection()->exec_INSERTquery($this->table, $data);
                $data['uid'] = $this->getDatabaseConnection()->sql_insert_id();
+               $this->updateRefIndex($data['uid']);
                $this->emitRecordCreatedSignal($data);
                return $data['uid'];
        }
@@ -250,6 +252,7 @@ class FileIndexRepository implements SingletonInterface {
                if (count($updateRow) > 0) {
                        $updateRow['tstamp'] = time();
                        $this->getDatabaseConnection()->exec_UPDATEquery($this->table, $this->getWhereClauseForFile($file), $updateRow);
+                       $this->updateRefIndex($file->getUid());
                        $this->emitRecordUpdatedSignal(array_intersect_key($file->getProperties(), array_flip($this->fields)));
                }
        }
@@ -338,9 +341,24 @@ class FileIndexRepository implements SingletonInterface {
         */
        public function remove($fileUid) {
                $this->getDatabaseConnection()->exec_DELETEquery($this->table, 'uid=' . (int)$fileUid);
+               $this->updateRefIndex($fileUid);
                $this->emitRecordDeletedSignal($fileUid);
        }
 
+
+       /**
+        * Update Reference Index (sys_refindex) for a file
+        *
+        * @param int $id Record UID
+        * @return void
+        */
+       public function updateRefIndex($id) {
+               /** @var $refIndexObj ReferenceIndex */
+               $refIndexObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Database\\ReferenceIndex');
+               $refIndexObj->updateRefIndexTable($this->table, $id);
+       }
+
+
        /*
         * Get the SignalSlot dispatcher
         *
@@ -390,4 +408,4 @@ class FileIndexRepository implements SingletonInterface {
        protected function emitRecordDeletedSignal($fileUid) {
                $this->getSignalSlotDispatcher()->dispatch('TYPO3\\CMS\\Core\\Resource\\Index\\FileIndexRepository', 'recordDeleted', array($fileUid));
        }
-}
+}
\ No newline at end of file