[TASK] Introduce Signals in IndexRecord- and MetaDataRepository 96/24896/6
authorSteffen Ritter <info@rs-websystems.de>
Fri, 18 Oct 2013 12:55:09 +0000 (14:55 +0200)
committerSteffen Ritter <info@rs-websystems.de>
Mon, 11 Nov 2013 16:02:05 +0000 (17:02 +0100)
In order to allow custom code to act on changes in the FAL
Layer the repositories now emit signals on create, update
and delete.

Releases: 6.2
Resolves: #52952
Change-Id: Ib42c1cb2aef199af3b4565560bdb2e094ac1cf06
Reviewed-on: https://review.typo3.org/24896
Reviewed-by: Steffen Ritter
Tested-by: Steffen Ritter
typo3/sysext/core/Classes/Resource/Index/FileIndexRepository.php
typo3/sysext/core/Classes/Resource/Index/MetaDataRepository.php

index 5bf27a0..9e8c881 100644 (file)
@@ -166,7 +166,9 @@ class FileIndexRepository implements SingletonInterface {
                } else {
                        $data = array_intersect_key($file->getProperties(), array_flip($this->fields));
                        $this->getDatabase()->exec_INSERTquery($this->table, $data);
-                       $file->updateProperties(array('uid' => $this->getDatabase()->sql_insert_id()));
+                       $data['uid'] = $this->getDatabase()->sql_insert_id();
+                       $file->updateProperties(array('uid' => $data['uid']));
+                       $this->emitRecordCreated($data);
                }
        }
 
@@ -194,6 +196,7 @@ class FileIndexRepository implements SingletonInterface {
                if (count($updateRow) > 0) {
                        $updateRow['tstamp'] = time();
                        $this->getDatabase()->exec_UPDATEquery($this->table, $this->getWhereClauseForFile($file), $updateRow);
+                       $this->emitRecordUpdated(array_intersect_key($file->getProperties(), array_flip($this->fields)));
                }
        }
 
@@ -225,5 +228,56 @@ class FileIndexRepository implements SingletonInterface {
         */
        public function remove($fileUid) {
                $this->getDatabase()->exec_DELETEquery($this->table, 'uid=' . intval($fileUid));
+               $this->emitRecordDeleted($fileUid);
+       }
+
+       /*
+        * Get the SignalSlot dispatcher
+        *
+        * @return \TYPO3\CMS\Extbase\SignalSlot\Dispatcher
+        */
+       protected function getSignalSlotDispatcher() {
+               return $this->getObjectManager()->get('TYPO3\\CMS\\Extbase\\SignalSlot\\Dispatcher');
+       }
+
+       /**
+        * Get the ObjectManager
+        *
+        * @return \TYPO3\CMS\Extbase\Object\ObjectManager
+        */
+       protected function getObjectManager() {
+               return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
+       }
+
+
+
+       /**
+        * Signal that is called after an IndexRecord is updated
+        *
+        * @param array $data
+        * @signal
+        */
+       protected function emitRecordUpdated(array $data) {
+               $this->getSignalSlotDispatcher()->dispatch('TYPO3\\CMS\\Core\\Resource\\Index\\FileIndexRepository', 'recordUpdated', array($data));
+       }
+
+       /**
+        * Signal that is called after an IndexRecord is created
+        *
+        * @param array $data
+        * @signal
+        */
+       protected function emitRecordCreated(array $data) {
+               $this->getSignalSlotDispatcher()->dispatch('TYPO3\\CMS\\Core\\Resource\\Index\\FileIndexRepository', 'recordCreated', array($data));
+       }
+
+       /**
+        * Signal that is called after an IndexRecord is deleted
+        *
+        * @param integer $fileUid
+        * @signal
+        */
+       protected function emitRecordDeleted($fileUid) {
+               $this->getSignalSlotDispatcher()->dispatch('TYPO3\\CMS\\Core\\Resource\\Index\\FileIndexRepository', 'recordDeleted', array($fileUid));
        }
 }
\ No newline at end of file
index 3fdee1b..4688016 100644 (file)
@@ -113,6 +113,8 @@ class MetaDataRepository implements SingletonInterface {
                $record = $emptyRecord;
                $record['uid'] = $this->getDatabase()->sql_insert_id();
 
+               $this->emitRecordCreated($record);
+
                return $record;
        }
 
@@ -132,6 +134,8 @@ class MetaDataRepository implements SingletonInterface {
                if (count($updateRow) > 0) {
                        $updateRow['tstamp'] = time();
                        $this->getDatabase()->exec_UPDATEquery($this->tableName, 'uid = ' . intval($row['uid']), $updateRow);
+
+                       $this->emitRecordUpdated(array_merge($row, $updateRow));
                }
        }
 
@@ -143,6 +147,7 @@ class MetaDataRepository implements SingletonInterface {
         */
        public function removeByFileUid($fileUid) {
                $this->getDatabase()->exec_DELETEquery($this->tableName, 'file=' . intval($fileUid));
+               $this->emitRecordDeleted($fileUid);
        }
 
        /**
@@ -174,4 +179,34 @@ class MetaDataRepository implements SingletonInterface {
        protected function emitRecordPostRetrievalSignal(\ArrayObject $data) {
                $this->getSignalSlotDispatcher()->dispatch('TYPO3\\CMS\\Core\\Resource\\Index\\MetaDataRepository', 'recordPostRetrieval', array($data));
        }
+
+       /**
+        * Signal that is called after an IndexRecord is updated
+        *
+        * @param array $data
+        * @signal
+        */
+       protected function emitRecordUpdated(array $data) {
+               $this->getSignalSlotDispatcher()->dispatch('TYPO3\\CMS\\Core\\Resource\\Index\\MetaDataRepository', 'recordUpdated', array($data));
+       }
+
+       /**
+        * Signal that is called after an IndexRecord is created
+        *
+        * @param array $data
+        * @signal
+        */
+       protected function emitRecordCreated(array $data) {
+               $this->getSignalSlotDispatcher()->dispatch('TYPO3\\CMS\\Core\\Resource\\Index\\MetaDataRepository', 'recordCreated', array($data));
+       }
+
+       /**
+        * Signal that is called after an IndexRecord is deleted
+        *
+        * @param integer $fileUid
+        * @signal
+        */
+       protected function emitRecordDeleted($fileUid) {
+               $this->getSignalSlotDispatcher()->dispatch('TYPO3\\CMS\\Core\\Resource\\Index\\MetaDataRepository', 'recordDeleted', array($fileUid));
+       }
 }
\ No newline at end of file