public function onLeadNewUpdate(LeadEvent $event)
 {
     $serializerGroups = array("leadDetails", "userList", "publishDetails", "ipAddress");
     $entity = $event->getLead();
     $payload = array('lead' => $entity);
     // get the leads
     if ($event->isNew()) {
         // get our new lead webhook events first
         $webhookEvents = $this->getEventWebooksByType(LeadEvents::LEAD_POST_SAVE . '_new');
         $this->webhookModel->QueueWebhooks($webhookEvents, $payload, $serializerGroups, true);
     }
     // now deal with webhooks for the update event
     if (!$event->isNew()) {
         $webhookEvents = $this->getEventWebooksByType(LeadEvents::LEAD_POST_SAVE . '_update');
         $this->webhookModel->QueueWebhooks($webhookEvents, $payload, $serializerGroups, true);
     }
 }
Exemple #2
0
 /**
  * Handle point triggers for new leads (including 0 point triggers)
  *
  * @param LeadEvent $event
  */
 public function onLeadSave(LeadEvent $event)
 {
     if ($event->isNew()) {
         /** @var \Mautic\PointBundle\Model\TriggerModel */
         $model = $this->factory->getModel('point.trigger');
         $model->triggerEvents($event->getLead());
     }
 }
Exemple #3
0
 /**
  * Add a lead entry to the audit log
  *
  * @param Events\LeadEvent $event
  */
 public function onLeadPostSave(Events\LeadEvent $event)
 {
     //Because there is an event within an event, there is a risk that something will trigger a loop which
     //needs to be prevented
     static $preventLoop = [];
     $lead = $event->getLead();
     if ($details = $event->getChanges()) {
         // Unset dateLastActive to prevent un-necessary audit log entries
         unset($details['dateLastActive']);
         if (empty($details)) {
             return;
         }
         $check = base64_encode($lead->getId() . serialize($details));
         if (!in_array($check, $preventLoop)) {
             $preventLoop[] = $check;
             $log = ["bundle" => "lead", "object" => "lead", "objectId" => $lead->getId(), "action" => $event->isNew() ? "create" : "update", "details" => $details, "ipAddress" => $this->factory->getIpAddressFromRequest()];
             $this->auditLogModel->writeToLog($log);
             if (isset($details['dateIdentified'])) {
                 //log the day lead was identified
                 $log = ["bundle" => "lead", "object" => "lead", "objectId" => $lead->getId(), "action" => "identified", "details" => [], "ipAddress" => $this->factory->getIpAddressFromRequest()];
                 $this->auditLogModel->writeToLog($log);
                 //trigger lead identified event
                 if (!$lead->imported && $this->dispatcher->hasListeners(LeadEvents::LEAD_IDENTIFIED)) {
                     $this->dispatcher->dispatch(LeadEvents::LEAD_IDENTIFIED, $event);
                 }
             }
             //add if an ip was added
             if (isset($details['ipAddresses']) && !empty($details['ipAddresses'][1])) {
                 $log = ["bundle" => "lead", "object" => "lead", "objectId" => $lead->getId(), "action" => "ipadded", "details" => $details['ipAddresses'], "ipAddress" => $this->request->server->get('REMOTE_ADDR')];
                 $this->auditLogModel->writeToLog($log);
             }
             //trigger the points change event
             if (!$lead->imported && isset($details["points"]) && (int) $details["points"][1] > 0) {
                 if (!$event->isNew() && $this->dispatcher->hasListeners(LeadEvents::LEAD_POINTS_CHANGE)) {
                     $pointsEvent = new Events\PointsChangeEvent($lead, $details['points'][0], $details['points'][1]);
                     $this->dispatcher->dispatch(LeadEvents::LEAD_POINTS_CHANGE, $pointsEvent);
                 }
             }
             if (!$lead->imported && isset($details["utmtags"])) {
                 $utmTagsEvent = new Events\LeadUtmTagsEvent($lead, $details['utmtags']);
                 $this->dispatcher->dispatch(LeadEvents::LEAD_UTMTAGS_ADD, $utmTagsEvent);
             }
         }
     }
 }
Exemple #4
0
 /**
  * Handle point triggers for new leads (including 0 point triggers).
  *
  * @param LeadEvent $event
  */
 public function onLeadSave(LeadEvent $event)
 {
     if ($event->isNew()) {
         $this->triggerModel->triggerEvents($event->getLead());
     }
 }