mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-19 10:24:50 +02:00
Use imports instead of FQNs
This commit is contained in:
parent
f63b6d7207
commit
5629215ce4
179 changed files with 792 additions and 597 deletions
|
@ -148,7 +148,7 @@ class AttachmentSubmitHandler
|
|||
throw new InvalidArgumentException('The given attachment class is not known! The passed class was: '.$attachment::class);
|
||||
}
|
||||
//Ensure the attachment has an assigned element
|
||||
if (!$attachment->getElement() instanceof \App\Entity\Attachments\AttachmentContainingDBElement) {
|
||||
if (!$attachment->getElement() instanceof AttachmentContainingDBElement) {
|
||||
throw new InvalidArgumentException('The given attachment is not assigned to an element! An element is needed to generate a path!');
|
||||
}
|
||||
|
||||
|
@ -176,7 +176,7 @@ class AttachmentSubmitHandler
|
|||
$options = $resolver->resolve($options);
|
||||
|
||||
//When a file is given then upload it, otherwise check if we need to download the URL
|
||||
if ($file instanceof \Symfony\Component\HttpFoundation\File\UploadedFile) {
|
||||
if ($file instanceof UploadedFile) {
|
||||
$this->upload($attachment, $file, $options);
|
||||
} elseif ($options['download_url'] && $attachment->isExternal()) {
|
||||
$this->downloadURL($attachment, $options);
|
||||
|
@ -192,7 +192,7 @@ class AttachmentSubmitHandler
|
|||
//this is only possible if the attachment is new (not yet persisted to DB)
|
||||
if ($options['become_preview_if_empty'] && null === $attachment->getID() && $attachment->isPicture()) {
|
||||
$element = $attachment->getElement();
|
||||
if ($element instanceof AttachmentContainingDBElement && !$element->getMasterPictureAttachment() instanceof \App\Entity\Attachments\Attachment) {
|
||||
if ($element instanceof AttachmentContainingDBElement && !$element->getMasterPictureAttachment() instanceof Attachment) {
|
||||
$element->setMasterPictureAttachment($attachment);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Services\Attachments;
|
||||
|
||||
use Imagine\Exception\RuntimeException;
|
||||
use App\Entity\Attachments\Attachment;
|
||||
use InvalidArgumentException;
|
||||
use Liip\ImagineBundle\Imagine\Cache\CacheManager;
|
||||
|
@ -140,7 +141,7 @@ class AttachmentURLGenerator
|
|||
$tmp = $this->thumbnailManager->getBrowserPath($asset_path, $filter_name, [], null, UrlGeneratorInterface::NETWORK_PATH);
|
||||
//So we remove the schema manually
|
||||
return preg_replace('/^https?:/', '', $tmp);
|
||||
} catch (\Imagine\Exception\RuntimeException $e) {
|
||||
} catch (RuntimeException $e) {
|
||||
//If the filter fails, we can not serve the thumbnail and fall back to the original image and log a warning
|
||||
$this->logger->warning('Could not open thumbnail for attachment with ID ' . $attachment->getID() . ': ' . $e->getMessage());
|
||||
return $this->assets->getUrl($asset_path);
|
||||
|
|
|
@ -22,6 +22,12 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Services\Attachments;
|
||||
|
||||
use App\Entity\Parts\Footprint;
|
||||
use App\Entity\ProjectSystem\Project;
|
||||
use App\Entity\Parts\Category;
|
||||
use App\Entity\Parts\Storelocation;
|
||||
use App\Entity\Parts\MeasurementUnit;
|
||||
use App\Entity\Parts\Manufacturer;
|
||||
use App\Entity\Attachments\Attachment;
|
||||
use App\Entity\Parts\Part;
|
||||
|
||||
|
@ -52,21 +58,21 @@ class PartPreviewGenerator
|
|||
$list[] = $attachment;
|
||||
}
|
||||
|
||||
if ($part->getFootprint() instanceof \App\Entity\Parts\Footprint) {
|
||||
if ($part->getFootprint() instanceof Footprint) {
|
||||
$attachment = $part->getFootprint()->getMasterPictureAttachment();
|
||||
if ($this->isAttachmentValidPicture($attachment)) {
|
||||
$list[] = $attachment;
|
||||
}
|
||||
}
|
||||
|
||||
if ($part->getBuiltProject() instanceof \App\Entity\ProjectSystem\Project) {
|
||||
if ($part->getBuiltProject() instanceof Project) {
|
||||
$attachment = $part->getBuiltProject()->getMasterPictureAttachment();
|
||||
if ($this->isAttachmentValidPicture($attachment)) {
|
||||
$list[] = $attachment;
|
||||
}
|
||||
}
|
||||
|
||||
if ($part->getCategory() instanceof \App\Entity\Parts\Category) {
|
||||
if ($part->getCategory() instanceof Category) {
|
||||
$attachment = $part->getCategory()->getMasterPictureAttachment();
|
||||
if ($this->isAttachmentValidPicture($attachment)) {
|
||||
$list[] = $attachment;
|
||||
|
@ -74,7 +80,7 @@ class PartPreviewGenerator
|
|||
}
|
||||
|
||||
foreach ($part->getPartLots() as $lot) {
|
||||
if ($lot->getStorageLocation() instanceof \App\Entity\Parts\Storelocation) {
|
||||
if ($lot->getStorageLocation() instanceof Storelocation) {
|
||||
$attachment = $lot->getStorageLocation()->getMasterPictureAttachment();
|
||||
if ($this->isAttachmentValidPicture($attachment)) {
|
||||
$list[] = $attachment;
|
||||
|
@ -82,14 +88,14 @@ class PartPreviewGenerator
|
|||
}
|
||||
}
|
||||
|
||||
if ($part->getPartUnit() instanceof \App\Entity\Parts\MeasurementUnit) {
|
||||
if ($part->getPartUnit() instanceof MeasurementUnit) {
|
||||
$attachment = $part->getPartUnit()->getMasterPictureAttachment();
|
||||
if ($this->isAttachmentValidPicture($attachment)) {
|
||||
$list[] = $attachment;
|
||||
}
|
||||
}
|
||||
|
||||
if ($part->getManufacturer() instanceof \App\Entity\Parts\Manufacturer) {
|
||||
if ($part->getManufacturer() instanceof Manufacturer) {
|
||||
$attachment = $part->getManufacturer()->getMasterPictureAttachment();
|
||||
if ($this->isAttachmentValidPicture($attachment)) {
|
||||
$list[] = $attachment;
|
||||
|
@ -114,7 +120,7 @@ class PartPreviewGenerator
|
|||
}
|
||||
|
||||
//Otherwise check if the part has a footprint with a valid master attachment
|
||||
if ($part->getFootprint() instanceof \App\Entity\Parts\Footprint) {
|
||||
if ($part->getFootprint() instanceof Footprint) {
|
||||
$attachment = $part->getFootprint()->getMasterPictureAttachment();
|
||||
if ($this->isAttachmentValidPicture($attachment)) {
|
||||
return $attachment;
|
||||
|
@ -122,7 +128,7 @@ class PartPreviewGenerator
|
|||
}
|
||||
|
||||
//With lowest priority use the master attachment of the project this part represents (when existing)
|
||||
if ($part->getBuiltProject() instanceof \App\Entity\ProjectSystem\Project) {
|
||||
if ($part->getBuiltProject() instanceof Project) {
|
||||
$attachment = $part->getBuiltProject()->getMasterPictureAttachment();
|
||||
if ($this->isAttachmentValidPicture($attachment)) {
|
||||
return $attachment;
|
||||
|
@ -142,7 +148,7 @@ class PartPreviewGenerator
|
|||
*/
|
||||
protected function isAttachmentValidPicture(?Attachment $attachment): bool
|
||||
{
|
||||
return $attachment instanceof \App\Entity\Attachments\Attachment
|
||||
return $attachment instanceof Attachment
|
||||
&& $attachment->isPicture()
|
||||
&& $this->attachmentHelper->isFileExisting($attachment);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue