[BUGFIX] Moving files and folders doesn't update hashes 81/25481/3
authorFrans Saris <franssaris@gmail.com>
Mon, 18 Nov 2013 07:47:04 +0000 (08:47 +0100)
committerSteffen Ritter <info@rs-websystems.de>
Wed, 18 Dec 2013 14:44:23 +0000 (15:44 +0100)
The ResourceStorage does not properly make use of the Indexer.
As result the indexRecord is not properly updated after a
file change.

This patch cleans up the ResourceStorage so it doesn't update
the index properties itself but leaves that to the indexer.

Resolves: #53655
Releases: 6.2
Change-Id: I249505a1bc0b93f8b3ffb0e9cb2b7f10a9a9968e
Reviewed-on: https://review.typo3.org/25481
Reviewed-by: Stefan Neufeind
Reviewed-by: Steffen Ritter
Tested-by: Steffen Ritter
typo3/sysext/core/Classes/Resource/Driver/LocalDriver.php
typo3/sysext/core/Classes/Resource/ResourceStorage.php

index bb98ba7..cd4053d 100644 (file)
@@ -780,9 +780,6 @@ class LocalDriver extends AbstractHierarchicalFilesystemDriver {
                if ($result === FALSE) {
                        throw new \RuntimeException('Replacing file ' . $filePath . ' with ' . $localFilePath . ' failed.', 1315314711);
                }
-               $fileInfo = $this->getFileInfoByIdentifier($file->getIdentifier());
-               $file->updateProperties($fileInfo);
-               // TODO update index
                return $result;
        }
 
