diff --git a/src/Controller/AdminPages/BaseAdminController.php b/src/Controller/AdminPages/BaseAdminController.php index 8d247b62..8bf37f46 100644 --- a/src/Controller/AdminPages/BaseAdminController.php +++ b/src/Controller/AdminPages/BaseAdminController.php @@ -34,6 +34,7 @@ namespace App\Controller\AdminPages; use App\Entity\Base\NamedDBElement; use App\Entity\Base\StructuralDBElement; use App\Entity\UserSystem\User; +use App\Exceptions\AttachmentDownloadException; use App\Form\AdminPages\ImportType; use App\Form\AdminPages\MassCreationForm; use App\Services\AttachmentHelper; @@ -109,7 +110,14 @@ abstract class BaseAdminController extends AbstractController 'secure_attachment' => $attachment['secureFile']->getData(), 'download_url' => $attachment['downloadURL']->getData() ]; - $this->attachmentSubmitHandler->handleFormSubmit($attachment->getData(), $attachment['file']->getData(), $options); + try { + $this->attachmentSubmitHandler->handleFormSubmit($attachment->getData(), $attachment['file']->getData(), $options); + } catch (AttachmentDownloadException $ex) { + $this->addFlash( + 'error', + $this->translator->trans('attachment.download_failed') . ' ' . $ex->getMessage() + ); + } } $em->persist($entity); @@ -154,7 +162,18 @@ abstract class BaseAdminController extends AbstractController $attachments = $form['attachments']; foreach ($attachments as $attachment) { /** @var $attachment FormInterface */ - $this->attachmentSubmitHandler->handleFormSubmit($attachment->getData(), $attachment['file']->getData()); + $options = [ + 'secure_attachment' => $attachment['secureFile']->getData(), + 'download_url' => $attachment['downloadURL']->getData() + ]; + try { + $this->attachmentSubmitHandler->handleFormSubmit($attachment->getData(), $attachment['file']->getData(), $options); + } catch (AttachmentDownloadException $ex) { + $this->addFlash( + 'error', + $this->translator->trans('attachment.download_failed') . ' ' . $ex->getMessage() + ); + } } $em->persist($new_entity); diff --git a/src/Controller/PartController.php b/src/Controller/PartController.php index 817651e3..80f2b729 100644 --- a/src/Controller/PartController.php +++ b/src/Controller/PartController.php @@ -32,6 +32,7 @@ namespace App\Controller; use App\Entity\Parts\Category; use App\Entity\Parts\Part; +use App\Exceptions\AttachmentDownloadException; use App\Form\Part\PartBaseType; use App\Services\AttachmentHelper; use App\Services\Attachments\AttachmentSubmitHandler; @@ -94,7 +95,18 @@ class PartController extends AbstractController $attachments = $form['attachments']; foreach ($attachments as $attachment) { /** @var $attachment FormInterface */ - $attachmentSubmitHandler->handleFormSubmit($attachment->getData(), $attachment['file']->getData()); + $options = [ + 'secure_attachment' => $attachment['secureFile']->getData(), + 'download_url' => $attachment['downloadURL']->getData() + ]; + try { + $attachmentSubmitHandler->handleFormSubmit($attachment->getData(), $attachment['file']->getData(), $options); + } catch (AttachmentDownloadException $ex) { + $this->addFlash( + 'error', + $translator->trans('attachment.download_failed') . ' ' . $ex->getMessage() + ); + } } @@ -169,7 +181,18 @@ class PartController extends AbstractController $attachments = $form['attachments']; foreach ($attachments as $attachment) { /** @var $attachment FormInterface */ - $attachmentSubmitHandler->handleFormSubmit($attachment->getData(), $attachment['file']->getData()); + $options = [ + 'secure_attachment' => $attachment['secureFile']->getData(), + 'download_url' => $attachment['downloadURL']->getData() + ]; + try { + $attachmentSubmitHandler->handleFormSubmit($attachment->getData(), $attachment['file']->getData(), $options); + } catch (AttachmentDownloadException $ex) { + $this->addFlash( + 'error', + $translator->trans('attachment.download_failed') . ' ' . $ex->getMessage() + ); + } } $em->persist($new_part); diff --git a/src/Services/Attachments/AttachmentSubmitHandler.php b/src/Services/Attachments/AttachmentSubmitHandler.php index b9ec2d03..734818ae 100644 --- a/src/Services/Attachments/AttachmentSubmitHandler.php +++ b/src/Services/Attachments/AttachmentSubmitHandler.php @@ -217,7 +217,7 @@ class AttachmentSubmitHandler ]); if (200 !== $response->getStatusCode()) { - throw new AttachmentDownloadException('Statuscode:' . $response->getStatusCode()); + throw new AttachmentDownloadException('Status code: ' . $response->getStatusCode()); } //Open a temporary file in the attachment folder