‪TYPO3CMS  ‪main
PreviewService.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 
23 
28 {
29  public function ‪__construct(
30  protected readonly ‪OnlineMediaHelperRegistry $onlineMediaHelperRegistry,
31  protected readonly ‪ProcessedFileRepository $processedFileRepository
32  ) {}
33 
34  public function ‪updatePreviewImage(‪File $file): string
35  {
36  if (!$this->onlineMediaHelperRegistry->hasOnlineMediaHelper($file->‪getExtension())) {
37  throw new \InvalidArgumentException('No online media helper exists for extension ' . $file->‪getExtension(), 1695130495);
38  }
39 
40  $onlineMediaHelper = $this->onlineMediaHelperRegistry->getOnlineMediaHelper($file);
41 
42  // Remove the current preview image to force regeneration on calling getPreviewImage() again
43  if (file_exists($previewImage = $onlineMediaHelper->getPreviewImage($file))) {
44  // Remove preview image and processed files
45  unlink($previewImage);
46  foreach ($this->processedFileRepository->findAllByOriginalFile($file) as $processedFile) {
47  $processedFile->delete();
48  }
49  }
50 
51  // Force regeneration of the preview image and return the path
52  return $onlineMediaHelper->getPreviewImage($file);
53  }
54 }
‪TYPO3\CMS\Core\Resource\ProcessedFileRepository
Definition: ProcessedFileRepository.php:39
‪TYPO3\CMS\Core\Resource\OnlineMedia\Service\PreviewService\__construct
‪__construct(protected readonly OnlineMediaHelperRegistry $onlineMediaHelperRegistry, protected readonly ProcessedFileRepository $processedFileRepository)
Definition: PreviewService.php:29
‪TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\OnlineMediaHelperRegistry
Definition: OnlineMediaHelperRegistry.php:27
‪TYPO3\CMS\Core\Resource\AbstractFile\getExtension
‪getExtension()
Definition: AbstractFile.php:243
‪TYPO3\CMS\Core\Resource\OnlineMedia\Service\PreviewService\updatePreviewImage
‪updatePreviewImage(File $file)
Definition: PreviewService.php:34
‪TYPO3\CMS\Core\Resource\File
Definition: File.php:26
‪TYPO3\CMS\Core\Resource\OnlineMedia\Service\PreviewService
Definition: PreviewService.php:28
‪TYPO3\CMS\Core\Resource\OnlineMedia\Service
Definition: PreviewService.php:18