diff --git a/app/bundles/DynamicContentBundle/Model/DynamicContentModel.php b/app/bundles/DynamicContentBundle/Model/DynamicContentModel.php index d3f09409e2b..035c7e77092 100644 --- a/app/bundles/DynamicContentBundle/Model/DynamicContentModel.php +++ b/app/bundles/DynamicContentBundle/Model/DynamicContentModel.php @@ -176,7 +176,19 @@ public function getSlotContentForLead($slot, $lead) */ public function createStatEntry(DynamicContent $dynamicContent, $lead, $source = null) { + if (empty($lead)) { + return; + } + + if ($lead instanceof Lead && !$lead->getId()) { + return; + } + if (is_array($lead)) { + if (empty($lead['id'])) { + return; + } + $lead = $this->em->getReference('MauticLeadBundle:Lead', $lead['id']); } diff --git a/app/bundles/LeadBundle/Helper/ContactRequestHelper.php b/app/bundles/LeadBundle/Helper/ContactRequestHelper.php index 409be138f25..da17c770b37 100644 --- a/app/bundles/LeadBundle/Helper/ContactRequestHelper.php +++ b/app/bundles/LeadBundle/Helper/ContactRequestHelper.php @@ -123,7 +123,10 @@ public function __construct( public function getContactFromQuery(array $queryFields = []) { $this->trackedContact = $this->contactTracker->getContact(); + + unset($queryFields['page_url']); // This is set now automatically by PageModel $this->queryFields = $queryFields; + try { $foundContact = $this->getContactFromUrl(); $this->trackedContact = $foundContact; @@ -131,6 +134,10 @@ public function getContactFromQuery(array $queryFields = []) } catch (ContactNotFoundException $exception) { } + if (!$this->trackedContact) { + return null; + } + $this->prepareContactFromRequest(); return $this->trackedContact; diff --git a/plugins/MauticFocusBundle/Model/FocusModel.php b/plugins/MauticFocusBundle/Model/FocusModel.php index 35e13bdca4f..6385dab7cc8 100644 --- a/plugins/MauticFocusBundle/Model/FocusModel.php +++ b/plugins/MauticFocusBundle/Model/FocusModel.php @@ -17,6 +17,7 @@ use Mautic\CoreBundle\Helper\Chart\LineChart; use Mautic\CoreBundle\Helper\TemplatingHelper; use Mautic\CoreBundle\Model\FormModel; +use Mautic\LeadBundle\Entity\Lead; use Mautic\LeadBundle\Model\FieldModel; use Mautic\LeadBundle\Model\LeadModel; use Mautic\PageBundle\Model\TrackableModel; @@ -330,6 +331,22 @@ public static function isLightColor($hex, $level = 200) */ public function addStat(Focus $focus, $type, $data = null, $lead = null) { + if (empty($lead)) { + return; + } + + if ($lead instanceof Lead && !$lead->getId()) { + return; + } + + if (is_array($lead)) { + if (empty($lead['id'])) { + return; + } + + $lead = $this->em->getReference('MauticLeadBundle:Lead', $lead['id']); + } + switch ($type) { case Stat::TYPE_FORM: /** @var \Mautic\FormBundle\Entity\Submission $data */