[BUGFIX] Avoid unnecessarily fetching file for processing 33/53033/2
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 13:30:28 +0000 (15:30 +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/53033
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/core/Classes/Resource/Hook/FileInfoHook.php
typo3/sysext/core/Classes/Resource/Processing/LocalPreviewHelper.php

index da30f40..d76a95a 100644 (file)
@@ -16,6 +16,7 @@ namespace TYPO3\CMS\Core\Resource\Hook;
 
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Core\Resource\ResourceFactory;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
  * Utility class to render TCEforms information about a sys_file record
@@ -64,19 +65,21 @@ class FileInfoHook
     protected function renderFileInformationContent(\TYPO3\CMS\Core\Resource\File $file = null)
     {
         if ($file !== null) {
-            $processedFile = $file->process(\TYPO3\CMS\Core\Resource\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/locallang_core.xlf:warning.file_missing'))
+                    . htmlspecialchars($GLOBALS['LANG']->sL('LLL:EXT:lang/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(\TYPO3\CMS\Core\Resource\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(\TYPO3\CMS\Core\Utility\GeneralUtility::formatSize($file->getSize())) . 'bytes)<br />';
index 7ea6ceb..03eca60 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();