コード例 #1
0
ファイル: EmailOpenEvent.php プロジェクト: Yame-/mautic
 /**
  * @param Email $email
  */
 public function __construct(Stat $stat, $request, $firstTime = false)
 {
     $this->entity = $stat;
     $this->email = $stat->getEmail();
     $this->request = $request;
     $this->firstTime = $firstTime;
 }
コード例 #2
0
ファイル: EmailModel.php プロジェクト: smotalima/mautic
 /**
  * @param Stat   $stat
  * @param        $reason
  * @param string $tag
  * @param bool   $flush
  */
 public function setDoNotContact(Stat $stat, $reason, $tag = 'bounced', $flush = true)
 {
     $lead = $stat->getLead();
     $email = $stat->getEmail();
     $address = $stat->getEmailAddress();
     $repo = $this->getRepository();
     if (!$repo->checkDoNotEmail($address)) {
         $dnc = new DoNotEmail();
         if ($email != null) {
             $dnc->setEmail($email);
         }
         $dnc->setLead($lead);
         $dnc->setEmailAddress($address);
         $dnc->setDateAdded(new \DateTime());
         $dnc->{"set" . ucfirst($tag)}();
         $dnc->setComments($reason);
         $em = $this->factory->getEntityManager();
         $em->persist($dnc);
         if ($flush) {
             $em->flush();
         }
     }
 }
コード例 #3
0
ファイル: MailHelper.php プロジェクト: emtudo/mautic
 /**
  * Create an email stat
  *
  * @param bool|true   $persist
  * @param string|null $emailAddress
  * @param null        $listId
  *
  * @return Stat|void
  * @throws \Doctrine\ORM\ORMException
  */
 public function createEmailStat($persist = true, $emailAddress = null, $listId = null)
 {
     static $copies = array();
     //create a stat
     $stat = new Stat();
     $stat->setDateSent(new \DateTime());
     $stat->setEmail($this->email);
     // Note if a lead
     if (null !== $this->lead) {
         $stat->setLead($this->factory->getEntityManager()->getReference('MauticLeadBundle:Lead', $this->lead['id']));
         $emailAddress = $this->lead['email'];
     }
     // Find email if applicable
     if (null === $emailAddress) {
         // Use the last address set
         $emailAddresses = $this->message->getTo();
         if (count($emailAddresses)) {
             end($emailAddresses);
             $emailAddress = key($emailAddresses);
         }
     }
     $stat->setEmailAddress($emailAddress);
     // Note if sent from a lead list
     if (null !== $listId) {
         $stat->setList($this->factory->getEntityManager()->getReference('MauticLeadBundle:LeadList', $listId));
     }
     $stat->setTrackingHash($this->idHash);
     if (!empty($this->source)) {
         $stat->setSource($this->source[0]);
         $stat->setSourceId($this->source[1]);
     }
     $stat->setTokens($this->getTokens());
     /** @var \Mautic\EmailBundle\Model\EmailModel $emailModel */
     $emailModel = $this->factory->getModel('email');
     // Save a copy of the email - use email ID if available simply to prevent from having to rehash over and over
     $id = null !== $this->email ? $this->email->getId() : md5($this->subject . $this->body['content']);
     if (!isset($copies[$id])) {
         $hash = strlen($id) !== 32 ? md5($this->subject . $this->body['content']) : $id;
         $copy = $emailModel->getCopyRepository()->findByHash($hash);
         if (null === $copy) {
             // Create a copy entry
             $copy = new Copy();
             $copy->setId($hash)->setBody($this->body['content'])->setSubject($this->subject)->setDateCreated(new \DateTime())->setEmail($this->email);
             $emailModel->getCopyRepository()->saveEntity($copy);
         }
         $copies[$id] = $copy;
     }
     $stat->setStoredCopy($copies[$id]);
     if ($persist) {
         $emailModel->getStatRepository()->saveEntity($stat);
     }
     return $stat;
 }
