Initial commit: CloudOps infrastructure platform
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Mautic\CampaignBundle\Helper;
|
||||
|
||||
use Mautic\CoreBundle\Helper\CoreParametersHelper;
|
||||
|
||||
final class CampaignConfig
|
||||
{
|
||||
public function __construct(private CoreParametersHelper $coreParametersHelper)
|
||||
{
|
||||
}
|
||||
|
||||
public function shouldDeleteEventLogInBackground(): bool
|
||||
{
|
||||
return (bool) $this->coreParametersHelper->get('delete_campaign_event_log_in_background', false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Mautic\CampaignBundle\Helper;
|
||||
|
||||
use Mautic\CampaignBundle\Event\CampaignLeadChangeEvent;
|
||||
|
||||
class CampaignEventHelper
|
||||
{
|
||||
/**
|
||||
* Determine if this campaign applies.
|
||||
*/
|
||||
public static function validateLeadChangeTrigger(?CampaignLeadChangeEvent $eventDetails = null, array $event = []): bool
|
||||
{
|
||||
if (null == $eventDetails) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$limitToCampaigns = $event['properties']['campaigns'];
|
||||
$action = $event['properties']['action'];
|
||||
|
||||
// check against selected campaigns
|
||||
if (!empty($limitToCampaigns) && !in_array($event['campaign']['id'], $limitToCampaigns)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// check against the selected action (was lead removed or added)
|
||||
$func = 'was'.ucfirst($action);
|
||||
if (!method_exists($eventDetails, $func) || !$eventDetails->$func()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace Mautic\CampaignBundle\Helper;
|
||||
|
||||
use Mautic\CampaignBundle\Entity\ChannelInterface;
|
||||
use Mautic\CampaignBundle\Entity\Event;
|
||||
use Mautic\CampaignBundle\EventCollector\Accessor\Event\AbstractEventAccessor;
|
||||
|
||||
class ChannelExtractor
|
||||
{
|
||||
public static function setChannel(ChannelInterface $entity, Event $event, AbstractEventAccessor $eventConfig): void
|
||||
{
|
||||
// Allow event to update itself
|
||||
$isSelf = $entity === $event;
|
||||
|
||||
if (!$isSelf && $entity->getChannel()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$channel = $eventConfig->getChannel()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$entity->setChannel($channel);
|
||||
|
||||
if (!$channelIdField = $eventConfig->getChannelIdField()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$event->getProperties()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$entity->setChannelId(
|
||||
self::getChannelId($event->getProperties(), $channelIdField)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $channelIdField
|
||||
*/
|
||||
private static function getChannelId(array $properties, $channelIdField): ?int
|
||||
{
|
||||
if (empty($properties[$channelIdField])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$channelId = $properties[$channelIdField];
|
||||
if (is_array($channelId) && (1 === count($channelId))) {
|
||||
// Only store channel ID if a single item was selected
|
||||
$channelId = reset($channelId);
|
||||
}
|
||||
|
||||
if (!is_numeric($channelId)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (int) $channelId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace Mautic\CampaignBundle\Helper;
|
||||
|
||||
class RemovedContactTracker
|
||||
{
|
||||
private array $removedContacts = [];
|
||||
|
||||
/**
|
||||
* @param int $campaignId
|
||||
* @param int $contactId
|
||||
*/
|
||||
public function addRemovedContact($campaignId, $contactId): void
|
||||
{
|
||||
if (!isset($this->removedContacts[$campaignId])) {
|
||||
$this->removedContacts[$campaignId] = [];
|
||||
}
|
||||
|
||||
$this->removedContacts[$campaignId][$contactId] = $contactId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $campaignId
|
||||
*/
|
||||
public function addRemovedContacts($campaignId, array $contactIds): void
|
||||
{
|
||||
foreach ($contactIds as $contactId) {
|
||||
$this->addRemovedContact($campaignId, $contactId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $campaignId
|
||||
*/
|
||||
public function clearRemovedContact($campaignId, $contactId): void
|
||||
{
|
||||
unset($this->removedContacts[$campaignId][$contactId]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $campaignId
|
||||
*/
|
||||
public function wasContactRemoved($campaignId, $contactId): bool
|
||||
{
|
||||
return !empty($this->removedContacts[$campaignId][$contactId]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getRemovedContacts()
|
||||
{
|
||||
return $this->removedContacts;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user