From 4b1b0757ff146837ec3ef8d928f37b04c1d17ac4 Mon Sep 17 00:00:00 2001 From: diosmosis Date: Wed, 8 Jul 2015 20:06:12 -0700 Subject: Move visitor not found logic in Visit::handle() to Goals request processor. --- plugins/Goals/Tracker/GoalsRequestProcessor.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'plugins/Goals') diff --git a/plugins/Goals/Tracker/GoalsRequestProcessor.php b/plugins/Goals/Tracker/GoalsRequestProcessor.php index 22315f7511..2bde947928 100644 --- a/plugins/Goals/Tracker/GoalsRequestProcessor.php +++ b/plugins/Goals/Tracker/GoalsRequestProcessor.php @@ -70,4 +70,26 @@ class GoalsRequestProcessor extends RequestProcessor $visitProperties->setRequestMetadata('Goals', 'visitIsConverted', $someGoalsConverted); } } + + public function processRequest(VisitProperties $visitProperties) + { + $isManualGoalConversion = self::$goalManager->isManualGoalConversion(); + $requestIsEcommerce = self::$goalManager->requestIsEcommerce; + + $visitorNotFoundInDb = $visitProperties->getRequestMetadata('CoreHome', 'visitorNotFoundInDb'); + + // There is an edge case when: + // - two manual goal conversions happen in the same second + // - which result in handleExistingVisit throwing the exception + // because the UPDATE didn't affect any rows (one row was found, but not updated since no field changed) + // - the exception is caught here and will result in a new visit incorrectly + // In this case, we cancel the current conversion to be recorded: + if ($visitorNotFoundInDb + && ($isManualGoalConversion + || $requestIsEcommerce) + ) { + $visitProperties->setRequestMetadata('Goals', 'someGoalsConverted', false); + $visitProperties->setRequestMetadata('Goals', 'visitIsConverted', false); + } + } } -- cgit v1.2.3