コード例 #4
0
ファイル: EmailModelTest.php プロジェクト: dongilbert/mautic
 /**
  * Test that processMailerCallback handles an array of hashIds correctly.
  */
 public function testProcessMailerCallbackWithHashIds()
 {
     // Setup dependencies
     $ipLookupHelper = $this->getMockBuilder(IpLookupHelper::class)->disableOriginalConstructor()->getMock();
     $themeHelper = $this->getMockBuilder(ThemeHelper::class)->disableOriginalConstructor()->getMock();
     $mailboxHelper = $this->getMockBuilder(Mailbox::class)->disableOriginalConstructor()->getMock();
     $mailHelper = $this->getMockBuilder(MailHelper::class)->disableOriginalConstructor()->getMock();
     $leadModel = $this->getMockBuilder(LeadModel::class)->disableOriginalConstructor()->getMock();
     $trackableModel = $this->getMockBuilder(TrackableModel::class)->disableOriginalConstructor()->getMock();
     $userModel = $this->getMockBuilder(UserModel::class)->disableOriginalConstructor()->getMock();
     $coreParametersHelper = $this->getMockBuilder(CoreParametersHelper::class)->disableOriginalConstructor()->getMock();
     // Setup the translator
     $translator = $this->getMockBuilder(Translator::class)->disableOriginalConstructor()->getMock();
     $translator->expects($this->any())->method('has')->will($this->returnValue(false));
     // Setup the StatRepository
     $statRepository = $this->getMockBuilder(StatRepository::class)->disableOriginalConstructor()->getMock();
     $statRepository->expects($this->once())->method('getTableAlias')->will($this->returnValue('s'));
     $leadEntity = $this->getMockBuilder(Lead::class)->disableOriginalConstructor()->getMock();
     $leadEntity->expects($this->any())->method('getId')->will($this->returnValue(1));
     $emailEntity = $this->getMockBuilder(Email::class)->disableOriginalConstructor()->getMock();
     $emailEntity->expects($this->any())->method('getId')->will($this->returnValue(1));
     $statEntity = new Stat();
     $statEntity->setTrackingHash('xyz123');
     $statEntity->setLead($leadEntity);
     $statEntity->setEmail($emailEntity);
     $statRepository->expects($this->any())->method('getEntities')->will($this->returnValue([$statEntity]));
     // Setup the EntityManager
     $entityManager = $this->getMockBuilder(EntityManager::class)->disableOriginalConstructor()->getMock();
     $entityManager->expects($this->any())->method('getRepository')->will($this->returnValueMap([['MauticEmailBundle:Stat', $statRepository]]));
     $entityManager->expects($this->any())->method('getReference')->will($this->returnValue($leadEntity));
     $messageModel = $this->getMockBuilder(MessageQueueModel::class)->disableOriginalConstructor()->getMock();
     $companyModel = $this->getMockBuilder(CompanyModel::class)->disableOriginalConstructor()->getMock();
     $companyRepository = $this->getMockBuilder(CompanyRepository::class)->disableOriginalConstructor()->getMock();
     $companyRepository->method('getCompaniesForContacts')->will($this->returnValue([]));
     $companyModel->method('getRepository')->willReturn($companyRepository);
     $emailModel = new \Mautic\EmailBundle\Model\EmailModel($ipLookupHelper, $themeHelper, $mailboxHelper, $mailHelper, $leadModel, $companyModel, $trackableModel, $userModel, $coreParametersHelper, $messageModel);
     $emailModel->setTranslator($translator);
     $emailModel->setEntityManager($entityManager);
     $response = [2 => ['hashIds' => ['xyz123' => 'some reason', '123xyz' => 'some reason']]];
     $dnc = $emailModel->processMailerCallback($response);
     $this->assertCount(1, $dnc);
 }
コード例 #5
0
ファイル: EmailModel.php プロジェクト: Yame-/mautic
 /**
  * @param Stat $stat
  * @param      $comments
  * @param int  $reason
  * @param bool $flush
  *
  * @return bool|DoNotContact
  */
 public function setDoNotContact(Stat $stat, $comments, $reason = DoNotContact::BOUNCED, $flush = true)
 {
     $lead = $stat->getLead();
     if ($lead instanceof Lead) {
         $email = $stat->getEmail();
         $channel = $email ? ['email' => $email->getId()] : 'email';
         return $this->leadModel->addDncForLead($lead, $channel, $comments, $reason, $flush);
     }
     return false;
 }
コード例 #6
0
ファイル: EmailModel.php プロジェクト: HomeRefill/mautic
 /**
  * @param Stat   $stat
  * @param string $comments
  * @param string $reason
  * @param bool   $flush
  */
 public function setDoNotContact(Stat $stat, $comments, $reason = 'bounced', $flush = true)
 {
     $lead = $stat->getLead();
     if ($lead instanceof Lead) {
         /** @var \Mautic\LeadBundle\Model\LeadModel $leadModel */
         $leadModel = $this->factory->getModel('lead.lead');
         $email = $stat->getEmail();
         $channel = $email ? array('email' => $email->getId()) : 'email';
         $leadModel->addDncForLead($lead, $channel, $comments, $reason, $flush);
     }
 }
コード例 #7
0
ファイル: MailHelper.php プロジェクト: Jandersolutions/mautic
 /**
  * Create an email stat
  */
 public function createLeadEmailStat()
 {
     if (!$this->lead) {
         return;
     }
     //create a stat
     $stat = new Stat();
     $stat->setDateSent(new \DateTime());
     $stat->setEmail($this->email);
     $stat->setLead($this->factory->getEntityManager()->getReference('MauticLeadBundle:Lead', $this->lead['id']));
     $stat->setEmailAddress($this->lead['email']);
     $stat->setTrackingHash($this->idHash);
     if (!empty($this->source)) {
         $stat->setSource($this->source[0]);
         $stat->setSourceId($this->source[1]);
     }
     $stat->setCopy($this->getBody());
     $stat->setTokens($this->getTokens());
     /** @var \Mautic\EmailBundle\Model\EmailModel $emailModel */
     $emailModel = $this->factory->getModel('email');
     $emailModel->getStatRepository()->saveEntity($stat);
 }
コード例 #8
0
 /**
  * @param Email $email
  */
 public function __construct(Stat $stat, $request)
 {
     $this->entity = $stat;
     $this->email = $stat->getEmail();
     $this->request = $request;
 }
コード例 #9
0
 /**
  * {@inheritDoc}
  */
 public function setOpenDetails($openDetails)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'setOpenDetails', array($openDetails));
     return parent::setOpenDetails($openDetails);
 }
コード例 #10
0
 /**
  * {@inheritDoc}
  */
 public function setStoredCopy(\Mautic\EmailBundle\Entity\Copy $storedCopy)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'setStoredCopy', array($storedCopy));
     return parent::setStoredCopy($storedCopy);
 }