‪TYPO3CMS  11.5
ImageProcessingService.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
24 
29 {
34 
38  private ‪$context;
39 
43  private ‪$locker;
44 
45  public function ‪__construct(
49  ) {
50  $this->processedFileRepository = ‪$processedFileRepository;
51  $this->context = ‪$context;
52  $this->locker = ‪$locker;
53  }
54 
55  public function ‪process(int $processedFileId): ‪ProcessedFile
56  {
58  $processedFile = $this->processedFileRepository->findByUid($processedFileId);
59  try {
60  $this->‪validateProcessedFile($processedFile);
61  $this->locker->acquireLock(self::class, $processedFileId);
62 
63  // Fetch the processed file again, as it might have been processed by another process while waiting for the lock
65  $processedFile = $this->processedFileRepository->findByUid($processedFileId);
66  $this->‪validateProcessedFile($processedFile);
67 
68  $this->context->setAspect('fileProcessing', new ‪FileProcessingAspect(false));
69  $processedFile = $processedFile->getOriginalFile()->process(
70  $processedFile->getTaskIdentifier(),
71  $processedFile->getProcessingConfiguration()
72  );
73 
74  $this->‪validateProcessedFile($processedFile);
75  } catch (FileAlreadyProcessedException $e) {
76  $processedFile = $e->getProcessedFile();
77  } finally {
78  $this->locker->releaseLock(self::class);
79  }
80 
81  return $processedFile;
82  }
83 
90  private function ‪validateProcessedFile(ProcessedFile $processedFile): void
91  {
92  if ($processedFile->isProcessed()) {
93  throw new FileAlreadyProcessedException($processedFile, 1599395651);
94  }
95  }
96 }
‪TYPO3\CMS\Core\Resource\ProcessedFileRepository
Definition: ProcessedFileRepository.php:31
‪TYPO3\CMS\Core\Resource\Service\ImageProcessingService\$locker
‪ResourceMutex $locker
Definition: ImageProcessingService.php:40
‪TYPO3\CMS\Core\Resource\Service\ImageProcessingService\$context
‪Context $context
Definition: ImageProcessingService.php:36
‪TYPO3\CMS\Core\Context\FileProcessingAspect
Definition: FileProcessingAspect.php:29
‪TYPO3\CMS\Core\Locking\ResourceMutex
Definition: ResourceMutex.php:27
‪TYPO3\CMS\Core\Resource\Service\ImageProcessingService\validateProcessedFile
‪validateProcessedFile(ProcessedFile $processedFile)
Definition: ImageProcessingService.php:87
‪TYPO3\CMS\Core\Resource\Service\ImageProcessingService
Definition: ImageProcessingService.php:29
‪TYPO3\CMS\Core\Resource\Service\ImageProcessingService\$processedFileRepository
‪ProcessedFileRepository $processedFileRepository
Definition: ImageProcessingService.php:32
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:53
‪TYPO3\CMS\Core\Resource\Service
Definition: ConfigurationService.php:18
‪TYPO3\CMS\Core\Resource\Service\ImageProcessingService\__construct
‪__construct(ProcessedFileRepository $processedFileRepository, Context $context, ResourceMutex $locker)
Definition: ImageProcessingService.php:42
‪TYPO3\CMS\Core\Resource\ProcessedFile\isProcessed
‪bool isProcessed()
Definition: ProcessedFile.php:295
‪TYPO3\CMS\Core\Resource\Exception\FileAlreadyProcessedException\getProcessedFile
‪ProcessedFile getProcessedFile()
Definition: FileAlreadyProcessedException.php:43
‪TYPO3\CMS\Core\Resource\Exception\FileAlreadyProcessedException
Definition: FileAlreadyProcessedException.php:29
‪TYPO3\CMS\Core\Resource\ProcessedFile
Definition: ProcessedFile.php:45
‪TYPO3\CMS\Core\Resource\Service\ImageProcessingService\process
‪process(int $processedFileId)
Definition: ImageProcessingService.php:52