mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 09:35:49 +02:00
Fail gracefully when Imagine can not produce an thumbnail.
We now just fall back to the original image instead of throwing an exception. (partly) Fixes issue #89. Maybe related to issue #136
This commit is contained in:
parent
d57377a143
commit
2ee42b7621
2 changed files with 16 additions and 3 deletions
3
docs/docker/.gitignore
vendored
Normal file
3
docs/docker/.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
db/
|
||||||
|
public_media/
|
||||||
|
uploads/
|
|
@ -45,6 +45,7 @@ namespace App\Services\Attachments;
|
||||||
use App\Entity\Attachments\Attachment;
|
use App\Entity\Attachments\Attachment;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use Liip\ImagineBundle\Service\FilterService;
|
use Liip\ImagineBundle\Service\FilterService;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
use function strlen;
|
use function strlen;
|
||||||
use Symfony\Component\Asset\Packages;
|
use Symfony\Component\Asset\Packages;
|
||||||
|
@ -59,15 +60,18 @@ class AttachmentURLGenerator
|
||||||
protected $attachmentHelper;
|
protected $attachmentHelper;
|
||||||
protected $filterService;
|
protected $filterService;
|
||||||
|
|
||||||
|
protected $logger;
|
||||||
|
|
||||||
public function __construct(Packages $assets, AttachmentPathResolver $pathResolver,
|
public function __construct(Packages $assets, AttachmentPathResolver $pathResolver,
|
||||||
UrlGeneratorInterface $urlGenerator, AttachmentManager $attachmentHelper,
|
UrlGeneratorInterface $urlGenerator, AttachmentManager $attachmentHelper,
|
||||||
FilterService $filterService)
|
FilterService $filterService, LoggerInterface $logger)
|
||||||
{
|
{
|
||||||
$this->assets = $assets;
|
$this->assets = $assets;
|
||||||
$this->pathResolver = $pathResolver;
|
$this->pathResolver = $pathResolver;
|
||||||
$this->urlGenerator = $urlGenerator;
|
$this->urlGenerator = $urlGenerator;
|
||||||
$this->attachmentHelper = $attachmentHelper;
|
$this->attachmentHelper = $attachmentHelper;
|
||||||
$this->filterService = $filterService;
|
$this->filterService = $filterService;
|
||||||
|
$this->logger = $logger;
|
||||||
|
|
||||||
//Determine a normalized path to the public folder (assets are relative to this folder)
|
//Determine a normalized path to the public folder (assets are relative to this folder)
|
||||||
$this->public_path = $this->pathResolver->parameterToAbsolutePath('public');
|
$this->public_path = $this->pathResolver->parameterToAbsolutePath('public');
|
||||||
|
@ -168,8 +172,14 @@ class AttachmentURLGenerator
|
||||||
return $this->assets->getUrl($asset_path);
|
return $this->assets->getUrl($asset_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
//Otherwise we can serve the relative path via Asset component
|
//Otherwise we can serve the relative path via Asset component
|
||||||
return $this->filterService->getUrlOfFilteredImage($asset_path, $filter_name);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue