Commit 210f531c by Damien Moulard

Fix batch import adherents/presta

parent 956fb4ad
...@@ -17,6 +17,7 @@ use App\Entity\Rubrique; ...@@ -17,6 +17,7 @@ use App\Entity\Rubrique;
use App\Entity\Siege; use App\Entity\Siege;
use App\Entity\User; use App\Entity\User;
use App\Entity\Usergroup; use App\Entity\Usergroup;
use App\Entity\Flux;
use App\Enum\ImportEnum; use App\Enum\ImportEnum;
use App\Enum\MoyenEnum; use App\Enum\MoyenEnum;
use App\Events\MLCEvents; use App\Events\MLCEvents;
...@@ -333,6 +334,8 @@ class ImportController extends CRUDController ...@@ -333,6 +334,8 @@ class ImportController extends CRUDController
private function importPrestataire($csvRows) private function importPrestataire($csvRows)
{ {
$operateur = $this->getUser();
$operateur_id = $operateur->getId();
// Iterate over the reader and write each row to the database // Iterate over the reader and write each row to the database
// groupe;adresse;cpostal;ville;raison;ecompte;metier;statut;responsable;iban;siret;web;horaires;description;rubriques;tags;tauxreconversion;cotisations;gestionnaire_email1;gestionnaire_nom1;gestionnaire_prenom1;gestionnaire_phone1;gestionnaire_mobile1;contact1;phone1;email1;contact2;phone2;email2 // groupe;adresse;cpostal;ville;raison;ecompte;metier;statut;responsable;iban;siret;web;horaires;description;rubriques;tags;tauxreconversion;cotisations;gestionnaire_email1;gestionnaire_nom1;gestionnaire_prenom1;gestionnaire_phone1;gestionnaire_mobile1;contact1;phone1;email1;contact2;phone2;email2
$line = 1; $line = 1;
...@@ -495,7 +498,7 @@ class ImportController extends CRUDController ...@@ -495,7 +498,7 @@ class ImportController extends CRUDController
$cotisation = new CotisationPrestataire(); $cotisation = new CotisationPrestataire();
$now = new DateTime(); $now = new DateTime();
$cotisation->setReference('Import du '.$now->format('d/m/Y H:i')); $cotisation->setReference('Import du '.$now->format('d/m/Y H:i'));
$cotisation->setOperateur($this->getUser()); $cotisation->setOperateur($operateur);
$cotisation->setRole('ROLE_SUPER_ADMIN'); $cotisation->setRole('ROLE_SUPER_ADMIN');
$cotisation->setExpediteur($prestataire); $cotisation->setExpediteur($prestataire);
$cotisation->setMoyen(MoyenEnum::MOYEN_AUTRE); $cotisation->setMoyen(MoyenEnum::MOYEN_AUTRE);
...@@ -569,6 +572,8 @@ class ImportController extends CRUDController ...@@ -569,6 +572,8 @@ class ImportController extends CRUDController
$this->em->persist($prestataire); $this->em->persist($prestataire);
$this->em->flush(); $this->em->flush();
$this->em->clear(); $this->em->clear();
// em is fully cleared: we need to refetch entities we get from em during process
$operateur = $this->em->getRepository(User::class)->findOneBy(array('id' => $operateur_id));
} }
$line++; $line++;
...@@ -579,6 +584,9 @@ class ImportController extends CRUDController ...@@ -579,6 +584,9 @@ class ImportController extends CRUDController
private function importAdherent($csvRows) private function importAdherent($csvRows)
{ {
// Batch operations with doctrine require some workaround
$operateur = $this->getUser();
$operateur_id = $operateur->getId();
// Iterate over the reader and write each row to the database // Iterate over the reader and write each row to the database
// groupe;firstname;lastname;email;phone;mobile;adresse;cpostal;ville;ecompte // groupe;firstname;lastname;email;phone;mobile;adresse;cpostal;ville;ecompte
$line = 1; $line = 1;
...@@ -678,7 +686,7 @@ class ImportController extends CRUDController ...@@ -678,7 +686,7 @@ class ImportController extends CRUDController
$cotisation = new CotisationAdherent(); $cotisation = new CotisationAdherent();
$now = new DateTime(); $now = new DateTime();
$cotisation->setReference('Import du '.$now->format('d/m/Y H:i')); $cotisation->setReference('Import du '.$now->format('d/m/Y H:i'));
$cotisation->setOperateur($this->getUser()); $cotisation->setOperateur($operateur);
$cotisation->setRole('ROLE_ADHERENT'); $cotisation->setRole('ROLE_ADHERENT');
$cotisation->setExpediteur($adherent); $cotisation->setExpediteur($adherent);
$cotisation->setMoyen(MoyenEnum::MOYEN_AUTRE); $cotisation->setMoyen(MoyenEnum::MOYEN_AUTRE);
...@@ -694,7 +702,7 @@ class ImportController extends CRUDController ...@@ -694,7 +702,7 @@ class ImportController extends CRUDController
$cotisation->getCotisationInfos()->setFin(DateTime::createFromFormat('Ymd', intval($cotisationDetailsArray[1]).'1231')); $cotisation->getCotisationInfos()->setFin(DateTime::createFromFormat('Ymd', intval($cotisationDetailsArray[1]).'1231'));
} }
$this->em->persist($cotisation); $this->em->persist($cotisation);
$this->addSuccess($row, $line, 'cotisations', $this->translator->trans('Cotisation ajouté : ').$groupe); $this->addSuccess($row, $line, 'cotisations', $this->translator->trans('Cotisation ajoutée : ').$groupe);
} }
} }
} else { } else {
...@@ -717,6 +725,8 @@ class ImportController extends CRUDController ...@@ -717,6 +725,8 @@ class ImportController extends CRUDController
} }
$this->em->flush(); $this->em->flush();
$this->em->clear(); $this->em->clear();
// em is fully cleared: we need to refetch entities we get from em during process
$operateur = $this->em->getRepository(User::class)->findOneBy(array('id' => $operateur_id));
} }
$line++; $line++;
......
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span> <span class="navbar-toggler-icon"></span>
</button> </button>
;
{% if menuItems is not defined %} {% if menuItems is not defined %}
{% set menuItems = getMenuItemsFromAlias('main') %} {% set menuItems = getMenuItemsFromAlias('main') %}
{% endif %} {% endif %}
......
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