[BUGFIX] Avoid unnecessarily fetching file for processing 15/53015/3
authorHelmut Hummel <typo3@helhum.io>
Sat, 20 May 2017 09:29:45 +0000 (11:29 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Fri, 2 Jun 2017 08:21:12 +0000 (10:21 +0200)
Files that are not configured as images, won't be processed,
but are still unnecessarily fetched for processing.

To avoid this, we change the processing API, that fetching
only happens, if the file is then used by following code.

In addition we avoid showing a non descriptive thumb
in FileInfoElement, which is used when editing meta data of the file.

Resolves: #81279
Releases: master, 8.7, 7.6
Change-Id: Ie68aa02b1b6149ddb7fbda346ac312d3646e260c
Reviewed-on: https://review.typo3.org/53015
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/backend/Classes/Form/Element/FileInfoElement.php
typo3/sysext/core/Classes/Resource/Processing/LocalPreviewHelper.php

index 2a34f1a..726ed5b 100644 (file)
@@ -66,19 +66,21 @@ class FileInfoElement extends AbstractFormElement
         $lang = $GLOBALS['LANG'];
 
         if ($file !== null) {
-            $processedFile = $file->process(ProcessedFile::CONTEXT_IMAGEPREVIEW, ['width' => 150, 'height' => 150]);
-            $previewImage = $processedFile->getPublicUrl(true);
             $content = '';
             if ($file->isMissing()) {
                 $content .= '<span class="label label-danger label-space-right">'
                     . htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:warning.file_missing'))
                     . '</span>';
             }
-            if ($previewImage) {
-                $content .= '<img src="' . htmlspecialchars($previewImage) . '" ' .
-                    'width="' . $processedFile->getProperty('width') . '" ' .
-                    'height="' . $processedFile->getProperty('height') . '" ' .
-                    'alt="" class="t3-tceforms-sysfile-imagepreview" />';
+            if (GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $file->getExtension())) {
+                $processedFile = $file->process(ProcessedFile::CONTEXT_IMAGEPREVIEW, ['width' => 150, 'height' => 150]);
+                $previewImage = $processedFile->getPublicUrl(true);
+                if ($previewImage) {
+                    $content .= '<img src="' . htmlspecialchars($previewImage) . '" ' .
+                        'width="' . $processedFile->getProperty('width') . '" ' .
+                        'height="' . $processedFile->getProperty('height') . '" ' .
+                        'alt="" class="t3-tceforms-sysfile-imagepreview" />';
+                }
             }
             $content .= '<strong>' . htmlspecialchars($file->getName()) . '</strong>';
             $content .= ' (' . htmlspecialchars(GeneralUtility::formatSize($file->getSize())) . 'bytes)<br />';
index 405ba60..999a92b 100644 (file)
@@ -93,15 +93,14 @@ class LocalPreviewHelper
      * @param File $file The source file
      * @param array $configuration Processing configuration
      * @param string $targetFilePath Output file path
-     * @return array|NULL
+     * @return array
      */
     protected function generatePreviewFromFile(File $file, array $configuration, $targetFilePath)
     {
-        $originalFileName = $file->getForLocalProcessing(false);
-
         // Check file extension
-        if ($file->getType() != File::FILETYPE_IMAGE &&
-            !GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $file->getExtension())) {
+        if ($file->getType() !== File::FILETYPE_IMAGE
+            && !GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $file->getExtension())
+        ) {
             // Create a default image
             $graphicalFunctions = GeneralUtility::makeInstance(GraphicalFunctions::class);
             $graphicalFunctions->getTemporaryImageWithText(
@@ -110,10 +109,13 @@ class LocalPreviewHelper
                 'No ext!',
                 $file->getName()
             );
-            $result = [
+            return [
                 'filePath' => $targetFilePath,
             ];
-        } elseif ($file->getExtension() === 'svg') {
+        }
+
+        $originalFileName = $file->getForLocalProcessing(false);
+        if ($file->getExtension() === 'svg') {
             /** @var $gifBuilder \TYPO3\CMS\Frontend\Imaging\GifBuilder */
             $gifBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\Imaging\GifBuilder::class);
             $gifBuilder->init();