Skip to content

Commit

Permalink
Added support for max repeat restart campaign
Browse files Browse the repository at this point in the history
  • Loading branch information
kuzmany committed Jul 4, 2018
1 parent 75eaeb2 commit 9536466
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 4 deletions.
1 change: 1 addition & 0 deletions Config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
'mautic.helper.integration',
'doctrine.dbal.default_connection',
'mautic.campaign.model.campaign',
'mautic.campaign.model.event',
],
],
],
Expand Down
35 changes: 31 additions & 4 deletions EventListener/CampaignSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@

use Doctrine\DBAL\Connection;
use Mautic\CampaignBundle\CampaignEvents;
use Mautic\CampaignBundle\Entity\Event;
use Mautic\CampaignBundle\Event\CampaignBuilderEvent;
use Mautic\CampaignBundle\Event\CampaignExecutionEvent;
use Mautic\CampaignBundle\Model\CampaignModel;
use Mautic\CampaignBundle\Model\EventModel;
use Mautic\CoreBundle\EventListener\CommonSubscriber;
use Mautic\PluginBundle\Helper\IntegrationHelper;
use MauticPlugin\MauticRecurringCampaignsBundle\RecurringCampaignsEvents;
Expand All @@ -37,17 +39,27 @@ class CampaignSubscriber extends CommonSubscriber
*/
protected $campaignModel;

/**
* @var EventModel
*/
private $eventModel;

/**
* ButtonSubscriber constructor.
*
* @param IntegrationHelper $helper
* @param Connection $db
* @param IntegrationHelper $integrationHelper
* @param Connection $db
* @param CampaignModel $campaignModel
* @param EventModel $eventModel
*
* @internal param IntegrationHelper $helper
*/
public function __construct(IntegrationHelper $integrationHelper, Connection $db, CampaignModel $campaignModel)
public function __construct(IntegrationHelper $integrationHelper, Connection $db, CampaignModel $campaignModel, EventModel $eventModel)
{
$this->integrationHelper = $integrationHelper;
$this->db = $db;
$this->campaignModel = $campaignModel;
$this->eventModel = $eventModel;
}

/**
Expand Down Expand Up @@ -99,8 +111,23 @@ public function onCampaignTriggerAction(CampaignExecutionEvent $event)

$lead = $event->getLead();
$campaigns = $event->getConfig()['campaigns'];

$limit = $event->getConfig()['limit'];
$qb = $this->db;

$properties = $event->getEvent()['properties'];
/** @var Event $event */
$eventEntity = $this->eventModel->getEntity($event->getEvent()['id']);
$numberOfRotation = isset($properties['numberOfRotation']) ? $properties['numberOfRotation'] : 0;

// return true if max execution
if (!empty($limit) && $numberOfRotation >= $limit) {
return $event->setResult(true);
}

$properties['numberOfRotation'] = $numberOfRotation + 1;
$eventEntity->setProperties($properties);
$this->eventModel->saveEntity($eventEntity);

foreach ($campaigns as $campaignId) {
if(!empty($event->getConfig()['action'])){
$qb->delete(
Expand Down
15 changes: 15 additions & 0 deletions Form/Type/CampaignEventRemoveLogsActionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace MauticPlugin\MauticRecurringCampaignsBundle\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints\NotBlank;
/**
Expand Down Expand Up @@ -43,6 +44,20 @@ public function buildForm(FormBuilderInterface $builder, array $options)
],
]);

$builder->add(
'limit',
NumberType::class,
[
'label' => 'plugin.recurring.campaigns.campaign.execute.limit',
'label_attr' => ['class' => 'control-label'],
'attr'=> [
'class' => 'form-control',
'tooltip'=>'plugin.recurring.campaigns.campaign.execute.limit.desc'
],
'data' => !empty($options['data']['limit']) ? $options['data']['limit'] : 0,
]
);

$builder->add(
'action',
'yesno_button_group',
Expand Down
2 changes: 2 additions & 0 deletions Translations/en_US/messages.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ plugin.recurring.campaigns.campaign.remove.scheduled="Remove just scheduled cont
plugin.recurring.campaigns.campaign.remove.scheduled.desc="If disabled, all contacts logs will remove"
plugin.recurring.campaigns.campaign.remove.from="After remove logs remove contact from selected campaigns"
plugin.recurring.campaigns.campaign.remove.from.desc="Contact will remove also from selected campaigsn after"
plugin.recurring.campaigns.campaign.execute.limit="Max event execution"
plugin.recurring.campaigns.campaign.execute.limit.desc="Set max time of remove logs campaigns. Unlimited is zero"


0 comments on commit 9536466

Please sign in to comment.