Commit ed1727e0 by Mathieu Poisbeau

#181: si erreur fatal/technique lors de l'import => l'affiche proprement à l'utilisateur

parent 28abaf87
...@@ -82,9 +82,6 @@ class ImportController extends CRUDController ...@@ -82,9 +82,6 @@ class ImportController extends CRUDController
$this->sendemail = false; $this->sendemail = false;
} }
/**
* @TODO: manage the case of a fatal error (so catch the exception, and display a nice message)!
*/
public function createAction() public function createAction()
{ {
$this->siege = $this->em->getRepository(Siege::class)->findOneById(1); $this->siege = $this->em->getRepository(Siege::class)->findOneById(1);
...@@ -104,6 +101,7 @@ class ImportController extends CRUDController ...@@ -104,6 +101,7 @@ class ImportController extends CRUDController
$this->em->flush(); $this->em->flush();
$idimport = $import->getId(); $idimport = $import->getId();
try {
$this->importFromCSV($type, $media); $this->importFromCSV($type, $media);
$import = $this->em->getRepository(Import::class)->findOneById($idimport); $import = $this->em->getRepository(Import::class)->findOneById($idimport);
...@@ -129,7 +127,14 @@ class ImportController extends CRUDController ...@@ -129,7 +127,14 @@ class ImportController extends CRUDController
); );
} }
return $this->redirect($this->admin->generateUrl('show', array('id' => $import->getId()))); return $this->redirect($this->admin->generateUrl('show', array('id' => $import->getId())));
} catch (\Exception $e) {
return $this->renderWithExtraParams('admin/import_error.html.twig', [
'action' => 'list',
'error' => $e->getMessage(),
]);
}
} }
return $this->renderWithExtraParams('admin/import.html.twig', array( return $this->renderWithExtraParams('admin/import.html.twig', array(
'action' => 'list', 'action' => 'list',
'form' => $form->createView(), 'form' => $form->createView(),
......
{% extends base_template %}
{% import _self as macros %}
{%- block tab_menu -%}
{{ knp_menu_render(admin.sidemenu(action), {
'currentClass': 'active',
'template': get_global_template('tab_menu_template')
}, 'twig') }}
{%- endblock -%}
{% block title %}
{{ 'Import de données : erreur !'|trans }}
{% endblock %}
{% block navbar_title %}
{{ block('title') }}
{% endblock %}
{% block content %}
<div class="px-3">
<h3>Erreur lors de l'importation !</h3>
<p><strong>Message à transmettre à l'équipe technique :</strong> {{ error }}</p>
</div>
{% endblock %}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment