Commit 8e7ca4e1 by Julien Jorry

Fix importController

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