diff options
-rw-r--r-- | core/Plugin/ActionDimension.php | 17 | ||||
-rw-r--r-- | core/Plugin/Manager.php | 14 | ||||
-rw-r--r-- | core/Plugin/VisitDimension.php | 37 | ||||
-rw-r--r-- | core/Tracker/GoalManager.php | 31 | ||||
-rw-r--r-- | core/Tracker/Visit.php | 1 | ||||
-rw-r--r-- | plugins/CoreHome/Columns/VisitGoalBuyer.php | 54 |
6 files changed, 117 insertions, 37 deletions
diff --git a/core/Plugin/ActionDimension.php b/core/Plugin/ActionDimension.php index 507b2d804f..adce8f3931 100644 --- a/core/Plugin/ActionDimension.php +++ b/core/Plugin/ActionDimension.php @@ -53,6 +53,23 @@ abstract class ActionDimension } } + public function uninstall() + { + if (empty($this->fieldName) || empty($this->fieldType)) { + return; + } + + try { + $sql = "ALTER TABLE `" . Common::prefixTable("log_link_visit_action") . "` DROP COLUMN `$this->fieldName`"; + Db::exec($sql); + } catch (\Exception $e) { + if (!Db::get()->isErrNo($e, '1091')) { + throw $e; + } + } + } + + public function shouldHandle() { return false; diff --git a/core/Plugin/Manager.php b/core/Plugin/Manager.php index c647ba2bd4..a4cb4cfa70 100644 --- a/core/Plugin/Manager.php +++ b/core/Plugin/Manager.php @@ -474,7 +474,6 @@ class Manager extends Singleton PiwikConfig::getInstance()->forceSave(); $this->clearCache($pluginName); - } protected function isPluginInFilesystem($pluginName) @@ -1300,6 +1299,19 @@ class Manager extends Singleton $plugin->uninstall(); } catch (\Exception $e) { } + + try { + $plugin = $this->getLoadedPlugin($pluginName); + // todo not sure if this makes sense here + foreach (VisitDimension::getDimensions($plugin) as $dimension) { + $dimension->uninstall(); + } + // todo not sure if this makes sense here + foreach (ActionDimension::getDimensions($plugin) as $dimension) { + $dimension->uninstall(); + } + } catch (\Exception $e) { + } } /** diff --git a/core/Plugin/VisitDimension.php b/core/Plugin/VisitDimension.php index 451ba7b181..c3a654591c 100644 --- a/core/Plugin/VisitDimension.php +++ b/core/Plugin/VisitDimension.php @@ -53,7 +53,7 @@ abstract class VisitDimension if ($this->hasImplementedEvent('onNewVisit') || $this->hasImplementedEvent('onExistingVisit') || $this->hasImplementedEvent('onConvertedVisit') ) { - $sql = "ALTER TABLE `" . Common::prefixTable("log_visit") . "` ADD `$this->fieldName` $this->fieldType;"; + $sql = "ALTER TABLE `" . Common::prefixTable("log_visit") . "` ADD `$this->fieldName` $this->fieldType"; Db::exec($sql); } @@ -65,7 +65,7 @@ abstract class VisitDimension try { if ($this->hasImplementedEvent('onRecordGoal')) { - $sql = "ALTER TABLE `" . Common::prefixTable("log_conversion") . "` ADD `$this->fieldName` $this->fieldType;"; + $sql = "ALTER TABLE `" . Common::prefixTable("log_conversion") . "` ADD `$this->fieldName` $this->fieldType"; Db::exec($sql); } @@ -76,6 +76,39 @@ abstract class VisitDimension } } + public function uninstall() + { + if (empty($this->fieldName) || empty($this->fieldType)) { + return; + } + + try { + if ($this->hasImplementedEvent('onNewVisit') + || $this->hasImplementedEvent('onExistingVisit') + || $this->hasImplementedEvent('onConvertedVisit') ) { + $sql = "ALTER TABLE `" . Common::prefixTable("log_visit") . "` DROP COLUMN `$this->fieldName`"; + Db::exec($sql); + } + + } catch (\Exception $e) { + if (!Db::get()->isErrNo($e, '1091')) { + throw $e; + } + } + + try { + if ($this->hasImplementedEvent('onRecordGoal')) { + $sql = "ALTER TABLE `" . Common::prefixTable("log_conversion") . "` DROP COLUMN `$this->fieldName`"; + Db::exec($sql); + } + + } catch (\Exception $e) { + if (!Db::get()->isErrNo($e, '1091')) { + throw $e; + } + } + } + protected function addSegment(Segment $segment) { $sqlSegment = $segment->getSqlSegment(); diff --git a/core/Tracker/GoalManager.php b/core/Tracker/GoalManager.php index 9d7ece7c05..d34a7ca1fd 100644 --- a/core/Tracker/GoalManager.php +++ b/core/Tracker/GoalManager.php @@ -10,7 +10,6 @@ namespace Piwik\Tracker; use Exception; use Piwik\Common; -use Piwik\Config; use Piwik\Piwik; use Piwik\Plugin\VisitDimension; use Piwik\Plugins\CustomVariables\CustomVariables; @@ -21,8 +20,6 @@ use Piwik\Tracker; class GoalManager { // log_visit.visit_goal_buyer - const TYPE_BUYER_NONE = 0; - const TYPE_BUYER_ORDERED = 1; const TYPE_BUYER_OPEN_CART = 2; const TYPE_BUYER_ORDERED_AND_OPEN_CART = 3; @@ -45,13 +42,14 @@ class GoalManager */ protected $action = null; protected $convertedGoals = array(); - protected $isThereExistingCartInVisit = false; /** * @var Request */ protected $request; protected $orderId; + protected $isThereExistingCartInVisit = false; + /** * Constructor * @param Request $request @@ -70,26 +68,15 @@ class GoalManager $this->requestIsEcommerce = ($this->idGoal == 0); } - function getBuyerType($existingType = GoalManager::TYPE_BUYER_NONE) + public function detectIsThereExistingCartInVisit($visitInformation) { - // Was there a Cart for this visit prior to the order? - $this->isThereExistingCartInVisit = in_array($existingType, - array(GoalManager::TYPE_BUYER_OPEN_CART, - GoalManager::TYPE_BUYER_ORDERED_AND_OPEN_CART)); + if (!empty($visitInformation['visit_goal_buyer'])) { + $goalBuyer = $visitInformation['visit_goal_buyer']; + $types = array(GoalManager::TYPE_BUYER_OPEN_CART, GoalManager::TYPE_BUYER_ORDERED_AND_OPEN_CART); - if (!$this->requestIsEcommerce) { - return $existingType; + // Was there a Cart for this visit prior to the order? + $this->isThereExistingCartInVisit = in_array($goalBuyer, $types); } - if ($this->isGoalAnOrder) { - return self::TYPE_BUYER_ORDERED; - } - // request is Add to Cart - if ($existingType == self::TYPE_BUYER_ORDERED - || $existingType == self::TYPE_BUYER_ORDERED_AND_OPEN_CART - ) { - return self::TYPE_BUYER_ORDERED_AND_OPEN_CART; - } - return self::TYPE_BUYER_OPEN_CART; } static public function getGoalDefinitions($idSite) @@ -291,7 +278,7 @@ class GoalManager } $conversion['items'] = $itemsCount; - if($this->isThereExistingCartInVisit) { + if ($this->isThereExistingCartInVisit) { $updateWhere = array( 'idvisit' => $visitInformation['idvisit'], 'idgoal' => self::IDGOAL_CART, diff --git a/core/Tracker/Visit.php b/core/Tracker/Visit.php index 7dceab977a..be3f415b52 100644 --- a/core/Tracker/Visit.php +++ b/core/Tracker/Visit.php @@ -166,6 +166,7 @@ class Visit implements VisitInterface $idReferrerActionUrl = $this->visitorInfo['visit_exit_idaction_url']; $idReferrerActionName = $this->visitorInfo['visit_exit_idaction_name']; try { + $this->goalManager->detectIsThereExistingCartInVisit($this->visitorInfo); $this->handleExistingVisit($visitor, $action, $visitIsConverted); if (!is_null($action)) { $action->record($visitor, $idReferrerActionUrl, $idReferrerActionName); diff --git a/plugins/CoreHome/Columns/VisitGoalBuyer.php b/plugins/CoreHome/Columns/VisitGoalBuyer.php index 64ca106962..7dbdc28ebb 100644 --- a/plugins/CoreHome/Columns/VisitGoalBuyer.php +++ b/plugins/CoreHome/Columns/VisitGoalBuyer.php @@ -18,11 +18,17 @@ use Piwik\Tracker\Visitor; class VisitGoalBuyer extends VisitDimension { + // log_visit.visit_goal_buyer + const TYPE_BUYER_NONE = 0; + const TYPE_BUYER_ORDERED = 1; + const TYPE_BUYER_OPEN_CART = GoalManager::TYPE_BUYER_OPEN_CART; + const TYPE_BUYER_ORDERED_AND_OPEN_CART = GoalManager::TYPE_BUYER_ORDERED_AND_OPEN_CART; + static protected $visitEcommerceStatus = array( - GoalManager::TYPE_BUYER_NONE => 'none', - GoalManager::TYPE_BUYER_ORDERED => 'ordered', - GoalManager::TYPE_BUYER_OPEN_CART => 'abandonedCart', - GoalManager::TYPE_BUYER_ORDERED_AND_OPEN_CART => 'orderedThenAbandonedCart', + self::TYPE_BUYER_NONE => 'none', + self::TYPE_BUYER_ORDERED => 'ordered', + self::TYPE_BUYER_OPEN_CART => 'abandonedCart', + self::TYPE_BUYER_ORDERED_AND_OPEN_CART => 'orderedThenAbandonedCart', ); protected $fieldName = 'visit_goal_buyer'; @@ -55,9 +61,7 @@ class VisitGoalBuyer extends VisitDimension */ public function onNewVisit(Request $request, Visitor $visitor, $action) { - $goalManager = new GoalManager($request); - - return $goalManager->getBuyerType(); + return $this->getBuyerType($request); } /** @@ -68,15 +72,16 @@ class VisitGoalBuyer extends VisitDimension */ public function onExistingVisit(Request $request, Visitor $visitor, $action) { - $goalBuyer = $visitor->getVisitorColumn('visit_goal_buyer'); + $goalBuyer = $visitor->getVisitorColumn($this->fieldName); // Ecommerce buyer status - $goalManager = new GoalManager($request); - $visitEcommerceStatus = $goalManager->getBuyerType($goalBuyer); + $visitEcommerceStatus = $this->getBuyerType($request, $goalBuyer); - if($visitEcommerceStatus != GoalManager::TYPE_BUYER_NONE - // only update if the value has changed (prevents overwriting the value in case a request has updated it in the meantime) + if($visitEcommerceStatus != self::TYPE_BUYER_NONE + // only update if the value has changed (prevents overwriting the value in case a request has + // updated it in the meantime) && $visitEcommerceStatus != $goalBuyer) { + return $visitEcommerceStatus; } @@ -86,9 +91,11 @@ class VisitGoalBuyer extends VisitDimension static public function getVisitEcommerceStatus($status) { $id = array_search($status, self::$visitEcommerceStatus); + if ($id === false) { throw new \Exception("Invalid 'visitEcommerceStatus' segment value $status"); } + return $id; } @@ -100,7 +107,30 @@ class VisitGoalBuyer extends VisitDimension if (!isset(self::$visitEcommerceStatus[$id])) { throw new \Exception("Unexpected ECommerce status value "); } + return self::$visitEcommerceStatus[$id]; } + private function getBuyerType(Request $request, $existingType = self::TYPE_BUYER_NONE) + { + $goalManager = new GoalManager($request); + + if (!$goalManager->requestIsEcommerce) { + return $existingType; + } + + if ($goalManager->isGoalAnOrder) { + return self::TYPE_BUYER_ORDERED; + } + + // request is Add to Cart + if ($existingType == self::TYPE_BUYER_ORDERED + || $existingType == self::TYPE_BUYER_ORDERED_AND_OPEN_CART + ) { + return self::TYPE_BUYER_ORDERED_AND_OPEN_CART; + } + + return self::TYPE_BUYER_OPEN_CART; + } + }
\ No newline at end of file |