diff --git a/Helper/TokenHelper.php b/Helper/TokenHelper.php index 2d76525a..39cdfc01 100644 --- a/Helper/TokenHelper.php +++ b/Helper/TokenHelper.php @@ -19,21 +19,16 @@ */ class TokenHelper { - /** - * To reduce overhead, fields will be searched for this before attempting token replacement. - */ + /** @var string To reduce overhead, fields will be searched for this before attempting token replacement. */ const TOKEN_KEY = '{{'; - /** - * @var Engine - */ + /** @var Engine */ private $engine; - /** - * @var array context of tokens for replacement - */ + /** @var array context of tokens for replacement */ private $context = []; + /** @var DateFormatHelper */ private $dateFormatHelper; /** @@ -53,14 +48,14 @@ public function __construct() /** * Recursively replaces tokens using an array for context. * - * @param array $array + * @param array|object $context * * @return array */ - public function renderArray($array = []) + public function renderArray($context = []) { $result = []; - foreach ($array as $key => $value) { + foreach ($context as $key => $value) { if (false !== strpos($key, self::TOKEN_KEY)) { $key = $this->engine->render($key, $this->context); } @@ -69,7 +64,7 @@ public function renderArray($array = []) $value = $this->engine->render($value, $this->context); } } elseif (is_array($value) || is_object($value)) { - $value = $this->tokenizeArray($value, $this->context); + $value = $this->renderArray($value); } $result[$key] = $value; } @@ -174,7 +169,7 @@ public function addContextContact(Contact $contact) } // Add DNC status. - /** @var DoNotContact $record */ + /** @var \Mautic\LeadBundle\Model\DoNotContact $record */ foreach ($contact->getDoNotContact() as $record) { if (!isset($context['doNotContact'])) { $context['doNotContact'] = []; diff --git a/Integration/ClientIntegration.php b/Integration/ClientIntegration.php index 268ac974..761bc34f 100644 --- a/Integration/ClientIntegration.php +++ b/Integration/ClientIntegration.php @@ -48,7 +48,7 @@ class ClientIntegration extends AbstractIntegration protected $contact; /** @var array */ - protected $event; + protected $event = []; /** @var bool $test */ protected $test = false; @@ -368,7 +368,7 @@ private function updateContact() if ($updatedFields || $updatedAttribution) { /** @var \Mautic\LeadBundle\Model\LeadModel $model */ $contactModel = $this->dispatcher->getContainer()->get('mautic.lead.model.lead'); - $contactModel->getRepository()->saveEntity($this->contact); + $contactModel->saveEntity($this->contact); $this->setLogs('Operation successful. The contact was updated.', 'updated'); } else { $this->setLogs('Operation successful, but no fields on the contact needed updating.', 'info'); diff --git a/Model/ApiPayload.php b/Model/ApiPayload.php index 4b358007..89bdb30d 100644 --- a/Model/ApiPayload.php +++ b/Model/ApiPayload.php @@ -288,10 +288,14 @@ private function getTokenHelper() $this->tokenHelper->setTimezones($tza, $tzb); // Add the Contact as context for field replacement. - $this->tokenHelper->addContextContact($this->contact); + if ($this->contact) { + $this->tokenHelper->addContextContact($this->contact); + } // Include the payload as additional context. - $this->tokenHelper->addContext(['payload' => $this->payload]); + if ($this->payload) { + $this->tokenHelper->addContext(['payload' => $this->payload]); + } return $this->tokenHelper; }