[BUGFIX] Renaming file does not update hash values 51/25451/4
authorFrans Saris <franssaris@gmail.com>
Fri, 15 Nov 2013 19:12:29 +0000 (20:12 +0100)
committerErnesto Baschny <ernst@cron-it.de>
Sat, 16 Nov 2013 01:28:37 +0000 (02:28 +0100)
When you rename a file the indentifier in the sys_file record
is updated but the indentifier_hash and folder_hash are not.
This results in a new sys_file record when accessing the
renamed/moved file.

Now when the identifier is changed the identifier and folder hash
are updated.

Releases: 6.2
Resolves: #53614
Change-Id: Iad7559d15705ab836e88860b1b198783f0420386
Reviewed-on: https://review.typo3.org/25451
Reviewed-by: Ernesto Baschny
Tested-by: Ernesto Baschny
typo3/sysext/core/Classes/Resource/ResourceStorage.php
typo3/sysext/core/Tests/Unit/Resource/ResourceStorageTest.php

index 0b35ee8..2f6422c 100644 (file)
@@ -1578,6 +1578,13 @@ class ResourceStorage {
                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);
        }
index afb6024..2336187 100644 (file)
@@ -439,8 +439,9 @@ class ResourceStorageTest extends \TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCa
                $indexFileRepositoryMock = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Index\\FileIndexRepository');
                $this->fixture->expects($this->any())->method('getFileIndexRepository')->will($this->returnValue($indexFileRepositoryMock));
                $mockedFile = $this->getMock('TYPO3\\CMS\\Core\\Resource\\File', array(), array(), '', FALSE);
+               $mockedFile->expects($this->any())->method('getIdentifier')->will($this->returnValue($fileInfo['identifier']));
                $mockedFile->expects($this->at(1))->method('updateProperties')->with($this->equalTo(array('sha1' => $hash)));
-               $mockedFile->expects($this->at(3))->method('updateProperties')->with($this->equalTo($newProperties));
+               $mockedFile->expects($this->at(4))->method('updateProperties')->with($this->equalTo($newProperties));
                $indexFileRepositoryMock->expects($this->once())->method('update')->with($mockedFile);
                $this->fixture->setFileContents($mockedFile, uniqid());
        }