Skip to content

Commit

Permalink
Minor refactoring to support Servers.
Browse files Browse the repository at this point in the history
  • Loading branch information
heathdutton committed Feb 19, 2018
1 parent 09bbec1 commit 22f215e
Showing 1 changed file with 43 additions and 21 deletions.
64 changes: 43 additions & 21 deletions Integration/ClientIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 22f215e

Please sign in to comment.