[BUGFIX] Persist files that are updated in ResourceStorage 78/17478/2
authorHelmut Hummel <helmut.hummel@typo3.org>
Sat, 12 Jan 2013 14:46:39 +0000 (15:46 +0100)
committerHelmut Hummel <helmut.hummel@typo3.org>
Sun, 13 Jan 2013 14:07:42 +0000 (15:07 +0100)
When renaming or moving folders all files in that
folder needs to be updated. ResourceStorage handles
that, but the changes to the properties are not
persisted, which leads to inconsistent file records.

Persist updated files using the FileRepository and
clean up the code a bit.

Fixes: #44439
Releases: 6.0, 6.1

Change-Id: I9a21040fdd6741e030d812df165cd33959dd8db1
Reviewed-on: https://review.typo3.org/17478
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
Reviewed-by: Helmut Hummel
Tested-by: Helmut Hummel
typo3/sysext/core/Classes/Resource/Driver/LocalDriver.php
typo3/sysext/core/Classes/Resource/FileRepository.php
typo3/sysext/core/Classes/Resource/ResourceStorage.php

index d10096a..d693d96 100644 (file)
@@ -927,6 +927,7 @@ class LocalDriver extends \TYPO3\CMS\Core\Resource\Driver\AbstractDriver {
         *
         * @param \TYPO3\CMS\Core\Resource\FileInterface $file
         * @return boolean TRUE if deleting the file succeeded
+        * @throws \RuntimeException
         */
        public function deleteFile(\TYPO3\CMS\Core\Resource\FileInterface $file) {
                $filePath = $this->getAbsolutePath($file);
index b217fb0..d8c931f 100644 (file)
@@ -248,7 +248,7 @@ class FileRepository extends \TYPO3\CMS\Core\Resource\AbstractRepository {
        /**
         * Updates an existing file object in the database
         *
-        * @param \TYPO3\CMS\Core\Resource\File $modifiedObject
+        * @param \TYPO3\CMS\Core\Resource\AbstractFile $modifiedObject
         * @return void
         */
        public function update($modifiedObject) {
index f25e42e..63f0996 100644 (file)
@@ -166,7 +166,7 @@ class ResourceStorage {
         */
        const DEFAULT_ProcessingFolder = '_processed_';
        /**
-        * @var \TYPO3\CMS\Core\Resource\Folder
+        * @var Folder
         */
        protected $processingFolder;
 
@@ -935,6 +935,7 @@ class ResourceStorage {
                        $fileInfo = $this->driver->getFileInfo($file);
                        $fileInfo['sha1'] = $this->driver->hash($file, 'sha1');
                        $file->updateProperties($fileInfo);
+                       $this->getFileRepository()->update($file);
                } catch (\RuntimeException $e) {
                        throw $e;
                }
@@ -1158,9 +1159,7 @@ class ResourceStorage {
                        $newProperties['storage'] = $storage->getUid();
                }
                $file->updateProperties($newProperties);
-               /** @var $fileRepository \TYPO3\CMS\Core\Resource\FileRepository */
-               $fileRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\FileRepository');
-               $fileRepository->update($file);
+               $this->getFileRepository()->update($file);
        }
 
        /**
@@ -1336,6 +1335,7 @@ class ResourceStorage {
                        foreach ($fileObjects as $oldIdentifier => $fileObject) {
                                $newIdentifier = $fileMappings[$oldIdentifier];
                                $fileObject->updateProperties(array('storage' => $this, 'identifier' => $newIdentifier));
+                               $this->getFileRepository()->update($fileObject);
                        }
                        $returnObject = $this->getFolder($fileMappings[$folderToMove->getIdentifier()]);
                } catch (\TYPO3\CMS\Core\Exception $e) {
@@ -1432,6 +1432,7 @@ class ResourceStorage {
                        foreach ($fileObjects as $oldIdentifier => $fileObject) {
                                $newIdentifier = $fileMappings[$oldIdentifier];
                                $fileObject->updateProperties(array('identifier' => $newIdentifier));
+                               $this->getFileRepository()->update($fileObject);
                        }
                        $returnObject = $this->getFolder($fileMappings[$folderObject->getIdentifier()]);
                } catch (\Exception $e) {
@@ -1901,6 +1902,13 @@ class ResourceStorage {
        }
 
        /**
+        * @return \TYPO3\CMS\Core\Resource\FileRepository
+        */
+       protected function getFileRepository() {
+               return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\FileRepository');
+       }
+
+       /**
         * @return \TYPO3\CMS\Core\Resource\Service\FileProcessingService
         */
        protected function getFileProcessingService() {
@@ -1942,4 +1950,4 @@ class ResourceStorage {
        }
 }
 
-?>
\ No newline at end of file
+?>