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,32 +101,40 @@ class ImportController extends CRUDController ...@@ -104,32 +101,40 @@ class ImportController extends CRUDController
$this->em->flush(); $this->em->flush();
$idimport = $import->getId(); $idimport = $import->getId();
$this->importFromCSV($type, $media); try {
$this->importFromCSV($type, $media);
$import = $this->em->getRepository(Import::class)->findOneById($idimport); $import = $this->em->getRepository(Import::class)->findOneById($idimport);
$import->setEnabled(true); $import->setEnabled(true);
$import->setSuccess(json_encode($this->success)); $import->setSuccess(json_encode($this->success));
$import->setWarnings(json_encode($this->warnings)); $import->setWarnings(json_encode($this->warnings));
$import->setErrors(json_encode($this->errors)); $import->setErrors(json_encode($this->errors));
$import->setNbentityadded($this->nbsuccess); $import->setNbentityadded($this->nbsuccess);
$import->setNbentityerror($this->nberrors); $import->setNbentityerror($this->nberrors);
$this->em->persist($import); $this->em->persist($import);
$this->em->flush(); $this->em->flush();
if (empty($this->errors)) { if (empty($this->errors)) {
$this->addFlash( $this->addFlash(
'success', 'success',
'Import effectué avec succès !' 'Import effectué avec succès !'
); );
} else { } else {
$this->addFlash( $this->addFlash(
'error', 'error',
"Il y a eu des erreurs lors de l'import !" "Il y a eu des erreurs lors de l'import !"
); );
}
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->redirect($this->admin->generateUrl('show', array('id' => $import->getId())));
} }
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