Skip to content

Commit

Permalink
Merge pull request #26 from TheDMSGroup/ENG-191
Browse files Browse the repository at this point in the history
[ENG-191] Hardening around enhancers.
  • Loading branch information
heathdutton authored Apr 3, 2018
2 parents 44f1fb0 + 6c3ce6b commit aa8baa6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 28 deletions.
23 changes: 12 additions & 11 deletions Integration/AlcazarIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ protected function getEnhancerFieldArray()
{
$field_list = [
'alcazar_lrn' => [
'label' => 'LRN',
'label' => 'LRN',
],
];

Expand All @@ -165,31 +165,31 @@ private function getAlcazarExtendedFields()
{
return [
'alcazar_spid' => [
'label' => 'Alcazar SPID',
'label' => 'Alcazar SPID',
],
'alcazar_ocn' => [
'label' => 'Alcazar OCN',
'label' => 'Alcazar OCN',
],
'alcazar_lata' => [
'label' => 'Alcazar LATA',
'label' => 'Alcazar LATA',
],
'alcazar_city' => [
'label' => 'Alcazar City',
'label' => 'Alcazar City',
],
'alcazar_state' => [
'label' => 'Alcazar State',
'label' => 'Alcazar State',
],
'alcazar_lec' => [
'label' => 'Alcazar LEC',
'label' => 'Alcazar LEC',
],
'alcazar_linetype' => [
'label' => 'Alcazar Line Type',
'label' => 'Alcazar Line Type',
],
'alcazar_dnc' => [
'label' => 'Alcazar DNC',
'label' => 'Alcazar DNC',
],
'alcazar_jurisdiction' => [
'label' => 'Alcazar Jurisdiction',
'label' => 'Alcazar Jurisdiction',
],
];
}
Expand All @@ -207,11 +207,12 @@ public function doEnhancement(Lead &$lead)
}

$phone = $lead->getPhone();
$phone = preg_replace('/[^0-9]/', '', $phone);
if (10 === strlen($phone)) {
$phone = '1'.$phone;
}
if (11 !== strlen($phone)) {
return false;
return;
}

$keys = $this->getKeys();
Expand Down
10 changes: 5 additions & 5 deletions Integration/FourleafIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,13 @@ public function doEnhancement(Lead &$lead)

$this->applyCost($lead);

$allowedAliases = $this->getEnhancerFieldArray();
foreach ($response as $key => $value) {
if ('md5' === $key) {
continue;
}
$alias = 'fourleaf_'.str_replace('user_', '', $key);
$default = $lead->getFieldValue($alias);
$lead->addUpdatedField($alias, $value, $default);
if (isset($allowedAliases[$alias])) {
$default = $lead->getFieldValue($alias);
$lead->addUpdatedField($alias, $value, $default);
}
}
$this->saveLead($lead);
}
Expand Down
2 changes: 1 addition & 1 deletion Integration/RandomIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function doEnhancement(Lead &$lead)
$settings = $this->getIntegrationSettings()->getFeatureSettings();

if (!$lead->getFieldValue($settings['random_field_name'])) {
$lead->{$settings['random_field_name']} = rand(1, 101);
$lead->addUpdatedField($settings['random_field_name'], rand(1, 100));
}
}
}
Expand Down
15 changes: 4 additions & 11 deletions Integration/XverifyIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public function doEnhancement(Lead &$lead)
$response = $status = $service = $fieldKey = null;
$fieldToUpdate = $integrationFieldName.'_valid'; //which validation field will we update?
try {
$fieldValue = $lead->$mauticFieldName;
$fieldValue = $lead->getFieldValue($mauticFieldName);
if (!empty($fieldValue)) {
switch ($integrationFieldName) {
case 'cellphone':
Expand All @@ -157,7 +157,7 @@ public function doEnhancement(Lead &$lead)
// phone API call
$service = 'phone';
$fieldKey = 'phone';
if (is_null($lead->$fieldToUpdate)) { // only if we havent checked already
if (is_null($lead->getFieldValue($fieldToUpdate))) { // only if we havent checked already
$response = $this->makeCall($service, $params, $fieldKey, $fieldValue);
$this->applyCost($lead);
$persist = true;
Expand All @@ -175,7 +175,7 @@ public function doEnhancement(Lead &$lead)
// email API call
$service = 'emails';
$fieldKey = 'email';
if (is_null($lead->$fieldToUpdate)) { // only if we havent checked already
if (is_null($lead->getFieldValue($fieldToUpdate))) { // only if we havent checked already
$response = $this->makeCall($service, $params, $fieldKey, $fieldValue);
$this->applyCost($lead);
$persist = true;
Expand Down Expand Up @@ -206,14 +206,7 @@ public function doEnhancement(Lead &$lead)

if ($persist) {
$this->saveLead($lead);
} // TODO why wont custom fields persist to DB?
// This would be a duplicate event now.
// if ($this->dispatcher->hasListeners(MauticEnhancerEvents::ENHANCER_COMPLETED)) {
// $isNew = !$lead->getId();
// $complete = new MauticEnhancerEvent($this, $lead, $isNew);
// $this->dispatcher->dispatch(MauticEnhancerEvents::ENHANCER_COMPLETED, $complete);
// }
}
}
}

Expand Down

0 comments on commit aa8baa6

Please sign in to comment.