From bf87d1121584c9d17569db133a8eb0d337c4257a Mon Sep 17 00:00:00 2001 From: Helmut Hummel <typo3@helhum.io> Date: Sat, 20 May 2017 11:29:45 +0200 Subject: [PATCH] [BUGFIX] Avoid unnecessarily fetching file for processing 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/52874 Tested-by: TYPO3com <no-reply@typo3.com> Reviewed-by: Philipp Gampe <philipp.gampe@typo3.org> Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl> Reviewed-by: Nicole Cordes <typo3@cordes.co> Tested-by: Nicole Cordes <typo3@cordes.co> Reviewed-by: Christer V <cvi@systime.dk> Reviewed-by: Frans Saris <franssaris@gmail.com> Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch> Tested-by: Christian Kuhn <lolli@schwarzbu.ch> --- .../Classes/Form/Element/FileInfoElement.php | 16 +++++++++------- .../Resource/Processing/LocalPreviewHelper.php | 16 +++++++++------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/typo3/sysext/backend/Classes/Form/Element/FileInfoElement.php b/typo3/sysext/backend/Classes/Form/Element/FileInfoElement.php index 9569d23b37e3..9bead0cf17be 100644 --- a/typo3/sysext/backend/Classes/Form/Element/FileInfoElement.php +++ b/typo3/sysext/backend/Classes/Form/Element/FileInfoElement.php @@ -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 />'; diff --git a/typo3/sysext/core/Classes/Resource/Processing/LocalPreviewHelper.php b/typo3/sysext/core/Classes/Resource/Processing/LocalPreviewHelper.php index 405ba607e050..999a92bf32f6 100644 --- a/typo3/sysext/core/Classes/Resource/Processing/LocalPreviewHelper.php +++ b/typo3/sysext/core/Classes/Resource/Processing/LocalPreviewHelper.php @@ -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(); -- GitLab