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,7 +314,11 @@ class ImportController extends CRUDController ...@@ -313,7 +314,11 @@ 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] : '';
if (!empty(trim($contact))) {
$contactC = $this->em->getRepository(ContactComptoir::class)->findOneBy(['comptoir' => $comptoir, 'name' => $contact]);
if (empty($contactComptoir)) {
$contactC = new ContactComptoir(); $contactC = new ContactComptoir();
}
$contactC->setComptoir($comptoir); $contactC->setComptoir($comptoir);
$contactC->setEnabled(true); $contactC->setEnabled(true);
$contactC->setName($contact); $contactC->setName($contact);
...@@ -323,6 +328,9 @@ class ImportController extends CRUDController ...@@ -323,6 +328,9 @@ class ImportController extends CRUDController
$this->em->persist($contactC); $this->em->persist($contactC);
} }
$this->addSuccess($row, $line, 'contact', $this->translator->trans('Contact ajouté : ') . $contactC); $this->addSuccess($row, $line, 'contact', $this->translator->trans('Contact ajouté : ') . $contactC);
} else {
break;
}
++$cptContact; ++$cptContact;
} }
...@@ -554,7 +562,11 @@ class ImportController extends CRUDController ...@@ -554,7 +562,11 @@ 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] : '';
if (!empty(trim($contact))) {
$contactC = $this->em->getRepository(ContactPrestataire::class)->findOneBy(['prestataire' => $prestataire, 'name' => $contact]);
if (empty($contactC)) {
$contactC = new ContactPrestataire(); $contactC = new ContactPrestataire();
}
$contactC->setPrestataire($prestataire); $contactC->setPrestataire($prestataire);
$contactC->setEnabled(true); $contactC->setEnabled(true);
$contactC->setName($contact); $contactC->setName($contact);
...@@ -564,12 +576,17 @@ class ImportController extends CRUDController ...@@ -564,12 +576,17 @@ class ImportController extends CRUDController
$this->em->persist($contactC); $this->em->persist($contactC);
} }
$this->addSuccess($row, $line, 'contact', $this->translator->trans('Contact ajouté : ') . $contact); $this->addSuccess($row, $line, 'contact', $this->translator->trans('Contact ajouté : ') . $contact);
} else {
break;
}
++$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);
if (!$this->test) {
$prestataire->setUsers($gestionnaires); $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,8 +868,10 @@ class ImportController extends CRUDController ...@@ -848,8 +868,10 @@ 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'));
} }
if (!$this->test) {
$this->em->persist($cotisation); $this->em->persist($cotisation);
} }
}
// if (!$this->test) { // if (!$this->test) {
// try { // try {
// $this->operationUtils->executeOperations($cotisation); // $this->operationUtils->executeOperations($cotisation);
...@@ -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);
if (!$this->test) {
$this->em->persist($geolocFound); $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