src/Manager/Progress/ModerationAnnuaireManager.php line 82

Open in your IDE?
  1. <?php
  2. namespace App\Manager\Progress;
  3. use App\Entity\Adherent\Annuaire\MagasinContact;
  4. use App\Entity\Adherent\Annuaire\MagasinContactQualifier;
  5. use App\Entity\Adherent\Magasin;
  6. use App\Entity\ContactThemeCanal;
  7. use App\Manager\DatasProgress;
  8. use App\Manager\WsProgressManager;
  9. use App\Repository\Adherent\Annuaire\MagasinContactQualifierRepository;
  10. use App\Repository\ContactThemeCanalRepository;
  11. use App\Service\PhoneNumberService;
  12. use DateTime;
  13. use DateTimeImmutable;
  14. use Doctrine\ORM\EntityManagerInterface;
  15. use Doctrine\ORM\UnitOfWork;
  16. use Doctrine\DBAL\Exception;
  17. use libphonenumber\PhoneNumberUtil;
  18. use Psr\Log\LoggerInterface;
  19. use Symfony\Component\Console\Helper\ProgressBar;
  20. use Symfony\Component\Console\Output\OutputInterface;
  21. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  22. use Throwable;
  23. class ModerationAnnuaireManager
  24. {
  25.     private DateTime $today;
  26.     const TABLES = ['mails' => 'mail''telephones' => 'tel'];
  27.     const K_ENTITE_TYPE = ['MAGASIN''GERANT'];
  28.     private PhoneNumberUtil $phoneNumberUtil;
  29.     public function __construct(
  30.         private readonly WsProgressManager                 $wsProgressManager,
  31.         private readonly SessionInterface                  $session,
  32.         private readonly DatasProgress                     $datasProgress,
  33.         private readonly LoggerInterface                   $progressLogger,
  34.         private readonly MagasinContactQualifierRepository $magasinContactQualifierRepository,
  35.         private readonly ContactThemeCanalRepository       $contactThemeCanalRepository,
  36.         private readonly PhoneNumberService                $phoneNumberService,
  37.         private readonly EntityManagerInterface            $entityManager
  38.     )
  39.     {
  40.         $this->today = (new DateTime('now'));
  41.         $this->phoneNumberUtil PhoneNumberUtil::getInstance();
  42.     }
  43.     /**
  44.      * @param Magasin $magasin L'objet Magasin représentant le magasin.
  45.      * @param String $typeData Table a appeler
  46.      * @param String $category MAGASIN pour magasin ou GERANT pour individu si l'on veut recevoir les infos du mag ou de l'indiv principal
  47.      * @param String $libAmt * ou qualifiant du contact (mobile_pro par exemple)
  48.      * @return bool|array
  49.      * @throws Exception
  50.      */
  51.     public function getDatasProgress(Magasin $magasinstring $typeDatastring $categorystring $libAmt "*"): bool|array
  52.     {
  53.         //Changement de la centrale en fonction du code adhérent.
  54.         $this->wsProgressManager->selectTenant($magasin->getKAdherent());
  55.         if (array_key_exists($typeDataself::TABLES)) {
  56.             if (in_array($categoryself::K_ENTITE_TYPE)) {
  57.                 if ($category === "GERANT") {
  58.                     // si le type est INDIVIDU on va chercher l'identifiant du gérant car ce sont les contacts du gérant que nous allons chercher
  59.                     $proprietaire $this->datasProgress->getProprietaire($magasin->getKMag());
  60.                     if ($proprietaire) {
  61.                         return $this->callProgressAndFormatted($proprietaire['K_INDIV'], $libAmtself::TABLES[$typeData], $category);
  62.                     } else {
  63.                         throw new Exception('Le propriétaire est introuvable.');
  64.                     }
  65.                 } elseif ($category === "MAGASIN") {
  66.                     return $this->callProgressAndFormatted($magasin->getKMag(), $libAmtself::TABLES[$typeData], $category);
  67.                 }
  68.             } else {
  69.                 throw new Exception('Le type ' $category ' ne correspond à aucun type possible.');
  70.             }
  71.         } else {
  72.             throw new Exception('La table ' self::TABLES[$typeData] . ' ne correspond à aucune table possible.');
  73.         }
  74.     }
  75.     public function callProgressAndFormatted(string $IdEntityTypestring $libAmt '*'string $tablestring $category): array
  76.     {
  77.         ini_set('memory_limit''-1');
  78.         $finalData = [];
  79.         $datas = [
  80.             "ACTION" => "GET",
  81.             "K_ENTITE_ID" => $IdEntityType// Le code magasin ou le code individu en fonction du K_ENTITE_TYPE
  82.             "K_ENTITE_TYPE" => ($category === "GERANT") ? "I" : (($category === "MAGASIN") ? "M" null), // I pour INDIVIDU et M pour MAGASIN
  83.             "LIB_AMT" => $libAmt // Par défaut * mais peux être le qualifiant du contact (mobile_pro par exemple)
  84.         ];
  85.         $ch curl_init($this->wsProgressManager->getUrl() . "web/" $table);
  86.         curl_setopt($chCURLOPT_HTTPHEADER, ['Content-Type:application/json']);
  87.         curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  88.         curl_setopt($chCURLOPT_POSTFIELDSjson_encode($datas));
  89.         curl_setopt($chCURLOPT_SSL_VERIFYHOST0);
  90.         curl_setopt($chCURLOPT_SSL_VERIFYPEER0);
  91.         curl_setopt($chCURLOPT_FOLLOWLOCATIONfalse);
  92.         curl_setopt($chCURLOPT_COOKIE$this->session->get('wsProgress_Token'));
  93.         $response json_decode(curl_exec($ch), true);
  94.         $returnHeader curl_getinfo($ch);
  95.         if ($returnHeader['http_code'] == 302 && preg_match('/auth\/login.jsp/'$returnHeader['redirect_url'])) {
  96.             $this->progressLogger->info('http_code 302 aucun session => reconnexion', ['Connecté avec l\'adhérent' => $this->wsProgressManager->getCurrentUser()]);
  97.             $this->wsProgressManager->auth();
  98.             curl_setopt($chCURLOPT_COOKIE$this->session->get('wsProgress_Token'));
  99.             $response json_decode(curl_exec($ch), true);
  100.         }
  101.         curl_close($ch);
  102.         if (!is_null($response) && $response['dsResAmt'] && array_key_exists('ttAmt'$response['dsResAmt'])) {
  103.             // récupération de tous les types de contact possible (voir la bdd)
  104.             $magContactQualifier $this->entityManager->getRepository(MagasinContactQualifier::class)->findAll();
  105.             foreach ($response['dsResAmt']['ttAmt'] as $contact) {
  106.                 if (!is_null($contact[strtoupper($table)]) && preg_replace('/\s+/'''strtolower($contact[strtoupper($table)])) !== "enattente") {
  107.                     $ID_ANNUAIRE = (int)$contact['ID_ANNUAIRE']; // Récupère l'id unique du contact
  108.                     $canaux = (!empty($contact['CHPSUP'])) ? explode(';'trim($contact['CHPSUP'])) : [];
  109.                     $qualifiant null;
  110.                     foreach ($magContactQualifier as $possibleQualifier) {
  111.                         if (strtolower($possibleQualifier->getProgressIdentifier()) === strtolower($contact['LIB_AMT']) &&
  112.                             strtolower($possibleQualifier->getCategory()) === strtolower($category)
  113.                         ) {
  114.                             $qualifiant $possibleQualifier;
  115.                         }
  116.                     }
  117.                     if (!is_null($qualifiant)) {// si c'est un qualifiant que l'on prend en compte, on le traite
  118.                         // on stocke les contacts dans un tableau ayant pour clé l'identifiant unique du contact dans progress
  119.                         $finalData[$ID_ANNUAIRE] = [
  120.                             'created_at' => (!empty($contact['D_MAJ'])) ? DateTimeImmutable::createFromFormat('Y-m-d H:i:s'$contact['D_CREE'] . ' ' gmdate('H:i:s'$contact['H_CREE'])) : DateTimeImmutable::createFromFormat('Y-m-d''1970-01-01'),
  121.                             'updated_at' => (!empty($contact['D_MAJ'])) ? DateTimeImmutable::createFromFormat('Y-m-d H:i:s'$contact['D_MAJ'] . ' ' gmdate('H:i:s'$contact['H_MAJ'])) : DateTimeImmutable::createFromFormat('Y-m-d''1970-01-01'),
  122.                             'value' => $contact[strtoupper($table)],
  123.                             'canaux' => $canaux// canaux de communication
  124.                             'qualifiant' => $qualifiant,
  125.                             'ID_ANNUAIRE' => $ID_ANNUAIRE,
  126.                             'K_PROGRESS' => $contact["K_" strtoupper($table)],
  127.                             'lib_amt' => $contact['LIB_AMT'],
  128.                             'principal' => $contact['L_PRINCIPAL']
  129.                         ];
  130.                     }
  131.                 }
  132.             }
  133.         }
  134.         return $finalData;
  135.     }
  136.     /**
  137.      * @throws Exception
  138.      * Crée ou met à jour un contact dans progress
  139.      */
  140.     public function addOrUpdateContactInProgress(MagasinContact $magContact): MagasinContact
  141.     {
  142.         try {
  143.             $magasin $magContact->getMagasin();
  144.             $table = (in_array(strtolower($magContact->getQualifier()->getType()), array_values(self::TABLES))) ? strtolower($magContact->getQualifier()->getType()) : false;
  145.             $canaux array_map(function ($canal) {
  146.                 return $canal->getProgressIdentifier();
  147.             }, $magContact->getCanaux()->toArray());
  148.             switch ($magContact->getQualifier()->getCategory()) {
  149.                 case 'MAGASIN':
  150.                     $kEntityType "M";
  151.                     $kEntityId $magasin->getKMag();
  152.                     break;
  153.                 case 'GERANT':
  154.                     $kEntityType "I";
  155.                     $proprietaire $this->datasProgress->getProprietaire($magasin->getKMag());
  156.                     $kEntityId $proprietaire['K_INDIV'];
  157.                     break;
  158.             }
  159.             $dataToSend = [
  160.                 "ACTION" => "SET",
  161.                 "K_ENTITE_TYPE" => $kEntityType,
  162.                 "K_ENTITE_ID" => $kEntityId,
  163.                 "K_PAYS" => $magContact->getMagasin()->getKPays(),
  164.                 strtoupper($magContact->getQualifier()->getType()) => ($magContact->getQualifier()->getType() == 'TEL') ? $this->phoneNumberService->getNumberWithoutIndic($magContact->getValue()) : $magContact->getValue(), // "TEL" => "0606060606" || "MAIL" => "test@groupeall.fr"
  165.                 "EAQUALI" => implode(','$canaux),
  166.                 "LIB_AMT" => $magContact->getQualifier()->getProgressIdentifier(),
  167.                 "ID_ANNUAIRE" => $magContact->getIdAnnuaireProgress() !== null ? (int)$magContact->getIdAnnuaireProgress() : -1
  168.             ];
  169.             ini_set('memory_limit''-1');
  170.             $ch curl_init($this->wsProgressManager->getUrl() . "web/" $table);
  171.             curl_setopt($chCURLOPT_HTTPHEADER, ['Content-Type:application/json']);
  172.             curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  173.             curl_setopt($chCURLOPT_POSTFIELDSjson_encode($dataToSend));
  174.             curl_setopt($chCURLOPT_SSL_VERIFYHOST0);
  175.             curl_setopt($chCURLOPT_SSL_VERIFYPEER0);
  176.             curl_setopt($chCURLOPT_FOLLOWLOCATIONfalse);
  177.             curl_setopt($chCURLOPT_COOKIE$this->session->get('wsProgress_Token'));
  178.             $response json_decode(curl_exec($ch), true);
  179.             $returnHeader curl_getinfo($ch);
  180.             if ($returnHeader['http_code'] == 302 && preg_match('/auth\/login.jsp/'$returnHeader['redirect_url'])) {
  181.                 $this->progressLogger->info('http_code 302 aucun session => reconnexion', ['Connecté avec l\'adhérent' => $this->wsProgressManager->getCurrentUser()]);
  182.                 $this->wsProgressManager->auth();
  183.                 curl_setopt($chCURLOPT_COOKIE$this->session->get('wsProgress_Token'));
  184.                 $response json_decode(curl_exec($ch), true);
  185.             }
  186.             curl_close($ch);
  187.             if ($response && array_key_exists('dsResAmt'$response) && array_key_exists('ttAmt'$response['dsResAmt']) && count($response['dsResAmt']['ttAmt']) > 0) {
  188.                 $magContact->setIdAnnuaireProgress((int)$response['dsResAmt']['ttAmt'][0]["ID_ANNUAIRE"]);
  189.                 $magContact->setKProgress($response['dsResAmt']['ttAmt'][0]["K_" strtoupper($table)]);
  190.                 $magContact->setPrincipal($response['dsResAmt']['ttAmt'][0]["L_PRINCIPAL"]);
  191.                 $this->entityManager->persist($magContact);
  192.                 $this->entityManager->flush();
  193.             }
  194.             return $magContact;
  195.         } catch (Throwable $exception) {
  196.             throw new Exception($exception->getMessage());
  197.         }
  198.     }
  199.     /**
  200.      * @throws Exception
  201.      * Supprime un contact dans progress
  202.      */
  203.     public function removeContactInProgress(MagasinContact $magContact): void
  204.     {
  205.         try {
  206.             $magasin $magContact->getMagasin();
  207.             $table strtolower($magContact->getQualifier()->getType());
  208.             if (in_array($tableself::TABLES)) {
  209.                 switch ($magContact->getQualifier()->getCategory()) {
  210.                     case 'MAGASIN':
  211.                         $kEntityType "M";
  212.                         $kEntityId $magContact->getMagasin()->getKMag();
  213.                         break;
  214.                     case 'GERANT':
  215.                         $kEntityType "I";
  216.                         $proprietaire $this->datasProgress->getProprietaire($magasin->getKMag());
  217.                         $kEntityId $proprietaire['K_INDIV'];
  218.                         break;
  219.                 }
  220.                 $dataToSend = [
  221.                     "ACTION" => "DEL",
  222.                     "K_ENTITE_ID" => $kEntityId,
  223.                     "K_ENTITE_TYPE" => $kEntityType,
  224. //                    strtoupper($magContact->getQualifier()->getType()) => ($magContact->getQualifier()->getType() == 'TEL') ? $this->phoneNumberService->getNumberWithoutIndic($magContact->getValue()) : $magContact->getValue(), // "TEL" => "0606060606" || "MAIL" => "test@groupeall.fr"
  225.                     "ID_ANNUAIRE" => (int)$magContact->getIdAnnuaireProgress(),
  226.                     "LIB_AMT" => $magContact->getQualifier()->getProgressIdentifier()
  227.                 ];
  228.                 $ch curl_init($this->wsProgressManager->getUrl() . "web/" $table);
  229.                 curl_setopt($chCURLOPT_HTTPHEADER, ['Content-Type:application/json']);
  230.                 curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  231.                 curl_setopt($chCURLOPT_POSTFIELDSjson_encode($dataToSend));
  232.                 curl_setopt($chCURLOPT_SSL_VERIFYHOST0);
  233.                 curl_setopt($chCURLOPT_SSL_VERIFYPEER0);
  234.                 curl_setopt($chCURLOPT_FOLLOWLOCATIONfalse);
  235.                 curl_setopt($chCURLOPT_COOKIE$this->session->get('wsProgress_Token'));
  236.                 $response json_decode(curl_exec($ch), true);
  237.                 $returnHeader curl_getinfo($ch);
  238.                 if ($returnHeader['http_code'] == 302 && preg_match('/auth\/login.jsp/'$returnHeader['redirect_url'])) {
  239.                     $this->progressLogger->info('http_code 302 aucun session => reconnexion', ['Connecté avec l\'adhérent' => $this->wsProgressManager->getCurrentUser()]);
  240.                     $this->wsProgressManager->auth();
  241.                     curl_setopt($chCURLOPT_COOKIE$this->session->get('wsProgress_Token'));
  242.                     $response json_decode(curl_exec($ch), true);
  243.                 }
  244.                 curl_close($ch);
  245.             } else {
  246.                 throw new Exception('La table ' $table ' ne correspond à aucune table possible.');
  247.             }
  248.         } catch (Throwable $exception) {
  249.             throw new Exception($exception->getMessage());
  250.         }
  251.     }
  252.     /**
  253.      * @param bool $progressBarActive
  254.      * @param OutputInterface|null $cmdOutput
  255.      * @return string
  256.      * Cette fonction récupère toutes les données de progress et met à jour ceux de l'espace adhérent en conséquence
  257.      * Elle met a jour TOUS les adhérents
  258.      */
  259.     public function majDataProgressEadh(OutputInterface $cmdOutput null): string
  260.     {
  261.         $exceptions = [];
  262.         $canaux $this->entityManager->getRepository(ContactThemeCanal::class)->createQueryBuilder('c''c.progressIdentifier')->getQuery()->getResult();
  263.         $magasins $this->entityManager->getRepository(Magasin::class)->createQueryBuilder('m')
  264.             ->where('m.deleted IS NULL')->orWhere('m.deleted != 1')
  265. //            ->setMaxResults(25) //pour les tests
  266.             ->getQuery()->getResult();
  267.         $progressBar = new ProgressBar($cmdOutput);
  268.         $progressBar->setFormat('verbose');
  269.         $progressBar->start();
  270.         $progressBar->setMaxSteps(count($magasins));
  271.         $gap 10;
  272.         $i 0;
  273.         foreach ($magasins as $magasin) {
  274.             try {
  275.                 $cmdOutput->writeln(["_____________________________""<info>{$magasin->getKAdherent()}</info>"], OutputInterface::OUTPUT_PLAIN);
  276.                 $magasinState $this->entityManager->getUnitOfWork()->getEntityState($magasin);
  277.                 if ($magasinState === UnitOfWork::STATE_DETACHED) {
  278.                     // Recharger l'entité depuis la base pour éviter le problème des entités détachées
  279.                     $magasin $this->entityManager->getRepository(Magasin::class)->find($magasin->getKAdherent());
  280.                 }
  281.                 $cmdOutput->writeln(["_____________________________""<info>Comparaison et mise à jour des contacts</info>"], OutputInterface::OUTPUT_PLAIN);
  282.                 [$contactsBdd$exceptions] = $this->updateAdhContactsByProgress($magasin$canaux$exceptions);
  283.                 $i++;
  284.                 if ($i === $gap) {
  285.                     $cmdOutput->writeln(["__________________________________""<info>FLUSH...</info>"], OutputInterface::OUTPUT_PLAIN);
  286.                     $i 0;
  287.                     $this->entityManager->flush();
  288.                     $progressBar->advance($gap);
  289.                 }
  290.             } catch (Throwable $e) {
  291.                 $cmdOutput->writeln([
  292.                     "<error>{$e->getMessage()}</error>",
  293.                     "<error>{$e->getFile()}</error>",
  294.                     "<error>{$e->getLine()}</error>",
  295.                     "Adhérent : " $magasin->getKAdherent()
  296.                 ], OutputInterface::OUTPUT_NORMAL);
  297.             }
  298.         }
  299.         $this->entityManager->flush();
  300.         $progressBar->finish();
  301.         $cmdOutput->writeln([
  302.             "______________",
  303.             "<info>Mise à jour des CONTACTS réussie</info>",
  304.             "______________"
  305.         ], OutputInterface::OUTPUT_PLAIN);
  306.         return 'ok';
  307.     }
  308.     /**
  309.      * @param Magasin $magasin
  310.      * @param array $canaux // Tableau des canaux de communication possible
  311.      * @param array $exceptions // Tableau qui récupère les erreurs ou exceptions rencontrées
  312.      * @return array
  313.      */
  314.     public function updateAdhContactsByProgress(Magasin $magasin, array $canaux, array $exceptions): array
  315.     {
  316.         // Contacts de l'adhérent
  317.         $contactsBdd $this->entityManager->getRepository(MagasinContact::class)->findBy(['magasin' => $magasin->getKAdherent()]);
  318.         // Nettoyage des valeurs (reformatage)
  319.         foreach ($contactsBdd as $contactBdd) {
  320.             if ($contactBdd->getQualifier()->getType() === "TEL") {
  321.                 $cleanedNumber $this->phoneNumberService->validateAndFormatPhoneNumber($contactBdd->getValue(), strtoupper($magasin->getKPays()));
  322.                 if ($cleanedNumber === null) {
  323.                     $this->entityManager->remove($contactBdd);
  324.                 } else {
  325.                     $cleanedNumber preg_replace('/\s+/'''strtolower($cleanedNumber));
  326.                     $contactBdd->setValue($cleanedNumber);
  327.                     $this->entityManager->persist($contactBdd);
  328.                 }
  329.             } else {
  330.                 $cleanedNumber preg_replace('/\s+/'''strtolower($contactBdd->getValue()));
  331.                 $contactBdd->setValue(strtolower($cleanedNumber));
  332.             }
  333.         }
  334.         // Suppression des doublons après reformatage des valeurs - il y a une contrainte d'unicité avec magasin, qualifiant et value
  335.         // Attention on réaffecte tous les canaux du contact doublon qui va être supprimé
  336.         foreach ($contactsBdd as $key => $currentContact) {
  337.             foreach ($contactsBdd as $secondKey => $secondContact) {
  338.                 if ($key !== $secondKey && $currentContact->getValue() === $secondContact->getValue() && $currentContact->getQualifier() === $secondContact->getQualifier()) {
  339.                     $currentContact->setName($secondContact->getName());
  340.                     foreach ($secondContact->getCanaux() as $canal) {
  341.                         $currentContact->addCanaux($canal);
  342.                     }
  343.                     $this->entityManager->remove($secondContact);
  344.                     unset($contactsBdd[$key]);
  345.                 }
  346.             }
  347.         }
  348.         try {
  349.             //Telephones magasin
  350.             [$contactsBdd$exceptions] = $this->updateContactsByTypeByProgress($magasin$contactsBdd$canaux'telephones''MAGASIN'$exceptions);
  351.         } catch (Throwable $e) {
  352.             $exceptions[] = [
  353.                 'magasin' => $magasin->getKAdherent(),
  354.                 'exception' => $e->getMessage()
  355.             ];
  356.         }
  357.         try {
  358.             //Mails magasin
  359.             [$contactsBdd$exceptions] = $this->updateContactsByTypeByProgress($magasin$contactsBdd$canaux'mails''MAGASIN'$exceptions);
  360.         } catch (Throwable $e) {
  361.             $exceptions[] = [
  362.                 'magasin' => $magasin->getKAdherent(),
  363.                 'exception' => $e->getMessage()
  364.             ];
  365.         }
  366.         try {
  367.             //Telephones Individu principal
  368.             [$contactsBdd$exceptions] = $this->updateContactsByTypeByProgress($magasin$contactsBdd$canaux'telephones''GERANT'$exceptions);
  369.         } catch (Throwable $e) {
  370.             $exceptions[] = [
  371.                 'magasin' => $magasin->getKAdherent(),
  372.                 'exception' => $e->getMessage()
  373.             ];
  374.         }
  375.         try {
  376.             //Mails individus principal
  377.             [$contactsBdd$exceptions] = $this->updateContactsByTypeByProgress($magasin$contactsBdd$canaux'mails''GERANT'$exceptions);
  378.         } catch (Throwable $e) {
  379.             $exceptions[] = [
  380.                 'magasin' => $magasin->getKAdherent(),
  381.                 'exception' => $e->getMessage()
  382.             ];
  383.         }
  384.         return [$contactsBdd$exceptions];
  385.     }
  386.     /**
  387.      *
  388.      * @throws Exception
  389.      */
  390.     public function updateContactsByTypeByProgress(Magasin $mag, array $contactsBdd, array $canauxstring $typeDatastring $category, array $exceptions): array
  391.     {
  392.         $progressContacts $this->getDatasProgress($mag$typeData$category);
  393.         foreach ($progressContacts as $ProgressContact) {
  394.             // Je reformate et corrige les data pour qu'elles soit clean
  395.             if ($ProgressContact['qualifiant']->getType() === "TEL") {
  396.                 // tels
  397.                 $valueProgressFormatted $this->phoneNumberService->validateAndFormatPhoneNumber(preg_replace('/\s+/'''strtolower($ProgressContact['value'])), strtoupper($mag->getKPays()));
  398.             } else {
  399.                 // mails
  400.                 $valueProgressFormatted preg_replace('/\s+/'''strtolower($ProgressContact['value']));
  401.             }
  402.             if (!is_null($valueProgressFormatted)) {
  403.                 $existingContact false;
  404.                 // vérifie si il existe déjà en base, si il existe on compare les dates de maj et le met a jour si nécessaire
  405.                 foreach ($contactsBdd as $contactBdd) {
  406.                     if ($contactBdd->getQualifier() === $ProgressContact['qualifiant']) {
  407.                         if ($ProgressContact['qualifiant']->isMultiple()) {
  408.                             if ($valueProgressFormatted === preg_replace('/\s+/'''strtolower($contactBdd->getValue()))) {
  409.                                 $contactBdd->setIdAnnuaireProgress((int)$ProgressContact['ID_ANNUAIRE']);
  410.                                 $contactBdd->setKProgress($ProgressContact['K_PROGRESS']);
  411.                                 $contactBdd->setPrincipal($ProgressContact['principal']);
  412.                                 $existingContact $contactBdd;
  413.                             }
  414.                         } else {
  415.                             $contactBdd->seIdAnnuaireProgress((int)$ProgressContact['ID_ANNUAIRE']);
  416.                             $contactBdd->setKProgress($ProgressContact['K_PROGRESS']);
  417.                             $contactBdd->setPrincipal($ProgressContact['principal']);
  418.                             $existingContact $contactBdd;
  419.                             if ($ProgressContact['updated_at'] > $existingContact->getUpdatedAt()) {
  420.                                 $existingContact->setValue($valueProgressFormatted);
  421.                             }
  422.                         }
  423.                     }
  424.                 }
  425.                 if (!$existingContact) {
  426.                     $existingContact = new MagasinContact();
  427.                     $existingContact->setMagasin($mag);
  428.                     $existingContact->setQualifier($ProgressContact['qualifiant']);
  429.                     $existingContact->setValue($valueProgressFormatted);
  430.                     $existingContact->setIdAnnuaireProgress((int)$ProgressContact['ID_ANNUAIRE']);
  431.                     $existingContact->setKProgress($ProgressContact['K_PROGRESS']);
  432.                     $existingContact->setPrincipal($ProgressContact['principal']);
  433.                     $contactsBdd[] = $existingContact;
  434.                 }
  435.                 // Assignation des canaux de com si il y en a
  436.                 foreach ($ProgressContact['canaux'] as $canal) {
  437.                     if (array_key_exists($canal$canaux)) {
  438.                         $existingContact->addCanaux($canaux[$canal]);
  439.                     }
  440.                 }
  441.                 $existingContact->setExistInProgress(true);
  442.                 $this->entityManager->persist($existingContact);
  443.             }
  444.         }
  445.         return [$contactsBdd$exceptions];
  446.     }
  447. }