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
$this->sendemail = false;
}
/**
* @TODO: manage the case of a fatal error (so catch the exception, and display a nice message)!
*/
public function createAction()
{
$this->siege = $this->em->getRepository(Siege::class)->findOneById(1);
......@@ -104,32 +101,40 @@ class ImportController extends CRUDController
$this->em->flush();
$idimport = $import->getId();
$this->importFromCSV($type, $media);
try {
$this->importFromCSV($type, $media);
$import = $this->em->getRepository(Import::class)->findOneById($idimport);
$import->setEnabled(true);
$import = $this->em->getRepository(Import::class)->findOneById($idimport);
$import->setEnabled(true);
$import->setSuccess(json_encode($this->success));
$import->setWarnings(json_encode($this->warnings));
$import->setErrors(json_encode($this->errors));
$import->setNbentityadded($this->nbsuccess);
$import->setNbentityerror($this->nberrors);
$this->em->persist($import);
$this->em->flush();
$import->setSuccess(json_encode($this->success));
$import->setWarnings(json_encode($this->warnings));
$import->setErrors(json_encode($this->errors));
$import->setNbentityadded($this->nbsuccess);
$import->setNbentityerror($this->nberrors);
$this->em->persist($import);
$this->em->flush();
if (empty($this->errors)) {
$this->addFlash(
'success',
'Import effectué avec succès !'
);
} else {
$this->addFlash(
'error',
"Il y a eu des erreurs lors de l'import !"
);
if (empty($this->errors)) {
$this->addFlash(
'success',
'Import effectué avec succès !'
);
} else {
$this->addFlash(
'error',
"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(
'action' => 'list',
'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