Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

M2 Fix sent email point actions issues (8619) #57

Open
wants to merge 6 commits into
base: mautic-2-16-2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions app/bundles/EmailBundle/EventListener/PointSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Mautic\EmailBundle\Event\EmailOpenEvent;
use Mautic\EmailBundle\Event\EmailSendEvent;
use Mautic\EmailBundle\Form\Type\EmailToUserType;
use Mautic\LeadBundle\Entity\Lead;
use Mautic\PointBundle\Event\PointBuilderEvent;
use Mautic\PointBundle\Event\TriggerBuilderEvent;
use Mautic\PointBundle\Model\PointModel;
Expand All @@ -31,6 +32,11 @@ class PointSubscriber extends CommonSubscriber
*/
protected $pointModel;

/**
* @var array
*/
private $triggered = [];

/**
* PointSubscriber constructor.
*
Expand Down Expand Up @@ -123,12 +129,34 @@ public function onEmailOpen(EmailOpenEvent $event)
*/
public function onEmailSend(EmailSendEvent $event)
{
if ($leadArray = $event->getLead()) {
$leadArray = $event->getLead();
if ($leadArray && is_array($leadArray) && !empty($leadArray['id'])) {
$lead = $this->em->getReference('MauticLeadBundle:Lead', $leadArray['id']);
} else {
return;
}

$this->pointModel->triggerAction('email.send', $event->getEmail(), null, $lead);
if ($this->shouldTriggerPointEmailSendAction($event, $lead)) {
$this->pointModel->triggerAction('email.send', $event->getEmail(), null, $lead, true);
}
}

/**
* @param EmailSendEvent $event
* @param Lead $lead
*
* @return bool
*/
private function shouldTriggerPointEmailSendAction(EmailSendEvent $event, Lead $lead)
{
if ($event->getEmail()) {
if (!isset($this->triggered[$lead->getId()][$event->getEmail()->getId()])) {
$this->triggered[$lead->getId()][$event->getEmail()->getId()] = true;

return true;
}
}

return false;
}
}
3 changes: 2 additions & 1 deletion app/bundles/EmailBundle/Form/Type/EmailOpenType.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public function buildForm(FormBuilderInterface $builder, array $options)
'class' => 'form-control',
'tooltip' => 'mautic.email.open.limittoemails_descr',
],
'required' => false,
'required' => false,
'email_type' => null,
];

if (isset($options['list_options'])) {
Expand Down
13 changes: 8 additions & 5 deletions app/bundles/PointBundle/Model/PointModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,17 @@ public function getPointActions()
* Triggers a specific point change.
*
* @param $type
* @param mixed $eventDetails passthrough from function triggering action to the callback function
* @param mixed $typeId Something unique to the triggering event to prevent unnecessary duplicate calls
* @param mixed $eventDetails passthrough from function triggering action to the callback function
* @param mixed $typeId Something unique to the triggering event to prevent unnecessary duplicate calls
* @param Lead $lead
* @param bool $allowUserRequest
*
* @throws \ReflectionException
*/
public function triggerAction($type, $eventDetails = null, $typeId = null, Lead $lead = null)
public function triggerAction($type, $eventDetails = null, $typeId = null, Lead $lead = null, $allowUserRequest = false)
{
//only trigger actions for anonymous users
if (!$this->security->isAnonymous()) {
//only trigger actions for not logged Mautic users
if (!$this->security->isAnonymous() && !$allowUserRequest) {
return;
}

Expand Down