‪TYPO3CMS  10.4
DeferredBackendImageProcessor.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
27 
32 {
33  public function ‪canProcessTask(‪TaskInterface $task): bool
34  {
35  $context = GeneralUtility::makeInstance(Context::class);
36  return TYPO3_MODE === 'BE'
37  && $task->‪getType() === 'Image'
38  && in_array($task->‪getName(), ['Preview', 'CropScaleMask'], true)
39  && (!$context->hasAspect('fileProcessing') || $context->getPropertyFromAspect('fileProcessing', 'deferProcessing'))
40  && $task->‪getSourceFile()->‪getProperty('width') > 0
41  && $task->‪getSourceFile()->‪getProperty('height') > 0
42  // Let the local image processor update the properties in case the target file exists already
44  }
45 
46  public function ‪processTask(‪TaskInterface $task): void
47  {
48  $imageDimension = ‪ImageDimension::fromProcessingTask($task);
49  $processedFile = $task->‪getTargetFile();
50  if (!$processedFile->isPersisted()) {
51  // For now, we need to persist the processed file in the repository to be able to reference its uid
52  // We could instead introduce a processing queue and persist the information there
53  $processedFileRepository = GeneralUtility::makeInstance(ProcessedFileRepository::class);
54  $processedFileRepository->add($processedFile);
55  }
56  $processedFile->setName($task->‪getTargetFileName());
57  $processingUrl = (string)GeneralUtility::makeInstance(UriBuilder::class)
58  ->buildUriFromRoute(
59  'image_processing',
60  [
61  'id' => $processedFile->getUid(),
62  ]
63  );
64  $processedFile->updateProcessingUrl(GeneralUtility::locationHeaderUrl($processingUrl));
65  $processedFile->updateProperties(
66  [
67  'width' => $imageDimension->getWidth(),
68  'height' => $imageDimension->getHeight(),
69  'size' => 0,
70  'checksum' => $task->‪getConfigurationChecksum(),
71  ]
72  );
73  $task->‪setExecuted(true);
74  }
75 }
‪TYPO3\CMS\Core\Resource\ProcessedFileRepository
Definition: ProcessedFileRepository.php:30
‪TYPO3\CMS\Backend\Resource\Processing\DeferredBackendImageProcessor\processTask
‪processTask(TaskInterface $task)
Definition: DeferredBackendImageProcessor.php:46
‪TYPO3\CMS\Core\Resource\Processing\TaskInterface\getType
‪string getType()
‪TYPO3\CMS\Core\Resource\Folder\hasFile
‪bool hasFile($name)
Definition: Folder.php:401
‪TYPO3\CMS\Backend\Resource\Processing\DeferredBackendImageProcessor
Definition: DeferredBackendImageProcessor.php:32
‪TYPO3\CMS\Core\Resource\Processing\TaskInterface
Definition: TaskInterface.php:33
‪TYPO3\CMS\Core\Resource\ResourceStorage\getProcessingFolder
‪Folder getProcessingFolder(File $file=null)
Definition: ResourceStorage.php:2738
‪TYPO3\CMS\Core\Resource\Processing\TaskInterface\getSourceFile
‪Resource File getSourceFile()
‪TYPO3\CMS\Backend\Resource\Processing\DeferredBackendImageProcessor\canProcessTask
‪canProcessTask(TaskInterface $task)
Definition: DeferredBackendImageProcessor.php:33
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:53
‪TYPO3\CMS\Core\Imaging\ImageDimension\fromProcessingTask
‪static fromProcessingTask(TaskInterface $task)
Definition: ImageDimension.php:56
‪TYPO3\CMS\Backend\Resource\Processing
Definition: DeferredBackendImageProcessor.php:18
‪TYPO3\CMS\Core\Resource\Processing\TaskInterface\getTargetFile
‪Resource ProcessedFile getTargetFile()
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:38
‪TYPO3\CMS\Core\Resource\Processing\TaskInterface\getName
‪string getName()
‪TYPO3\CMS\Core\Resource\File\getProperty
‪mixed getProperty($key)
Definition: File.php:65
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Resource\Processing\ProcessorInterface
Definition: ProcessorInterface.php:22
‪TYPO3\CMS\Core\Resource\Processing\TaskInterface\setExecuted
‪setExecuted($successful)
‪TYPO3\CMS\Core\Resource\Processing\TaskInterface\getConfigurationChecksum
‪string getConfigurationChecksum()
‪TYPO3\CMS\Core\Resource\Processing\TaskInterface\getTargetFileName
‪string getTargetFileName()
‪TYPO3\CMS\Core\Resource\AbstractFile\getStorage
‪ResourceStorage getStorage()
Definition: AbstractFile.php:390
‪TYPO3\CMS\Core\Imaging\ImageDimension
Definition: ImageDimension.php:31