Commit 8e7ca4e1 by Julien Jorry

Fix importController

parent fa7ce658
...@@ -30,6 +30,7 @@ use App\Utils\OperationUtils; ...@@ -30,6 +30,7 @@ use App\Utils\OperationUtils;
use Behat\Transliterator\Transliterator; use Behat\Transliterator\Transliterator;
use DateTime; use DateTime;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
use FOS\UserBundle\Event\UserEvent; use FOS\UserBundle\Event\UserEvent;
use FOS\UserBundle\Model\UserManagerInterface; use FOS\UserBundle\Model\UserManagerInterface;
use FOS\UserBundle\Util\TokenGeneratorInterface; use FOS\UserBundle\Util\TokenGeneratorInterface;
...@@ -313,16 +314,23 @@ class ImportController extends CRUDController ...@@ -313,16 +314,23 @@ class ImportController extends CRUDController
$contact = array_key_exists('contact' . $cptContact, $row) ? $row['contact' . $cptContact] : ''; $contact = array_key_exists('contact' . $cptContact, $row) ? $row['contact' . $cptContact] : '';
$phone = array_key_exists('phone' . $cptContact, $row) ? $row['phone' . $cptContact] : ''; $phone = array_key_exists('phone' . $cptContact, $row) ? $row['phone' . $cptContact] : '';
$email = array_key_exists('email' . $cptContact, $row) ? $row['email' . $cptContact] : ''; $email = array_key_exists('email' . $cptContact, $row) ? $row['email' . $cptContact] : '';
$contactC = new ContactComptoir(); if (!empty(trim($contact))) {
$contactC->setComptoir($comptoir); $contactC = $this->em->getRepository(ContactComptoir::class)->findOneBy(['comptoir' => $comptoir, 'name' => $contact]);
$contactC->setEnabled(true); if (empty($contactComptoir)) {
$contactC->setName($contact); $contactC = new ContactComptoir();
$contactC->setTel($phone); }
$contactC->setEmail($email); $contactC->setComptoir($comptoir);
if (!$this->test) { $contactC->setEnabled(true);
$this->em->persist($contactC); $contactC->setName($contact);
$contactC->setTel($phone);
$contactC->setEmail($email);
if (!$this->test) {
$this->em->persist($contactC);
}
$this->addSuccess($row, $line, 'contact', $this->translator->trans('Contact ajouté : ') . $contactC);
} else {
break;
} }
$this->addSuccess($row, $line, 'contact', $this->translator->trans('Contact ajouté : ') . $contactC);
++$cptContact; ++$cptContact;
} }
...@@ -554,22 +562,31 @@ class ImportController extends CRUDController ...@@ -554,22 +562,31 @@ class ImportController extends CRUDController
$contact = array_key_exists('contact' . $cptContact, $row) ? $row['contact' . $cptContact] : ''; $contact = array_key_exists('contact' . $cptContact, $row) ? $row['contact' . $cptContact] : '';
$phone = array_key_exists('phone' . $cptContact, $row) ? $row['phone' . $cptContact] : ''; $phone = array_key_exists('phone' . $cptContact, $row) ? $row['phone' . $cptContact] : '';
$email = array_key_exists('email' . $cptContact, $row) ? $row['email' . $cptContact] : ''; $email = array_key_exists('email' . $cptContact, $row) ? $row['email' . $cptContact] : '';
$contactC = new ContactPrestataire(); if (!empty(trim($contact))) {
$contactC->setPrestataire($prestataire); $contactC = $this->em->getRepository(ContactPrestataire::class)->findOneBy(['prestataire' => $prestataire, 'name' => $contact]);
$contactC->setEnabled(true); if (empty($contactC)) {
$contactC->setName($contact); $contactC = new ContactPrestataire();
$contactC->setTel($phone); }
$contactC->setEmail($email); $contactC->setPrestataire($prestataire);
if (!$this->test) { $contactC->setEnabled(true);
$this->em->persist($contactC); $contactC->setName($contact);
$contactC->setTel($phone);
$contactC->setEmail($email);
if (!$this->test) {
$this->em->persist($contactC);
}
$this->addSuccess($row, $line, 'contact', $this->translator->trans('Contact ajouté : ') . $contact);
} else {
break;
} }
$this->addSuccess($row, $line, 'contact', $this->translator->trans('Contact ajouté : ') . $contact);
++$cptContact; ++$cptContact;
} }
// Importer les gestionnaires du prestataire s'ils existent // Importer les gestionnaires du prestataire s'ils existent
$groupeGestionnaire = $this->em->getRepository(Usergroup::class)->findOneByName('Prestataire'); $groupeGestionnaire = $this->em->getRepository(Usergroup::class)->findOneByName('Prestataire');
$gestionnaires = $this->importGestionnaires($row, $line, $groupeGestionnaire); $gestionnaires = $this->importGestionnaires($row, $line, $groupeGestionnaire);
$prestataire->setUsers($gestionnaires); if (!$this->test) {
$prestataire->setUsers($gestionnaires);
}
if (!empty($groupe)) { if (!empty($groupe)) {
$groupeFound = $this->em->getRepository(Groupe::class)->findOneBy(['slug' => $this->slugify($groupe)]); $groupeFound = $this->em->getRepository(Groupe::class)->findOneBy(['slug' => $this->slugify($groupe)]);
...@@ -808,6 +825,9 @@ class ImportController extends CRUDController ...@@ -808,6 +825,9 @@ class ImportController extends CRUDController
} else { } else {
$this->addWarning($row, $line, 'groupe', 'empty'); $this->addWarning($row, $line, 'groupe', 'empty');
} }
if (!$this->test) {
$this->em->persist($adherent);
}
if (!empty($cotisations)) { if (!empty($cotisations)) {
$cotisationArray = explode(',', $cotisations); $cotisationArray = explode(',', $cotisations);
...@@ -848,7 +868,9 @@ class ImportController extends CRUDController ...@@ -848,7 +868,9 @@ class ImportController extends CRUDController
$cotisation->getCotisationInfos()->setDebut(DateTime::createFromFormat('Ymd', intval($cotisationDetailsArray[1]) . '0101')); $cotisation->getCotisationInfos()->setDebut(DateTime::createFromFormat('Ymd', intval($cotisationDetailsArray[1]) . '0101'));
$cotisation->getCotisationInfos()->setFin(DateTime::createFromFormat('Ymd', intval($cotisationDetailsArray[1]) . '1231')); $cotisation->getCotisationInfos()->setFin(DateTime::createFromFormat('Ymd', intval($cotisationDetailsArray[1]) . '1231'));
} }
$this->em->persist($cotisation); if (!$this->test) {
$this->em->persist($cotisation);
}
} }
// if (!$this->test) { // if (!$this->test) {
// try { // try {
...@@ -876,7 +898,9 @@ class ImportController extends CRUDController ...@@ -876,7 +898,9 @@ class ImportController extends CRUDController
$geolocFound->setCpostal($cpostal); $geolocFound->setCpostal($cpostal);
$geolocFound->setVille($ville); $geolocFound->setVille($ville);
$adherent->setGeoloc($geolocFound); $adherent->setGeoloc($geolocFound);
$this->em->persist($geolocFound); if (!$this->test) {
$this->em->persist($geolocFound);
}
$this->addSuccess($row, $line, 'adresse', $this->translator->trans('Adhérent : nouvelle adresse : ') . $geolocFound->__toString()); $this->addSuccess($row, $line, 'adresse', $this->translator->trans('Adhérent : nouvelle adresse : ') . $geolocFound->__toString());
} }
} }
...@@ -1136,9 +1160,11 @@ class ImportController extends CRUDController ...@@ -1136,9 +1160,11 @@ class ImportController extends CRUDController
$userFound = $this->em->getRepository(User::class)->findOneBy(['email' => $email]); $userFound = $this->em->getRepository(User::class)->findOneBy(['email' => $email]);
if (!empty($userFound)) { if (!empty($userFound)) {
$userFound->addPossiblegroup($groupe); $userFound->addPossiblegroup($groupe);
$users[] = $userFound;
if (!$this->test) { if (!$this->test) {
$users[] = $userFound;
$this->em->persist($userFound); $this->em->persist($userFound);
} else {
$this->em->detach($userFound);
} }
$this->addSuccess($row, $line, 'gestionnaire', $this->translator->trans('Rôle ' . $groupe . ' ajouté à l\'utilisateur ') . $userFound); $this->addSuccess($row, $line, 'gestionnaire', $this->translator->trans('Rôle ' . $groupe . ' ajouté à l\'utilisateur ') . $userFound);
} else { } else {
...@@ -1148,7 +1174,7 @@ class ImportController extends CRUDController ...@@ -1148,7 +1174,7 @@ class ImportController extends CRUDController
$mobile = array_key_exists('gestionnaire_mobile' . $cptGestionnaire, $row) ? $row['gestionnaire_mobile' . $cptGestionnaire] : ''; $mobile = array_key_exists('gestionnaire_mobile' . $cptGestionnaire, $row) ? $row['gestionnaire_mobile' . $cptGestionnaire] : '';
$adherent = new Adherent(); $adherent = new Adherent();
$user = $this->userManager->createUser(); $user = new User(); // $this->userManager->createUser();
$user->setConfirmationToken($this->tokenGenerator->generateToken()); $user->setConfirmationToken($this->tokenGenerator->generateToken());
$user->setEnabled(true); $user->setEnabled(true);
$user->setPassword(md5(random_bytes(10))); $user->setPassword(md5(random_bytes(10)));
......
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