[BUGFIX] Processed files get corrupted when regenerated 53/18153/2
authorAndreas Wolf <andreas.wolf@typo3.org>
Sat, 9 Feb 2013 10:02:05 +0000 (11:02 +0100)
committerAndreas Wolf <andreas.wolf@typo3.org>
Sat, 9 Feb 2013 11:23:17 +0000 (12:23 +0100)
After a file is being (re)processed, the information about it is updated
in the database by the ProcessedFileRepository. The repository gathers
information for the update from the processed file.

For unprocessed files (i.e. those where the original file should be
used), the ProcessedFile class does a fallback to the original file
object. Unfortunately, this fallback is also applied for the uid
property, which makes the repository overwrite a random record in
sys_file_processedfile. This leads to wrong images being displayed in
the frontend.

This patch makes the processed file only return its own uid.

IMPORTANT: To make sure your sys_file_processedfile data is not
corrupted, empty the table and your processed files folder (usually
fileadmin/_processed_/). This will slow down your site as all processed
files are regenerated, but afterwards all data will be correct.

Change-Id: I40685d5748a5a0fcf015c7d876a374f42154831d
Resolves: #45308
Related: #44616 #45168
Releases: 6.1, 6.0
Reviewed-on: https://review.typo3.org/18153
Reviewed-by: Andreas Wolf
Tested-by: Andreas Wolf
typo3/sysext/core/Classes/Resource/ProcessedFile.php
typo3/sysext/core/Classes/Resource/ProcessedFileRepository.php

index 2ee5498..40d6338 100644 (file)
@@ -417,13 +417,23 @@ class ProcessedFile extends AbstractFile {
         * @return mixed
         */
        public function getProperty($key) {
         * @return mixed
         */
        public function getProperty($key) {
-               if ($this->isUnchanged()) {
+               // The uid always (!) has to come from this file and never the original file (see getOriginalFile() to get this)
+               if ($this->isUnchanged() && $key !== 'uid') {
                        return $this->originalFile->getProperty($key);
                } else {
                        return $this->properties[$key];
                }
        }
 
                        return $this->originalFile->getProperty($key);
                } else {
                        return $this->properties[$key];
                }
        }
 
+       /**
+        * Returns the uid of this file
+        *
+        * @return int
+        */
+       public function getUid() {
+               return $this->properties['uid'];
+       }
+
 
        /**
         * Checks if the ProcessedFile needs reprocessing
 
        /**
         * Checks if the ProcessedFile needs reprocessing
index 948bfcb..f91f35c 100644 (file)
@@ -134,7 +134,7 @@ class ProcessedFileRepository extends AbstractRepository {
         */
        public function update($processedFile) {
                if ($processedFile->isPersisted()) {
         */
        public function update($processedFile) {
                if ($processedFile->isPersisted()) {
-                       $uid = intval($processedFile->getProperty('uid'));
+                       $uid = intval($processedFile->getUid());
                        $updateFields = $this->cleanUnavailableColumns($processedFile->toArray());
                        $updateFields['tstamp'] = time();
                        $this->databaseConnection->exec_UPDATEquery($this->table, 'uid=' . intval($uid), $updateFields);
                        $updateFields = $this->cleanUnavailableColumns($processedFile->toArray());
                        $updateFields['tstamp'] = time();
                        $this->databaseConnection->exec_UPDATEquery($this->table, 'uid=' . intval($uid), $updateFields);