[BUGFIX] Missing signals on adding file 45/23745/2
authorAndreas Wolf <andreas.wolf@typo3.org>
Mon, 5 Aug 2013 13:28:01 +0000 (15:28 +0200)
committerStefan Neufeind <typo3.neufeind@speedpartner.de>
Wed, 11 Sep 2013 13:31:02 +0000 (15:31 +0200)
There are signals for most operations performed in the file storage, but
not for adding a file. Especially this operation is interesting for
things like file indexing, automatic generation of variants (renditions)
etc., therefore this patch adds the two missing signals.

Resolves: #50795
Releases: 6.2, 6.1, 6.0
Change-Id: I0def7b44ff8977a42916e01388604fcbf2d6d299
Reviewed-on: https://review.typo3.org/23745
Reviewed-by: Stefan Neufeind
Tested-by: Stefan Neufeind
typo3/sysext/core/Classes/Resource/ResourceStorage.php

index 4ca88d4..a5bc5d9 100644 (file)
@@ -69,6 +69,8 @@ class ResourceStorage {
 
        const SIGNAL_PreProcessConfiguration = 'preProcessConfiguration';
        const SIGNAL_PostProcessConfiguration = 'postProcessConfiguration';
+       const SIGNAL_PreFileAdd = 'preFileAdd';
+       const SIGNAL_PostFileAdd = 'postFileAdd';
        const SIGNAL_PreFileCopy = 'preFileCopy';
        const SIGNAL_PostFileCopy = 'postFileCopy';
        const SIGNAL_PreFileMove = 'preFileMove';
@@ -1061,8 +1063,8 @@ class ResourceStorage {
                        throw new \InvalidArgumentException('File "' . $localFilePath . '" does not exist.', 1319552745);
                }
                $this->assureFileAddPermissions($localFilePath, $targetFolder, $targetFileName);
-               $targetFolder = $targetFolder ? $targetFolder : $this->getDefaultFolder();
-               $targetFileName = $targetFileName ? $targetFileName : PathUtility::basename($localFilePath);
+               $targetFolder = $targetFolder ?: $this->getDefaultFolder();
+               $targetFileName = $targetFileName ?: PathUtility::basename($localFilePath);
                if ($conflictMode === 'cancel' && $this->driver->fileExistsInFolder($targetFileName, $targetFolder)) {
                        throw new Exception\ExistingTargetFileNameException('File "' . $targetFileName . '" already exists in folder ' . $targetFolder->getIdentifier(), 1322121068);
                } elseif ($conflictMode === 'changeName') {
@@ -1070,7 +1072,13 @@ class ResourceStorage {
                }
                // We do not care whether the file exists if $conflictMode is "replace",
                // so just use the name as is in that case
-               return $this->driver->addFile($localFilePath, $targetFolder, $targetFileName);
+               $this->emitPreFileAddSignal($targetFileName, $targetFolder);
+
+               $file = $this->driver->addFile($localFilePath, $targetFolder, $targetFileName);
+
+               $this->emitPostFileAddSignal($file, $targetFolder);
+
+               return $file;
        }
 
        /**
@@ -1914,6 +1922,28 @@ class ResourceStorage {
        }
 
        /**
+        * Emits file pre-add signal
+        *
+        * @param string $fileName
+        * @param Folder $targetFolder
+        * @return void
+        */
+       protected function emitPreFileAddSignal($fileName, Folder $targetFolder) {
+               $this->getSignalSlotDispatcher()->dispatch('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', self::SIGNAL_PreFileAdd, array($fileName, $targetFolder));
+       }
+
+       /**
+        * Emits the file post-add signal
+        *
+        * @param FileInterface $file
+        * @param Folder $targetFolder
+        * @return void
+        */
+       protected function emitPostFileAddSignal(FileInterface $file, Folder $targetFolder) {
+               $this->getSignalSlotDispatcher()->dispatch('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', self::SIGNAL_PostFileAdd, array($file, $targetFolder));
+       }
+
+       /**
         * Emits file pre-copy signal
         *
         * @param FileInterface $file