diff --git a/docs/docker/.gitignore b/docs/docker/.gitignore new file mode 100644 index 00000000..5bb9e3bb --- /dev/null +++ b/docs/docker/.gitignore @@ -0,0 +1,3 @@ +db/ +public_media/ +uploads/ \ No newline at end of file diff --git a/src/Services/Attachments/AttachmentURLGenerator.php b/src/Services/Attachments/AttachmentURLGenerator.php index e90643f6..eb189df9 100644 --- a/src/Services/Attachments/AttachmentURLGenerator.php +++ b/src/Services/Attachments/AttachmentURLGenerator.php @@ -45,6 +45,7 @@ namespace App\Services\Attachments; use App\Entity\Attachments\Attachment; use InvalidArgumentException; use Liip\ImagineBundle\Service\FilterService; +use Psr\Log\LoggerInterface; use RuntimeException; use function strlen; use Symfony\Component\Asset\Packages; @@ -59,15 +60,18 @@ class AttachmentURLGenerator protected $attachmentHelper; protected $filterService; + protected $logger; + public function __construct(Packages $assets, AttachmentPathResolver $pathResolver, UrlGeneratorInterface $urlGenerator, AttachmentManager $attachmentHelper, - FilterService $filterService) + FilterService $filterService, LoggerInterface $logger) { $this->assets = $assets; $this->pathResolver = $pathResolver; $this->urlGenerator = $urlGenerator; $this->attachmentHelper = $attachmentHelper; $this->filterService = $filterService; + $this->logger = $logger; //Determine a normalized path to the public folder (assets are relative to this folder) $this->public_path = $this->pathResolver->parameterToAbsolutePath('public'); @@ -168,8 +172,14 @@ class AttachmentURLGenerator return $this->assets->getUrl($asset_path); } - //Otherwise we can serve the relative path via Asset component - return $this->filterService->getUrlOfFilteredImage($asset_path, $filter_name); + try { + //Otherwise we can serve the relative path via Asset component + return $this->filterService->getUrlOfFilteredImage($asset_path, $filter_name); + } catch (\Imagine\Exception\RuntimeException $e) { + //If the filter fails, we can not serve the thumbnail and fall back to the original image and log an warning + $this->logger->warning('Could not open thumbnail for attachment with ID ' . $attachment->getID() . ': ' . $e->getMessage()); + return $this->assets->getUrl($asset_path); + } } /**