diff --git a/Integration/ClientIntegration.php b/Integration/ClientIntegration.php index 8c217c65..27444394 100644 --- a/Integration/ClientIntegration.php +++ b/Integration/ClientIntegration.php @@ -49,6 +49,9 @@ class ClientIntegration extends AbstractIntegration /** @var Contact $contact The contact we wish to send and update. */ protected $contact; + /** @var array */ + protected $event; + /** @var bool $test */ protected $test = false; @@ -104,6 +107,7 @@ public function getAuthenticationType() public function pushLead($contact, $config = []) { + $this->event = $config; $config = $this->mergeConfigToFeatureSettings($config); if (empty($config['contactclient'])) { return false; @@ -185,10 +189,12 @@ private function getContactClientModel() /** * @return Container|\Symfony\Component\DependencyInjection\ContainerInterface */ - private function getContainer(){ + private function getContainer() + { if (!$this->container) { $this->container = $this->dispatcher->getContainer(); } + return $this->container; } @@ -241,7 +247,7 @@ public function sendContact( // Duplicates - Check duplicate cache to ensure we have not already sent this contact. if (!$this->test) { - $this->getCacheModel()->evaluateDuplicate(); + $this->getCacheModel()->evaluateDuplicate(); } // Exclusivity - Check exclusivity rules on the cache to ensure this contact hasn't been sent to a disallowed competitor. @@ -295,13 +301,33 @@ public function sendContact( return $this->valid; } + /** + * Get the Cache model for duplicate/exclusive/limit checking. + * + * @return Cache|object + * @throws Exception + */ + private function getCacheModel() + { + if (!$this->cacheModel) { + /** @var cacheModel $cacheModel */ + $this->cacheModel = $this->getContainer()->get('mautic.contactclient.model.cache'); + $this->cacheModel->setContact($this->contact); + $this->cacheModel->setContactClient($this->contactClient); + } + + return $this->cacheModel; + } + /** * @return ApiPayload */ - private function getApiPayloadModel(){ + private function getApiPayloadModel() + { if (!$this->payload) { $this->payload = $this->getContainer()->get('mautic.contactclient.model.apipayload'); } + return $this->payload; } @@ -377,24 +403,6 @@ private function createCache() } } - /** - * Get the Cache model for duplicate/exclusive/limit checking. - * - * @return Cache|object - * @throws Exception - */ - private function getCacheModel() - { - if (!$this->cacheModel) { - /** @var cacheModel $cacheModel */ - $this->cacheModel = $this->getContainer()->get('mautic.contactclient.model.cache'); - $this->cacheModel->setContact($this->contact); - $this->cacheModel->setContactClient($this->contactClient); - } - - return $this->cacheModel; - } - /** * Log to: * contactclient_stats @@ -447,6 +455,20 @@ private function logResults() } } + // Session storage for external plugins (should probably be dispatcher instead). + $session = $this->dispatcher->getContainer()->get('session'); + $eventId = isset($this->event['id']) ? $this->event['id'] : 0; + $events = $session->get('contactclient_events', []); + $events[$eventId] = array_merge($this->event, [ + 'valid' => $this->valid, + 'statType' => $statType, + ]); + $session->set('contactclient_events', $events); + // Indicates that a single (or more) valid sends have been made. + if ($this->valid) { + $session->set('contactclient_valid', true); + } + // Add log entry for statistics / charts. $attribution = !empty($this->logs['attribution']) ? $this->logs['attribution'] : 0; $clientModel->addStat($this->contactClient, $statType, $this->contact, $attribution);