From 43f1d3359d8b29f1867e62e8eae0a17c3c72f7d1 Mon Sep 17 00:00:00 2001 From: heathdutton Date: Thu, 5 Apr 2018 11:30:12 -0400 Subject: [PATCH] [ENG-197] Only log source cost stat when accepted. --- Model/Api.php | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/Model/Api.php b/Model/Api.php index 7bb2a40..b24822d 100644 --- a/Model/Api.php +++ b/Model/Api.php @@ -74,7 +74,7 @@ class Api protected $scrubRate; /** @var int */ - protected $attribution = 0; + protected $cost = 0; /** @var string */ protected $utmSource; @@ -139,6 +139,9 @@ class Api /** @var EntityManager */ protected $em; + /** @var int */ + protected $attribution; + /** * Api constructor. * @@ -299,11 +302,13 @@ private function parseSourceCampaignSettings() ); } // Establish parameters from campaign settings. - $this->realTime = (bool) isset($campaignSettings->realTime) && $campaignSettings->realTime; - $this->limits = isset($campaignSettings->limits) ? $campaignSettings->limits : []; - $this->scrubRate = isset($campaignSettings->scrubRate) ? intval($campaignSettings->scrubRate) : 0; - $this->attribution = isset($campaignSettings->cost) ? (abs(floatval($campaignSettings->cost)) * -1) : 0; - $this->utmSource = !empty($this->contactSource->getUtmSource()) ? $this->contactSource->getUtmSource() : null; + $this->realTime = (bool) isset($campaignSettings->realTime) && $campaignSettings->realTime; + $this->limits = isset($campaignSettings->limits) ? $campaignSettings->limits : []; + $this->scrubRate = isset($campaignSettings->scrubRate) ? intval($campaignSettings->scrubRate) : 0; + $this->cost = isset($campaignSettings->cost) ? (abs(floatval($campaignSettings->cost))) : 0; + $this->utmSource = !empty( + $this->contactSource->getUtmSource() + ) ? $this->contactSource->getUtmSource() : null; // Apply field overrides if ($this->utmSource) { $this->fieldsProvided['utm_source'] = $this->utmSource; @@ -1015,7 +1020,7 @@ private function getCacheModel() */ private function saveContact() { - $exception = null; + $exception = null; $this->dispatchContextCreate(); try { $this->getContactModel()->saveEntity($this->contact); @@ -1056,7 +1061,7 @@ private function addContactToCampaign() { if ($this->contact->getId()) { // Add the contact directly to the campaign without duplicate checking. - $this->addContactsToCampaign($this->campaign, [$this->contact], false, $this->realTime); + $this->addContactsToCampaign($this->campaign, [$this->contact], false); } return $this; @@ -1068,15 +1073,13 @@ private function addContactToCampaign() * @param Campaign $campaign * @param array $contacts * @param bool $manuallyAdded - * @param bool $realTime * * @throws \Exception */ public function addContactsToCampaign( Campaign $campaign, $contacts = [], - $manuallyAdded = false, - $realTime = false + $manuallyAdded = false ) { foreach ($contacts as $contact) { $campaignContact = new CampaignContact(); @@ -1203,7 +1206,7 @@ private function processRealTime() */ private function applyAttribution() { - if (0 == $this->attribution) { + if (0 == $this->cost) { return; } @@ -1211,7 +1214,7 @@ private function applyAttribution() $this->contact = $this->getContactModel()->getEntity($this->contact->getId()); $originalAttribution = $this->contact->getAttribution(); // Attribution is always a negative number to represent cost. - $newAttribution = $originalAttribution + $this->attribution; + $newAttribution = $originalAttribution + ($this->cost * -1); if ($newAttribution != $originalAttribution) { $this->contact->addUpdatedField( 'attribution', @@ -1220,9 +1223,7 @@ private function applyAttribution() $this->dispatchContextCreate(); $this->getContactModel()->saveEntity($this->contact); } - } else { - // Since we did NOT accept the lead, invalidate attribution. - $this->attribution = 0; + $this->attribution = ($this->cost * -1); } } @@ -1250,12 +1251,10 @@ private function logResults() $sourceModel = $this->container->get('mautic.contactsource.model.contactsource'); if ($this->valid) { - $statLevel = 'INFO'; - $message = 'Contact '.$this->contact->getId( + $message = 'Contact '.$this->contact->getId( ).' was imported successfully from Campaign: '.$this->campaign->getname(); } else { - $statLevel = 'ERROR'; - $message = isset($this->errors) ? implode(PHP_EOL, $this->errors) : ''; + $message = isset($this->errors) ? implode(PHP_EOL, $this->errors) : ''; if ($this->eventErrors) { $message = implode(PHP_EOL.' ', $this->eventErrors); }