Commit 210f531c by Damien Moulard

Fix batch import adherents/presta

parent 956fb4ad
......@@ -17,6 +17,7 @@ use App\Entity\Rubrique;
use App\Entity\Siege;
use App\Entity\User;
use App\Entity\Usergroup;
use App\Entity\Flux;
use App\Enum\ImportEnum;
use App\Enum\MoyenEnum;
use App\Events\MLCEvents;
......@@ -333,6 +334,8 @@ class ImportController extends CRUDController
private function importPrestataire($csvRows)
{
$operateur = $this->getUser();
$operateur_id = $operateur->getId();
// 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
$line = 1;
......@@ -495,7 +498,7 @@ class ImportController extends CRUDController
$cotisation = new CotisationPrestataire();
$now = new DateTime();
$cotisation->setReference('Import du '.$now->format('d/m/Y H:i'));
$cotisation->setOperateur($this->getUser());
$cotisation->setOperateur($operateur);
$cotisation->setRole('ROLE_SUPER_ADMIN');
$cotisation->setExpediteur($prestataire);
$cotisation->setMoyen(MoyenEnum::MOYEN_AUTRE);
......@@ -569,6 +572,8 @@ class ImportController extends CRUDController
$this->em->persist($prestataire);
$this->em->flush();
$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++;
......@@ -579,6 +584,9 @@ class ImportController extends CRUDController
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
// groupe;firstname;lastname;email;phone;mobile;adresse;cpostal;ville;ecompte
$line = 1;
......@@ -678,7 +686,7 @@ class ImportController extends CRUDController
$cotisation = new CotisationAdherent();
$now = new DateTime();
$cotisation->setReference('Import du '.$now->format('d/m/Y H:i'));
$cotisation->setOperateur($this->getUser());
$cotisation->setOperateur($operateur);
$cotisation->setRole('ROLE_ADHERENT');
$cotisation->setExpediteur($adherent);
$cotisation->setMoyen(MoyenEnum::MOYEN_AUTRE);
......@@ -694,7 +702,7 @@ class ImportController extends CRUDController
$cotisation->getCotisationInfos()->setFin(DateTime::createFromFormat('Ymd', intval($cotisationDetailsArray[1]).'1231'));
}
$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 {
......@@ -717,6 +725,8 @@ class ImportController extends CRUDController
}
$this->em->flush();
$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++;
......
......@@ -8,4 +8,4 @@
{% include 'common/menu.html.twig' %}
{% endblock menu %}
</nav>
</header>
\ No newline at end of file
</header>
<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>
</button>
;
{% if menuItems is not defined %}
{% set menuItems = getMenuItemsFromAlias('main') %}
{% 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