index 4c2ed77..5d736a1 100644 (file)
@@ -1407,10 +1407,9 @@ class ResourceStorage {
        public function setFileContents(AbstractFile $file, $contents) {
                // Check if user is allowed to edit
                $this->assureFileWritePermissions($file);
-               // Call driver method to update the file and update file properties afterwards
+               // Call driver method to update the file and update file index entry afterwards
                $result = $this->driver->setFileContents($file, $contents);
-               $file->updateProperties(array('sha1' => $this->driver->hash($file, 'sha1')));
-               $this->updateFile($file);
+               $this->getIndexer()->updateIndexEntry($file);
                return $result;
        }
 
@@ -1529,21 +1528,21 @@ class ResourceStorage {
                }
                $this->emitPreFileMoveSignal($file, $targetFolder);
                $sourceStorage = $file->getStorage();
-               // Call driver method to move the file that also updates the file
-               // object properties
+               // Call driver method to move the file and update the index entry
                try {
                        if ($sourceStorage === $this) {
                                $newIdentifier = $this->driver->moveFileWithinStorage($file, $targetFolder, $targetFileName);
                                if (!$file instanceof AbstractFile) {
                                        throw new \RuntimeException('The given file is not of type AbstractFile.', 1384209025);
                                }
-                               $this->updateFile($file, $newIdentifier);
+                               $file->updateProperties(array('identifier' => $newIdentifier));
                        } else {
                                $tempPath = $file->getForLocalProcessing();
                                $newIdentifier = $this->driver->addFileRaw($tempPath, $targetFolder, $targetFileName);
                                $sourceStorage->driver->deleteFileRaw($file->getIdentifier());
-                               $this->updateFile($file, $newIdentifier, $this);
+                               $file->updateProperties(array('storage' => $this->getUid(), 'identifier' => $newIdentifier));
                        }
+                       $this->getIndexer()->updateIndexEntry($file);
                } catch (\TYPO3\CMS\Core\Exception $e) {
                        echo $e->getMessage();
                }
@@ -1551,44 +1550,6 @@ class ResourceStorage {
                return $file;
        }
 
-       /**
-        * Updates the properties of a file object with some that are freshly
-        * fetched from the driver.
-        *
-        * @param AbstractFile $file
-        * @param string $identifier The identifier of the file. If set, this will overwrite the file object's identifier (use e.g. after moving a file)
-        * @param ResourceStorage $storage
-        * @return void
-        */
-       protected function updateFile(AbstractFile $file, $identifier = '', $storage = NULL) {
-               if ($identifier === '') {
-                       $identifier = $file->getIdentifier();
-               }
-               $fileInfo = $this->driver->getFileInfoByIdentifier($identifier);
-               // TODO extend mapping
-               $newProperties = array(
-                       'storage' => $fileInfo['storage'],
-                       'identifier' => $fileInfo['identifier'],
-                       'tstamp' => $fileInfo['mtime'],
-                       'crdate' => $fileInfo['ctime'],
-                       'mime_type' => $fileInfo['mimetype'],
-                       'size' => $fileInfo['size'],
-                       'name' => $fileInfo['name']
-               );
-               if ($storage !== NULL) {
-                       $newProperties['storage'] = $storage->getUid();
-               }
-               if ($identifier !== $file->getIdentifier()) {
-                       if ($storage === NULL) {
-                               $storage = $file->getStorage();
-                       }
-                       $newProperties['identifier_hash'] = $storage->hashFileIdentifier($identifier);
-                       $newProperties['folder_hash'] = $storage->hashFileIdentifier($storage->getFolderIdentifierFromFileIdentifier($identifier));
-               }
-               $file->updateProperties($newProperties);
-               $this->getFileIndexRepository()->update($file);
-       }
-
        /**
         * Previously in \TYPO3\CMS\Core\Utility\File\ExtendedFileUtility::func_rename()
         *
@@ -1609,11 +1570,11 @@ class ResourceStorage {
                $this->assureFileRenamePermissions($file, $targetFileName);
                $this->emitPreFileRenameSignal($file, $targetFileName);
 
-               // Call driver method to rename the file that also updates the file
-               // object properties
+               // Call driver method to rename the file and update the index entry
                try {
                        $newIdentifier = $this->driver->renameFile($file, $targetFileName);
-                       $this->updateFile($file, $newIdentifier);
+                       $file->updateProperties(array('identifier' => $newIdentifier));
+                       $this->getIndexer()->updateIndexEntry($file);
                } catch (\RuntimeException $e) {
 
                }
@@ -1643,6 +1604,7 @@ class ResourceStorage {
                // TODO check permissions
                $this->emitPreFileReplaceSignal($file, $localFilePath);
                $result = $this->driver->replaceFile($file, $localFilePath);
+               $this->getIndexer()->updateIndexEntry($file);
                $this->emitPostFileReplaceSignal($file, $localFilePath);
                return $result;
        }
@@ -1726,7 +1688,7 @@ class ResourceStorage {
                foreach ($fileObjects as $oldIdentifier => $fileObject) {
                        $newIdentifier = $fileMappings[$oldIdentifier];
                        $fileObject->updateProperties(array('storage' => $this->getUid(), 'identifier' => $newIdentifier));
-                       $this->getFileIndexRepository()->update($fileObject);
+                       $this->getIndexer()->updateIndexEntry($fileObject);
                }
                $returnObject = $this->getFolder($fileMappings[$folderToMove->getIdentifier()]);
                $this->emitPostFolderMoveSignal($folderToMove, $targetParentFolder, $newFolderName);
@@ -1822,7 +1784,7 @@ class ResourceStorage {
                foreach ($fileObjects as $oldIdentifier => $fileObject) {
                        $newIdentifier = $fileMappings[$oldIdentifier];
                        $fileObject->updateProperties(array('identifier' => $newIdentifier));
-                       $this->getFileIndexRepository()->update($fileObject);
+                       $this->getIndexer()->updateIndexEntry($fileObject);
                }
                $returnObject = $this->getFolder($fileMappings[$folderObject->getIdentifier()]);
 
@@ -2428,4 +2390,13 @@ class ResourceStorage {
        public function getDriverType() {
                return $this->storageRecord['driver'];
        }
+
+       /**
+        * Gets Indexer
+        *
+        * @return \TYPO3\CMS\Core\Resource\Index\Indexer
+        */
+       protected function getIndexer() {
+               return GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\Index\\Indexer', $this);
+       }
 }