Uploading now works everywhere. Show an flash message if the download fails.

This commit is contained in:
Jan Böhmer 2019-10-19 18:50:17 +02:00
parent 27a001b1d2
commit 9385d28e40
3 changed files with 47 additions and 5 deletions

View file

@ -34,6 +34,7 @@ namespace App\Controller\AdminPages;
use App\Entity\Base\NamedDBElement; use App\Entity\Base\NamedDBElement;
use App\Entity\Base\StructuralDBElement; use App\Entity\Base\StructuralDBElement;
use App\Entity\UserSystem\User; use App\Entity\UserSystem\User;
use App\Exceptions\AttachmentDownloadException;
use App\Form\AdminPages\ImportType; use App\Form\AdminPages\ImportType;
use App\Form\AdminPages\MassCreationForm; use App\Form\AdminPages\MassCreationForm;
use App\Services\AttachmentHelper; use App\Services\AttachmentHelper;
@ -109,7 +110,14 @@ abstract class BaseAdminController extends AbstractController
'secure_attachment' => $attachment['secureFile']->getData(), 'secure_attachment' => $attachment['secureFile']->getData(),
'download_url' => $attachment['downloadURL']->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); $em->persist($entity);
@ -154,7 +162,18 @@ abstract class BaseAdminController extends AbstractController
$attachments = $form['attachments']; $attachments = $form['attachments'];
foreach ($attachments as $attachment) { foreach ($attachments as $attachment) {
/** @var $attachment FormInterface */ /** @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); $em->persist($new_entity);

View file

@ -32,6 +32,7 @@ namespace App\Controller;
use App\Entity\Parts\Category; use App\Entity\Parts\Category;
use App\Entity\Parts\Part; use App\Entity\Parts\Part;
use App\Exceptions\AttachmentDownloadException;
use App\Form\Part\PartBaseType; use App\Form\Part\PartBaseType;
use App\Services\AttachmentHelper; use App\Services\AttachmentHelper;
use App\Services\Attachments\AttachmentSubmitHandler; use App\Services\Attachments\AttachmentSubmitHandler;
@ -94,7 +95,18 @@ class PartController extends AbstractController
$attachments = $form['attachments']; $attachments = $form['attachments'];
foreach ($attachments as $attachment) { foreach ($attachments as $attachment) {
/** @var $attachment FormInterface */ /** @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']; $attachments = $form['attachments'];
foreach ($attachments as $attachment) { foreach ($attachments as $attachment) {
/** @var $attachment FormInterface */ /** @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); $em->persist($new_part);

View file

@ -217,7 +217,7 @@ class AttachmentSubmitHandler
]); ]);
if (200 !== $response->getStatusCode()) { 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 //Open a temporary file in the attachment folder