Ejemplo n.º 1
0
 /**
  * @param        $email
  * @param string $reason
  * @param bool   $flush
  */
 public function setBounceDoNotContact($email, $reason = '', $flush = true)
 {
     $repo = $this->getRepository();
     if (!$repo->checkDoNotEmail($email)) {
         $dnc = new DoNotEmail();
         $dnc->setEmailAddress($email);
         $dnc->setDateAdded(new \DateTime());
         $dnc->setBounced();
         $dnc->setComments($reason);
         $em = $this->factory->getEntityManager();
         $em->persist($dnc);
         if ($flush) {
             $em->flush();
         }
     }
 }
 /**
  * {@inheritDoc}
  */
 public function setManual($manual = true)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'setManual', array($manual));
     return parent::setManual($manual);
 }
Ejemplo n.º 3
0
 /**
  * Add a do not contact entry for the lead
  *
  * @param Lead       $lead
  * @param string     $emailAddress
  * @param string     $reason
  * @param bool|true  $persist
  * @param bool|false $manual
  *
  * @return DoNotEmail|bool
  * @throws \Doctrine\DBAL\DBALException
  */
 public function setDoNotContact(Lead $lead, $emailAddress = '', $reason = '', $persist = true, $manual = false)
 {
     if (empty($emailAddress)) {
         $emailAddress = $lead->getEmail();
         if (empty($emailAddress)) {
             return false;
         }
     }
     $em = $this->factory->getEntityManager();
     $repo = $em->getRepository('MauticEmailBundle:Email');
     if (!$repo->checkDoNotEmail($emailAddress)) {
         $dnc = new DoNotEmail();
         $dnc->setLead($lead);
         $dnc->setEmailAddress($emailAddress);
         $dnc->setDateAdded(new \DateTime());
         $dnc->setUnsubscribed();
         $dnc->setManual($manual);
         $dnc->setComments($reason);
         if ($persist) {
             $repo->saveEntity($dnc);
         } else {
             $lead->addDoNotEmailEntry($dnc);
             return $dnc;
         }
     }
     return false;
 }
Ejemplo n.º 4
0
 /**
  * @param           $email
  * @param string    $tag
  * @param string    $reason
  * @param bool|true $flush
  * @param int|null  $leadId
  */
 public function setEmailDoNotContact($email, $tag = 'bounced', $reason = '', $flush = true, $leadId = null)
 {
     $repo = $this->getRepository();
     $dnc = $repo->checkDoNotEmail($email);
     if (false === $dnc) {
         if (null == $leadId) {
             // Check to see if a lead exists with this email
             /** @var \Mautic\LeadBundle\Model\LeadModel $leadModel */
             $leadModel = $this->factory->getModel('lead');
             $leadRepo = $leadModel->getRepository();
             $foundLead = $leadRepo->getLeadByEmail($email);
             $lead = null !== $foundLead ? $this->em->getReference('MauticLeadBundle:Lead', $foundLead['id']) : null;
         } else {
             $lead = $this->em->getReference('MauticLeadBundle:Lead', $leadId);
         }
         $dnc = new DoNotEmail();
         $dnc->setEmailAddress($email);
         $dnc->setLead($lead);
         $dnc->setDateAdded(new \DateTime());
         $method = 'set' . ucfirst($tag);
         if (method_exists($dnc, $method)) {
             $method = 'setBounced';
         }
         $dnc->{$method}();
         $dnc->setComments($reason);
         $this->em->persist($dnc);
         if ($flush) {
             $this->em->flush($dnc);
         }
     } elseif ($dnc['bounced']) {
         // Update the entry
         /** @var \Mautic\EmailBundle\Entity\DoNotEmail $dncEntity */
         $dncEntity = $this->em->getReference('MauticEmailBundle:DoNotEmail', $dnc['id']);
         if ('unsubscribed' == $tag) {
             // Unsubscribe user so they cannot be contacted
             $dncEntity->setBounced(false);
             $dncEntity->setUnsubscribed(true);
         }
         if (null !== $leadId) {
             $dncEntity->setLead($this->em->getReference('MauticLeadBundle:Lead', $leadId));
         }
         $dncEntity->setDateAdded(new \DateTime());
         $dncEntity->setComments($reason);
         $this->em->persist($dncEntity);
         if ($flush) {
             $this->em->flush($dncEntity);
         }
     }
 }
Ejemplo n.º 5
0
 /**
  * Add a do not contact entry for the lead
  *
  * @param Lead   $lead
  * @param string $emailAddress
  * @param string $reason
  * @param bool   $persist
  */
 public function setDoNotContact(Lead $lead, $emailAddress = '', $reason = '', $persist = true)
 {
     if (empty($emailAddress)) {
         $fields = $lead->getFields();
         $emailAddress = $fields['core']['email']['value'];
         if (empty($emailAddress)) {
             return;
         }
     }
     $em = $this->factory->getEntityManager();
     $repo = $em->getRepository('MauticEmailBundle:Email');
     if (!$repo->checkDoNotEmail($emailAddress)) {
         $dnc = new DoNotEmail();
         $dnc->setLead($lead);
         $dnc->setEmailAddress($emailAddress);
         $dnc->setDateAdded(new \DateTime());
         $dnc->setUnsubscribed();
         $dnc->setComments($reason);
         if ($persist) {
             $repo->saveEntity($dnc);
         } else {
             return $dnc;
         }
     }
 }
Ejemplo n.º 6
0
 /**
  * @param DoNotEmail $doNotEmail
  */
 public function removeDoNotEmailEntry(DoNotEmail $doNotEmail)
 {
     if ($doNotEmail->getBounced()) {
         $type = $doNotEmail->isManual() ? 'manual' : 'bounced';
     } elseif ($doNotEmail->getUnsubscribed()) {
         $type = 'unsubscribed';
     }
     $this->changes['dnc_status'] = array('removed', $type);
     $this->doNotEmail->removeElement($doNotEmail);
 }