[BUGFIX] Only persist processedFile if processing was successful 96/39696/5
authorFrans Saris <franssaris@gmail.com>
Mon, 25 May 2015 07:19:24 +0000 (09:19 +0200)
committerFrank Nägler <typo3@naegler.net>
Sat, 30 May 2015 14:15:13 +0000 (16:15 +0200)
Due to multiple reasons (for instance target folder is not writable)
the processing of a file can fail.

This change prevents wrong data being saved in sys_file_processedfile
when processing failed.

Resolves: #67094
Releases: master, 6.2
Change-Id: I6051d503ba74629dc6493b7bac9f28bf320aeb66
Reviewed-on: http://review.typo3.org/39696
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
Reviewed-by: Frank Nägler <typo3@naegler.net>
Tested-by: Frank Nägler <typo3@naegler.net>
typo3/sysext/core/Classes/Resource/ProcessedFile.php
typo3/sysext/core/Classes/Resource/Processing/LocalImageProcessor.php
typo3/sysext/core/Classes/Resource/Service/FileProcessingService.php

index 85cb84b..77915f0 100644 (file)
@@ -257,7 +257,7 @@ class ProcessedFile extends AbstractFile {
         * @return bool
         */
        public function isProcessed() {
-               return ($this->isPersisted() && !$this->needsReprocessing()) || $this->updated;
+               return $this->updated || ($this->isPersisted() && !$this->needsReprocessing());
        }
 
        /**
index 9a5c980..537f79b 100644 (file)
@@ -63,7 +63,7 @@ class LocalImageProcessor implements ProcessorInterface {
                        if ($result === NULL) {
                                $task->setExecuted(TRUE);
                                $task->getTargetFile()->setUsesOriginalFile();
-                       } elseif (file_exists($result['filePath'])) {
+                       } elseif (!empty($result['filePath']) && file_exists($result['filePath'])) {
                                $task->setExecuted(TRUE);
                                $imageDimensions = $this->getGraphicalFunctionsObject()->getImageDimensions($result['filePath']);
                                $task->getTargetFile()->setName($task->getTargetFileName());
@@ -73,7 +73,7 @@ class LocalImageProcessor implements ProcessorInterface {
                                $task->getTargetFile()->updateWithLocalFile($result['filePath']);
 
                        // New dimensions + no new file (for instance svg)
-                       } elseif (!empty($result['width']) && !empty($result['height'])) {
+                       } elseif (!empty($result['width']) && !empty($result['height']) && empty($result['filePath'])) {
                                $task->setExecuted(TRUE);
                                $task->getTargetFile()->setUsesOriginalFile();
                                $task->getTargetFile()->updateProperties(
index d1db1cd..c8e9dc5 100644 (file)
@@ -115,7 +115,7 @@ class FileProcessingService {
                        $processor = Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\Processing\LocalImageProcessor::class);
                        $processor->processTask($task);
 
-                       if ($processedFile->isProcessed()) {
+                       if ($task->isExecuted() && $task->isSuccessful() && $processedFile->isProcessed()) {
                                /** @var $processedFileRepository Resource\ProcessedFileRepository */
                                $processedFileRepository = Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\ProcessedFileRepository::class);
                                $processedFileRepository->add($processedFile);