‪TYPO3CMS  10.4
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
64  $processedFile = $this->processedFileRepository->findByUid($processedFileId);
65  $this->‪validateProcessedFile($processedFile);
66 
67  $this->context->setAspect('fileProcessing', new ‪FileProcessingAspect(false));
68  $processedFile = $processedFile->getOriginalFile()->process(
69  $processedFile->getTaskIdentifier(),
70  $processedFile->getProcessingConfiguration()
71  );
72 
73  $this->‪validateProcessedFile($processedFile);
74  } catch (FileAlreadyProcessedException $e) {
75  $processedFile = $e->getProcessedFile();
76  } finally {
77  $this->locker->releaseLock(self::class);
78  }
79 
80  return $processedFile;
81  }
82 
89  private function ‪validateProcessedFile(ProcessedFile $processedFile): void
90  {
91  if ($processedFile->isProcessed()) {
92  throw new FileAlreadyProcessedException($processedFile, 1599395651);
93  }
94  }
95 }
‪TYPO3\CMS\Core\Resource\ProcessedFileRepository
Definition: ProcessedFileRepository.php:30
‪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:86
‪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: ExtractorService.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:293
‪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:44
‪TYPO3\CMS\Core\Resource\Service\ImageProcessingService\process
‪process(int $processedFileId)
Definition: ImageProcessingService.php:52