Skip to content

Commit

Permalink
Remove dwc session, add cache (mautic#13464)
Browse files Browse the repository at this point in the history
* MAUT-3358 / Remove session, add cache

* fixed conflits, code style

* hopefully resolved conflicts with parent

---------

Co-authored-by: Lukas Sykora <[email protected]>
Co-authored-by: John Linhart <[email protected]>
  • Loading branch information
3 people authored Apr 18, 2024
1 parent 34ffbe1 commit 175ceac
Showing 1 changed file with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Mautic\DynamicContentBundle\EventListener;

use Mautic\CacheBundle\Cache\CacheProvider;
use Mautic\CampaignBundle\CampaignEvents;
use Mautic\CampaignBundle\Event\CampaignBuilderEvent;
use Mautic\CampaignBundle\Event\CampaignExecutionEvent;
Expand All @@ -11,15 +12,16 @@
use Mautic\DynamicContentBundle\Form\Type\DynamicContentDecisionType;
use Mautic\DynamicContentBundle\Form\Type\DynamicContentSendType;
use Mautic\DynamicContentBundle\Model\DynamicContentModel;
use Psr\Cache\CacheItemInterface;
use Psr\Cache\InvalidArgumentException;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Session\SessionInterface;

class CampaignSubscriber implements EventSubscriberInterface
{
public function __construct(
private DynamicContentModel $dynamicContentModel,
private SessionInterface $session,
protected CacheProvider $cache,
private EventDispatcherInterface $dispatcher
) {
}
Expand Down Expand Up @@ -77,7 +79,9 @@ public function onCampaignBuild(CampaignBuilderEvent $event): void
}

/**
* @return bool|CampaignExecutionEvent
* @return false|CampaignExecutionEvent
*
* @throws InvalidArgumentException
*/
public function onCampaignTriggerDecision(CampaignExecutionEvent $event)
{
Expand All @@ -99,7 +103,11 @@ public function onCampaignTriggerDecision(CampaignExecutionEvent $event)
$this->dynamicContentModel->setSlotContentForLead($defaultDwc, $lead, $eventDetails);
}

$this->session->set('dwc.slot_name.lead.'.$lead->getId(), $eventDetails);
/** @var CacheItemInterface $item */
$item = $this->cache->getItem('dwc.slot_name.lead.'.$lead->getId());
$item->set($eventDetails);
$item->expiresAfter(86400); // one day in seconds
$this->cache->save($item);

$event->stopPropagation();

Expand All @@ -110,7 +118,9 @@ public function onCampaignTriggerAction(CampaignExecutionEvent $event)
{
$eventConfig = $event->getConfig();
$lead = $event->getLead();
$slot = $this->session->get('dwc.slot_name.lead.'.$lead->getId());
/* @var CacheItemInterface $item */
$item = $this->cache->getItem('dwc.slot_name.lead.'.$lead->getId());
$slot = $item->get();

$dwc = $this->dynamicContentModel->getRepository()->getEntity($eventConfig['dynamicContent']);

Expand Down

0 comments on commit 175ceac

Please sign in to comment.