<?php
namespace App\Service;
use App\Entity\Session;
use App\Entity\UserPlacementTest;
use Symfony\Component\DependencyInjection\ContainerInterface as Container;
use Doctrine\ORM\EntityManagerInterface;
use App\Entity\SubscriptionOrder;
use App\Entity\SessionOrder;
use App\Entity\EmailListUnsubscribeLog;
use App\Entity\EmailListSubscribeLostLog;
use App\Entity\EmailListActionLog;
use App\Repository\SubscriptionOrderRepository;
use App\Repository\SessionOrderRepository;
use TestMonitor\ActiveCampaign\Resources\Contact;
use TestMonitor\ActiveCampaign\Resources\CustomField;
class ActiveCampaignHelper
{
protected $container;
protected $em;
private $activeCampaign;
private $Activecampaign_url;
private $subscriptionOrderRepository;
private $sessionOrderRepository;
const ID_LIST_SUBSCRIBE_PRIVATE = 168; // List : élèves actuels = 168
const ID_LIST_SUBSCRIBE_GROUP = 169; // List : élèves Cours collectif = 169
const ID_LIST_UNSUBSCRIBE_PRIVATE = 140; // List : Anciens élèves = 140
const ID_LIST_UNSUBSCRIBE_GROUP = 167; // list : Anciens étudiants collectifs = 167
const ID_LIST_MAIN = 175; // List principale
public function __construct(Container $container, EntityManagerInterface $entityManager, SubscriptionOrderRepository $subscriptionOrderRepository, SessionOrderRepository $sessionOrderRepository)
{
$this->container = $container;
$this->em = $entityManager;
$Activecampaign_url = $this->container->getParameter('ACTIVECAMPAIGN_URL');
$Activecampaign_api_key = $this->container->getParameter('ACTIVECAMPAIGN_API_KEY');
$activeCampaign = new ActiveCampaignApi($Activecampaign_url, $Activecampaign_api_key);
$this->activeCampaign = $activeCampaign;
$this->Activecampaign_url = $Activecampaign_url;
$this->subscriptionOrderRepository = $subscriptionOrderRepository;
$this->sessionOrderRepository = $sessionOrderRepository;
}
public function getAllListsByName($name)
{
$data = [];
$res = $this->activeCampaign->findListByLimit($name, 50);
return $res;
}
public function getAllListsChoiceField()
{
$data = [];
$res = $this->getAllListsByName('lists');
foreach ($res as $e) {
$data[$e->name] = $e->id;
}
return $data;
}
public function getAllTagsChoiceField()
{
$data = [];
$res = $this->getAllListsByName('tags');
//var_dump($res);
foreach ($res as $e) {
$data[$e->tag] = $e->tag;
}
return $data;
}
public function getOrCreateContact($order)
{
$contact = null;
if (
$order != null
) {
$lastName = "";
$firstName = "";
$email = "";
$phone = "";
$participant = null;
$user = null;
if ($order instanceof SubscriptionOrder) {
$participant = $order->getParticipant();
$user = $order->getUser();
}
if ($order instanceof SessionOrder) {
$participant = $order->getParticipant();
$user = $order->getStudents();
}
if ($order instanceof UserPlacementTest) {
$participant = $order->getParticipant();
$user = $order->getUser();
}
if ($user != null) {
$lastName = $user->getLastName();
$firstName = $user->getFirstName();
$email = $user->getEmail();
if ($participant != null && $participant->getLastName() != "" && $participant->getFirstName() != "") {
$lastName = $participant->getLastName();
$firstName = $participant->getFirstName();
}
$phone = "";
}
// Find or create a contact.
$contact = $this->activeCampaign->findOrCreateContact($email, $firstName, $lastName, $phone);
}
return $contact;
}
// Get Lists ID & TAGS to subscribe or unnsubscribe
public function getListsAndTags($order, $isUnsubscribe = false)
{
$addToListPrivate = false;
$addToListGroup = false;
$lists = [];
$tags = [];
// Attacher les listes par defaut selon le type Entity
$periods = [];
$subjects = [];
if ($order instanceof SubscriptionOrder) {
// Attacher Tag language
$user = $order->getUser();
if ($user != null) {
$tagLanguage = $user->getLanguage();
// Verifier si Abonnement
if (!$isUnsubscribe)
$tags[] = $tagLanguage;
}
// Attacher Categorie Arabe or Coran
$category = $order->getCategory();
if ($category != null) {
// Remonter tag category lors de l'abonnement
$tags[] = $category->getName();
}
$subject = $order->getSubject();
if ($subject != null) {
$subjects[] = $subject->getId();
// Remonter tag subject lors de l'abonnement
$tags[] = $subject->getTagName();
}
$addToListPrivate = true;
}
if ($order instanceof SessionOrder) {
// Attacher Tag language
$user = $order->getStudents();
if ($user != null) {
$tagLanguage = $user->getLanguage();
// Verifier si Abonnement
if (!$isUnsubscribe)
$tags[] = $tagLanguage;
}
// Attacher session Exemple : juillet2021
$session = $order->getSession();
if ($session != null) {
// Remonter Period subject lors de l'abonnement
$tags[] = $session->getPeriod();
$periods[] = $session->getPeriod();
// Attacher session Exemple : Niveau 1
$level = $session->getLevel();
if ($level != null) {
// Remonter level subject lors de l'abonnement
$tags[] = $level->getName();
$subject = $level->getSubject();
if ($subject != null) {
$subjects[] = $subject->getId();
// Remonter tag subject lors de l'abonnement
$tags[] = $subject->getTagName();
}
}
}
$addToListGroup = true;
}
if ($addToListPrivate) {
$lists[] = self::ID_LIST_SUBSCRIBE_PRIVATE;
} elseif ($addToListGroup) {
$lists[] = self::ID_LIST_SUBSCRIBE_GROUP;
}
// Recuperer tous les Tags avec une requette SQL si desabonnement
if ($isUnsubscribe) {
$tags = $this->getTagsFromAllOrdersFromDB($order, $isUnsubscribe);
}
$lists = array_unique($lists);
$tags = array_unique($tags);
$res = [
"lists" => $lists,
"tags" => $tags
];
return (object) $res;
}
public function getTagsFromAllOrdersFromDB($order, $isUnsubscribe = false)
{
$tags = [];
if ($order instanceof SubscriptionOrder) {
$user = $order->getUser();
if ($user != null) {
// recuperer les tags
// Category
$field = 'category';
$tagsToAdd = $this->subscriptionOrderRepository->getTagsFromSubscriptionForUser($user, $isUnsubscribe, $field);
$tags = array_merge($tags, $tagsToAdd);
// Subject
$field = 'subject';
$tagsToAdd = $this->subscriptionOrderRepository->getTagsFromSubscriptionForUser($user, $isUnsubscribe, $field);
$tags = array_merge($tags, $tagsToAdd);
}
}
if ($order instanceof SessionOrder) {
// Attacher Tag language
$user = $order->getStudents();
if ($user != null) {
// recuperer les Tags
// Period
$field = 'period';
$tagsToAdd = $this->sessionOrderRepository->getTagsFromSessionForUser($user, $isUnsubscribe, $field);
$tags = array_merge($tags, $tagsToAdd);
// Level
$field = 'level';
$tagsToAdd = $this->sessionOrderRepository->getTagsFromSessionForUser($user, $isUnsubscribe, $field);
$tags = array_merge($tags, $tagsToAdd);
// Subject
$field = 'subject';
$tagsToAdd = $this->sessionOrderRepository->getTagsFromSessionForUser($user, $isUnsubscribe, $field);
$tags = array_merge($tags, $tagsToAdd);
}
}
return $tags;
}
public function getListsUnsubscribe($order, $unsubscribeAll = false)
{
$addToListPrivate = false;
$addToListGroup = false;
$lists = [];
// Attacher les listes par defaut
if ($order instanceof SubscriptionOrder) {
$addToListPrivate = true;
}
if ($order instanceof SessionOrder) {
$addToListGroup = true;
}
if ($unsubscribeAll) {
$lists[] = self::ID_LIST_UNSUBSCRIBE_PRIVATE;
$lists[] = self::ID_LIST_UNSUBSCRIBE_GROUP;
} else {
if ($addToListPrivate) {
$lists[] = self::ID_LIST_UNSUBSCRIBE_PRIVATE;
} elseif ($addToListGroup) {
$lists[] = self::ID_LIST_UNSUBSCRIBE_GROUP;
}
}
return $lists;
}
// Get Lists ID to subscribe
public function getListIds($listAndTags)
{
$res = $listAndTags->lists;
return $res;
}
// Get TAGS to subscribe
public function getTags($listAndTags)
{
$res = [];
$tags = $listAndTags->tags;
foreach ($tags as $t) {
if ($t != null) {
$tag = $this->activeCampaign->findTagList($t);
if ($tag != null) {
$res[] = $tag;
}
}
}
return $res;
}
/*
* Subscribe a contact to a list or unsubscribe a contact from a list.
*
* @param int $list ID of list to remove contact from
* @param int $contact ID of contact to remove from list
* @param bool $subscribe TRUE to subscribe, FALSE otherwise
*/
public function updateContactLists($listsID = [], $contactID = "", $subscribe = true)
{
foreach ($listsID as $listID) {
$this->activeCampaign->updateListStatus($listID, $contactID, $subscribe);
}
}
/*
Add Tags to contact
*/
public function addTagsToContact($tags, $contact)
{
foreach ($tags as $tag) {
//$tag = $this->activeCampaign->findTag($nameTag);
$this->activeCampaign->addTagToContact($contact, $tag);
}
return $tags;
}
/*
* Create Contact in ActiveCampain API
*/
public function addOrder($order)
{
if ($this->checkApiDown($order))
return false;
if ($order != null) {
try {
$this->subscribeContactToLists($order);
} catch (\Exception $e) {
$this->logFailedAction(EmailListActionLog::ACTION_SUBSCRIBE, $e, $this->buildOrderContext($order));
return false;
}
}
return true;
}
/*
* Subscribe contact to lists
*/
public function subscribeContactToLists($order)
{
// Cree Contact dans ActiveCampaign
$contact = $this->getOrCreateContact($order);
if ($contact != null) {
$contactID = $contact->id;
$listAndTags = $this->getListsAndTags($order);
$listsID = $this->getListIds($listAndTags);
$tags = $this->getTags($listAndTags);
$subscribe = true;
$this->updateContactLists($listsID, $contactID, $subscribe);
$this->addTagsToContact($tags, $contact);
// Abonner à la liste principale
$this->activeCampaign->updateListStatus(self::ID_LIST_MAIN, $contactID, true);
// Unsubscribe contact in lists Archive
$listsID = $this->getListsUnsubscribe($order);
$subscribe = false;
$this->updateContactLists($listsID, $contactID, $subscribe);
}
}
/*
* Unsubscribe contact from Old Lists
*/
public function unsubscribeOrder($order)
{
if ($order != null) {
try {
$this->unsubscribeContactToLists($order);
} catch (\Exception $e) {
$this->logFailedAction(EmailListActionLog::ACTION_UNSUBSCRIBE, $e, $this->buildOrderContext($order));
}
}
}
public function removeTagsContact($contact, $tags)
{
foreach ($tags as $tag) {
$this->activeCampaign->removeTagFromContact($contact, $tag);
}
}
public function unsubscribeContactToLists($order)
{
// Cree Contact dans ActiveCampaign
$contact = $this->getOrCreateContact($order);
if ($contact != null) {
$contactID = $contact->id;
$isUnsubscribe = true;
$listAndTags = $this->getListsAndTags($order, $isUnsubscribe);
$listsID = $this->getListIds($listAndTags);
$tags = $this->getTags($listAndTags);
// Check if active SessionOrder or SubscriptionOrder exist
$ordersActiveExist = $this->checkOrderSActiveExist($order);
if ($ordersActiveExist) {
// Unsubscribe from Lists ( Anciens élèves , Anciens étudiants collectifs )
$listsID = $this->getListsUnsubscribe($order);
$subscribe = false;
$this->updateContactLists($listsID, $contactID, $subscribe);
} else {
// Unsubscribe from All Lists
$subscribe = false;
$this->updateContactLists($listsID, $contactID, $subscribe);
// Subscribe contact in lists Archive
$listsID = $this->getListsUnsubscribe($order);
$subscribe = true;
$this->updateContactLists($listsID, $contactID, $subscribe);
}
// Remove tags contact
$this->removeTagsContact($contact, $tags);
// add log
$this->addLogUnsubscribeLog($order);
}
}
public function checkOrderSActiveExist($order)
{
// verifier si order actif existe
$exist = false;
$nbOrders = 0;
if ($order instanceof SubscriptionOrder) {
$user = $order->getUser();
$nbOrders = $this->subscriptionOrderRepository->getNumberActiveSubscriptionForUser($user);
}
if ($order instanceof SessionOrder) {
$user = $order->getStudents();
$nbOrders = $this->sessionOrderRepository->getNumberActiveSessionsForUser($user);
}
//echo " nbOrders : $nbOrders <br> ";
if ($nbOrders > 0) {
$exist = true;
}
return $exist;
}
public function addLogUnsubscribeLog($order)
{
//Ajouter log lors de désabonemement
$emailListUnsubscribeLog = new EmailListUnsubscribeLog();
if ($order instanceof SubscriptionOrder) {
$emailListUnsubscribeLog->setSubscriptionOrder($order);
}
if ($order instanceof SessionOrder) {
$emailListUnsubscribeLog->setSessionOrder($order);
}
$this->em->persist($emailListUnsubscribeLog);
//$this->em->flush();
}
function checkApiDown($order)
{
if (!$this->checkOnline()) {
$this->addLogSubscribeLostLog($order);
return true;
}
return false;
}
function checkOnline()
{
$domain = $this->Activecampaign_url;
$curlInit = curl_init($domain);
curl_setopt($curlInit, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($curlInit, CURLOPT_HEADER, true);
curl_setopt($curlInit, CURLOPT_NOBODY, true);
curl_setopt($curlInit, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curlInit);
$httpCode = curl_getinfo($curlInit, CURLINFO_HTTP_CODE);
curl_close($curlInit);
return $response !== false && $httpCode >= 200 && $httpCode < 300;
}
private function buildOrderContext($order): array
{
if ($order instanceof SubscriptionOrder) {
return ['subscriptionOrder' => $order];
}
if ($order instanceof SessionOrder) {
return ['sessionOrder' => $order];
}
return [];
}
private function logFailedAction(string $action, \Throwable $e, array $context = []): void
{
$log = new EmailListActionLog();
$log->setAction($action);
$log->setLastError($e->getMessage());
if (!empty($context['subscriptionOrder'])) {
$log->setSubscriptionOrder($context['subscriptionOrder']);
}
if (!empty($context['sessionOrder'])) {
$log->setSessionOrder($context['sessionOrder']);
}
if (!empty($context['userPlacementTest'])) {
$log->setUserPlacementTest($context['userPlacementTest']);
}
if (!empty($context['session'])) {
$log->setSession($context['session']);
}
if (!empty($context['user'])) {
$log->setUser($context['user']);
}
if (!empty($context['child'])) {
$log->setChild($context['child']);
}
if (!empty($context['extraData'])) {
$log->setExtraData($context['extraData']);
}
$this->em->persist($log);
$this->em->flush();
}
public function addLogSubscribeLostLog($order)
{
//Ajouter log lors de désabonemement
$emailListSubscribeLostLog = new EmailListSubscribeLostLog();
if ($order instanceof SubscriptionOrder) {
$emailListSubscribeLostLog->setSubscriptionOrder($order);
}
if ($order instanceof SessionOrder) {
$emailListSubscribeLostLog->setSessionOrder($order);
}
$this->em->persist($emailListSubscribeLostLog);
$this->em->flush();
}
//fait par moi
public function sendTagToActiveCampaing($tag, $user, $participant)
{
if ($user != null) {
try {
$this->doSendTag($tag, $user, $participant);
return true;
} catch (\Exception $e) {
$this->logFailedAction(EmailListActionLog::ACTION_SEND_TAG, $e, [
'user' => $user,
'child' => $participant,
'extraData' => ['tag' => $tag],
]);
return false;
}
}
return false;
}
private function doSendTag($tag, $user, $participant): void
{
$lastName = $user->getLastName();
$firstName = $user->getFirstName();
$email = $user->getEmail();
$gender = $user->getGender()->getName();
$language = $user->getLanguage();
if ($participant !== null) {
$lastName = $participant->getLastName();
$firstName = $participant->getFirstName();
$gender = $participant->getGender()->getName();
}
$contact = $this->activeCampaign->updateOrCreateContact($email, $firstName, $lastName, "");
$this->activeCampaign->addTagsToContact($contact, [$tag, $gender, $language]);
}
/**
* @param SessionOrder $order
*/
function removeOrder($order)
{
try {
$this->doRemoveOrder($order);
} catch (\Exception $e) {
$this->logFailedAction(EmailListActionLog::ACTION_REMOVE, $e, $this->buildOrderContext($order));
}
}
private function doRemoveOrder($order): void
{
$contact = $this->getOrCreateContact($order);
if ($contact !== null) {
$contactID = $contact->id;
$listAndTags = $this->getListsAndTags($order);
$listsID = $this->getListIds($listAndTags);
$tags = $this->getTags($listAndTags);
$period = $order->getSession()->getPeriod();
$level = $order->getSession()->getLevel();
$subject = $level->getSubject();
$otherSessionsInfo = ['period' => 0, 'level' => 0, 'subject' => 0];
foreach ($order->getStudents()->getSessionOrder() as $sessionOrder) {
if ($sessionOrder->getIsActif()) {
if ($sessionOrder->getSession()->getPeriod() == $period) {
$otherSessionsInfo['period']++;
}
if ($sessionOrder->getSession()->getLevel() == $level) {
$otherSessionsInfo['level']++;
}
if ($sessionOrder->getSession()->getLevel()->getSubject() == $subject) {
$otherSessionsInfo['subject']++;
}
}
}
foreach ($tags as $tag) {
if ($order->getSession()->getPeriod() == $tag->tag && $otherSessionsInfo['period'] == 0) {
$this->activeCampaign->removeTagFromContact($contact, $tag);
}
if ($order->getSession()->getLevel()->getName() == $tag->tag && $otherSessionsInfo['level'] == 0) {
$this->activeCampaign->removeTagFromContact($contact, $tag);
}
if ($order->getSession()->getLevel()->getSubject() == $tag->tag && $otherSessionsInfo['subject'] == 0) {
$this->activeCampaign->removeTagFromContact($contact, $tag);
}
}
$this->updateContactLists($listsID, $contactID, false);
}
}
/**
* Trouve ou crée un contact AC, l'abonne à la liste donnée et lui ajoute le tag (créé si absent).
*
* @param SubscriptionOrder|SessionOrder $order
* @param string $tagName
* @param int $listId
* @return bool
*/
public function addCustomTagToContact($order, string $tagName, int $listId): bool
{
try {
$this->doAddCustomTagToContact($order, $tagName, $listId);
return true;
} catch (\Exception $e) {
$context = $this->buildOrderContext($order);
$context['extraData'] = ['tagName' => $tagName, 'listId' => $listId];
$this->logFailedAction(EmailListActionLog::ACTION_ADD_CUSTOM_TAG, $e, $context);
return false;
}
}
private function doAddCustomTagToContact($order, string $tagName, int $listId): void
{
$contact = $this->getOrCreateContact($order);
if ($contact === null) {
return;
}
$this->activeCampaign->updateListStatus($listId, $contact->id, true);
$tag = $this->activeCampaign->findTagList($tagName);
if ($tag !== null) {
$this->activeCampaign->addTagToContact($contact, $tag);
}
}
public function updateCustomFieldLastLevelTestForContact($contactEmail, Session $session)
{
try {
$this->doUpdateFieldLevel($contactEmail, $session);
} catch (\Exception $e) {
$this->logFailedAction(EmailListActionLog::ACTION_UPDATE_FIELD_LEVEL, $e, [
'session' => $session,
'extraData' => ['contactEmail' => $contactEmail],
]);
}
}
private function doUpdateFieldLevel(string $contactEmail, Session $session): void
{
$fieldID = null;
$fieldDateID = null;
switch ($session->getLevel()->getSubject()->getId()) {
case 1:
$fieldID = "Last Level AL KAAMIL";
$fieldDateID = "Last Level AL KAAMIL DATE";
break;
case 33:
$fieldID = "Last Level TAKALLAM";
$fieldDateID = "Last Level TAKALLAM DATE";
break;
}
$value = $session->getLevel()->getLevel();
if ($fieldID !== null) {
$contact = $this->activeCampaign->findContact($contactEmail);
if ($contact instanceof Contact) {
$customField = $this->activeCampaign->findCustomField($fieldID);
if ($customField instanceof CustomField) {
$this->activeCampaign->addCustomFieldToContact($contact, $customField, $value);
}
$customFieldDate = $this->activeCampaign->findCustomField($fieldDateID);
if ($customFieldDate instanceof CustomField) {
$this->activeCampaign->addCustomFieldToContact($contact, $customFieldDate, date('d/m/Y'));
}
}
}
}
public function updateCustomFieldLastTestResultForContact($contactEmail, UserPlacementTest $userPlacementTest)
{
try {
$this->doUpdateFieldTest($contactEmail, $userPlacementTest);
} catch (\Exception $e) {
$this->logFailedAction(EmailListActionLog::ACTION_UPDATE_FIELD_TEST, $e, [
'userPlacementTest' => $userPlacementTest,
'extraData' => ['contactEmail' => $contactEmail],
]);
}
}
private function doUpdateFieldTest(string $contactEmail, UserPlacementTest $userPlacementTest): void
{
$fieldID = null;
$fieldDateID = null;
switch ($userPlacementTest->getSubject()->getId()) {
case 1:
$fieldID = "Level Test Result AL KAAMIL";
$fieldDateID = "Last Level Test Result AL KAAMIL DATE";
break;
case 33:
$fieldID = "Level Test Result TAKALLAM";
$fieldDateID = "Last Level Test Result TAKALLAM DATE";
break;
}
if ($fieldID !== null) {
$contact = $this->activeCampaign->findContact($contactEmail);
if ($contact instanceof Contact) {
$customField = $this->activeCampaign->findCustomField($fieldID);
if ($customField instanceof CustomField) {
$this->activeCampaign->addCustomFieldToContact($contact, $customField, $userPlacementTest->getTestResult()->getLevel());
}
$customFieldDate = $this->activeCampaign->findCustomField($fieldDateID);
if ($customFieldDate instanceof CustomField) {
$this->activeCampaign->addCustomFieldToContact($contact, $customFieldDate, date('d/m/Y'));
}
}
}
}
public function addTagsForPlacementTest(array $tags, UserPlacementTest $userPlacementTest): void
{
try {
$this->doAddTagsForPlacementTest($tags, $userPlacementTest);
} catch (\Exception $e) {
$this->logFailedAction(EmailListActionLog::ACTION_ADD_TAGS_PLACEMENT, $e, [
'userPlacementTest' => $userPlacementTest,
'extraData' => ['tags' => $tags],
]);
}
}
private function doAddTagsForPlacementTest(array $tagNames, UserPlacementTest $userPlacementTest): void
{
$contact = $this->getOrCreateContact($userPlacementTest);
if ($contact !== null) {
$resolvedTags = [];
foreach ($tagNames as $tagName) {
$tag = $this->activeCampaign->findTagList($tagName);
if ($tag !== null) {
$resolvedTags[] = $tag;
}
}
$this->addTagsToContact($resolvedTags, $contact);
}
}
/**
* Exécute l'action d'un EmailListActionLog sans intercepter les exceptions.
* Utilisé par la commande de retry pour pouvoir mettre à jour l'entrée de log existante.
*
* @throws \Exception si l'action échoue ou si les données requises sont manquantes
*/
public function executeAction(EmailListActionLog $log): void
{
$action = $log->getAction();
$subscriptionOrder = $log->getSubscriptionOrder();
$sessionOrder = $log->getSessionOrder();
$order = $subscriptionOrder ?? $sessionOrder;
$extraData = $log->getExtraData() ?? [];
switch ($action) {
case EmailListActionLog::ACTION_SUBSCRIBE:
if ($order === null) {
throw new \RuntimeException('Order manquant pour action subscribe.');
}
$this->subscribeContactToLists($order);
break;
case EmailListActionLog::ACTION_UNSUBSCRIBE:
if ($order === null) {
throw new \RuntimeException('Order manquant pour action unsubscribe.');
}
$this->unsubscribeContactToLists($order);
break;
case EmailListActionLog::ACTION_REMOVE:
if ($sessionOrder === null) {
throw new \RuntimeException('SessionOrder manquant pour action remove.');
}
$this->doRemoveOrder($sessionOrder);
break;
case EmailListActionLog::ACTION_UPDATE_FIELD_LEVEL:
if ($log->getSession() === null || empty($extraData['contactEmail'])) {
throw new \RuntimeException('Session ou contactEmail manquant pour action update_field_level.');
}
$this->doUpdateFieldLevel($extraData['contactEmail'], $log->getSession());
break;
case EmailListActionLog::ACTION_UPDATE_FIELD_TEST:
if ($log->getUserPlacementTest() === null || empty($extraData['contactEmail'])) {
throw new \RuntimeException('UserPlacementTest ou contactEmail manquant pour action update_field_test.');
}
$this->doUpdateFieldTest($extraData['contactEmail'], $log->getUserPlacementTest());
break;
case EmailListActionLog::ACTION_SEND_TAG:
if ($log->getUser() === null || empty($extraData['tag'])) {
throw new \RuntimeException('User ou tag manquant pour action send_tag.');
}
$this->doSendTag($extraData['tag'], $log->getUser(), $log->getChild());
break;
case EmailListActionLog::ACTION_ADD_CUSTOM_TAG:
if ($order === null || empty($extraData['tagName']) || !isset($extraData['listId'])) {
throw new \RuntimeException('Order, tagName ou listId manquant pour action add_custom_tag.');
}
$this->doAddCustomTagToContact($order, $extraData['tagName'], (int) $extraData['listId']);
break;
case EmailListActionLog::ACTION_ADD_TAGS_PLACEMENT:
if ($log->getUserPlacementTest() === null || empty($extraData['tags'])) {
throw new \RuntimeException('UserPlacementTest ou tags manquant pour action add_tags_placement.');
}
$this->doAddTagsForPlacementTest($extraData['tags'], $log->getUserPlacementTest());
break;
default:
throw new \RuntimeException(sprintf('Action inconnue : "%s".', $action));
}
}
}