From 851d760043945057e25d2d37dee5227eb7266747 Mon Sep 17 00:00:00 2001 From: Alan Hartless Date: Fri, 30 Nov 2018 16:46:56 -0600 Subject: [PATCH 1/2] Prevent exception for Mautic users --- app/bundles/LeadBundle/Helper/ContactRequestHelper.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/bundles/LeadBundle/Helper/ContactRequestHelper.php b/app/bundles/LeadBundle/Helper/ContactRequestHelper.php index c8a77ab0757..0506fd99e4e 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; @@ -171,6 +178,7 @@ private function getContactFromUrl() true, true ); + if ($foundContact->getId() !== $this->trackedContact->getId()) { // A contact was found by a publicly updatable field return $foundContact; From 28f689ec96dc9d499b64cfa15a2e8dc6ebb0ca11 Mon Sep 17 00:00:00 2001 From: Alan Hartless Date: Fri, 30 Nov 2018 16:47:46 -0600 Subject: [PATCH 2/2] Prevent a "new entity found" exception for sessions that aren't tracked --- .../Model/DynamicContentModel.php | 12 ++++++++++++ plugins/MauticFocusBundle/Model/FocusModel.php | 17 +++++++++++++++++ 2 files changed, 29 insertions(+) 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/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 */