Esempio n. 1
0
 /**
  * @param $pluginName
  */
 private function executePluginUninstall($pluginName)
 {
     try {
         $plugin = $this->getLoadedPlugin($pluginName);
         $plugin->uninstall();
     } catch (\Exception $e) {
     }
     if (empty($plugin)) {
         return;
     }
     try {
         foreach (VisitDimension::getDimensions($plugin) as $dimension) {
             $this->uninstallDimension($dimension);
         }
     } catch (\Exception $e) {
     }
     try {
         foreach (ActionDimension::getDimensions($plugin) as $dimension) {
             $this->uninstallDimension($dimension);
         }
     } catch (\Exception $e) {
     }
     try {
         foreach (ConversionDimension::getDimensions($plugin) as $dimension) {
             $this->uninstallDimension($dimension);
         }
     } catch (\Exception $e) {
     }
 }
Esempio n. 2
0
 /**
  * @param VisitDimension|ActionDimension|ConversionDimension $dimension
  * @param VisitDimension[]|ActionDimension[]|ConversionDimension[] $allDimensions
  * @return bool
  */
 private function doesAnotherPluginDefineSameColumnWithDbEntry($dimension, $allDimensions)
 {
     $module = $dimension->getModule();
     $columnName = $dimension->getColumnName();
     foreach ($allDimensions as $dim) {
         if ($dim->getColumnName() === $columnName && $dim->hasColumnType() && $dim->getModule() !== $module) {
             return true;
         }
     }
     return false;
 }
Esempio n. 3
0
 /**
  * @return mixed|Dimension[]
  */
 private static function getActionDimensions()
 {
     return ActionDimension::getAllDimensions();
 }
Esempio n. 4
0
 public static function getDimensions(Plugin $plugin)
 {
     $dimensions = array();
     foreach (VisitDimension::getDimensions($plugin) as $dimension) {
         $dimensions[] = $dimension;
     }
     foreach (ActionDimension::getDimensions($plugin) as $dimension) {
         $dimensions[] = $dimension;
     }
     foreach (ConversionDimension::getDimensions($plugin) as $dimension) {
         $dimensions[] = $dimension;
     }
     return $dimensions;
 }
Esempio n. 5
0
 /**
  * @param ActionDimension|ConversionDimension|VisitDimension $dimension
  * @param string $componentPrefix
  * @param array $columns
  * @param array $versions
  * @return array The modified versions array
  */
 private static function mixinVersions($dimension, $componentPrefix, $columns, $versions)
 {
     $columnName = $dimension->getColumnName();
     if (!$columnName || !$dimension->hasColumnType()) {
         return $versions;
     }
     $component = $componentPrefix . $columnName;
     $version = $dimension->getVersion();
     if (array_key_exists($columnName, $columns) && false === PiwikUpdater::getCurrentRecordedComponentVersion($component) && self::wasDimensionMovedFromCoreToPlugin($component, $version)) {
         PiwikUpdater::recordComponentSuccessfullyUpdated($component, $version);
         return $versions;
     }
     $versions[$component] = $version;
     return $versions;
 }
Esempio n. 6
0
 /**
  * Records in the DB the association between the visit and this action.
  *
  * @param int $idReferrerActionUrl is the ID of the last action done by the current visit.
  * @param $idReferrerActionName
  * @param Visitor $visitor
  */
 public function record(Visitor $visitor, $idReferrerActionUrl, $idReferrerActionName)
 {
     $this->loadIdsFromLogActionTable();
     $visitAction = array('idvisit' => $visitor->getVisitorColumn('idvisit'), 'idsite' => $this->request->getIdSite(), 'idvisitor' => $visitor->getVisitorColumn('idvisitor'), 'idaction_url' => $this->getIdActionUrl(), 'idaction_url_ref' => $idReferrerActionUrl, 'idaction_name_ref' => $idReferrerActionName);
     /** @var ActionDimension[] $dimensions */
     $dimensions = ActionDimension::getAllDimensions();
     foreach ($dimensions as $dimension) {
         $value = $dimension->onNewAction($this->request, $visitor, $this);
         if ($value !== false) {
             if (is_float($value)) {
                 $value = Common::forceDotAsSeparatorForDecimalPoint($value);
             }
             $visitAction[$dimension->getColumnName()] = $value;
         }
     }
     // idaction_name is NULLable. we only set it when applicable
     if ($this->isActionHasActionName()) {
         $visitAction['idaction_name'] = (int) $this->getIdActionName();
     }
     foreach ($this->actionIdsCached as $field => $idAction) {
         $visitAction[$field] = $idAction === false ? 0 : $idAction;
     }
     $customValue = $this->getCustomFloatValue();
     if (!empty($customValue)) {
         $visitAction[self::DB_COLUMN_CUSTOM_FLOAT] = Common::forceDotAsSeparatorForDecimalPoint($customValue);
     }
     $visitAction = array_merge($visitAction, $this->customFields);
     $this->idLinkVisitAction = $this->getModel()->createAction($visitAction);
     $visitAction['idlink_va'] = $this->idLinkVisitAction;
     Common::printDebug("Inserted new action:");
     $visitActionDebug = $visitAction;
     $visitActionDebug['idvisitor'] = bin2hex($visitActionDebug['idvisitor']);
     Common::printDebug($visitActionDebug);
     /**
      * Triggered after successfully persisting a [visit action entity](/guides/persistence-and-the-mysql-backend#visit-actions).
      *
      * This event is deprecated, use [Dimensions](http://developer.piwik.org/guides/dimensions) instead.
      *
      * @param Action $tracker Action The Action tracker instance.
      * @param array $visitAction The visit action entity that was persisted. Read
      *                           [this](/guides/persistence-and-the-mysql-backend#visit-actions) to see what it contains.
      * @deprecated
      */
     Piwik::postEvent('Tracker.recordAction', array($trackerAction = $this, $visitAction));
 }
Esempio n. 7
0
 /**
  * @param ActionDimension|ConversionDimension|VisitDimension $dimension
  * @param string $componentPrefix
  * @param array $columns
  * @param array $versions
  * @return array The modified versions array
  */
 private function mixinVersions(PiwikUpdater $updater, $dimension, $componentPrefix, $columns, $versions)
 {
     $columnName = $dimension->getColumnName();
     // dimensions w/o columns do not need DB updates
     if (!$columnName || !$dimension->hasColumnType()) {
         return $versions;
     }
     $component = $componentPrefix . $columnName;
     $version = $dimension->getVersion();
     // if the column exists in the table, but has no associated version, and was one of the core columns
     // that was moved when the dimension refactor took place, then:
     // - set the installed version in the DB to the current code version
     // - and do not check for updates since we just set the version to the latest
     if (array_key_exists($columnName, $columns) && false === $updater->getCurrentComponentVersion($component) && self::wasDimensionMovedFromCoreToPlugin($component, $version)) {
         $updater->markComponentSuccessfullyUpdated($component, $version);
         return $versions;
     }
     $versions[$component] = $version;
     return $versions;
 }
Esempio n. 8
0
 public function test_getAllDimensions_shouldLoadAllDimensionsButOnlyIfLoadedPlugins()
 {
     Manager::getInstance()->loadPlugins(array('Actions', 'Events'));
     $dimensions = ActionDimension::getAllDimensions();
     $this->assertGreaterThan(8, count($dimensions));
     foreach ($dimensions as $dimension) {
         $this->assertInstanceOf('\\Piwik\\Plugin\\Dimension\\ActionDimension', $dimension);
         $this->assertRegExp('/Piwik.Plugins.(Actions|Events).Columns/', get_class($dimension));
     }
 }
Esempio n. 9
0
 public function install()
 {
     $changes = parent::install();
     $changes['log_link_visit_action'][] = "ADD INDEX index_idsite_servertime ( idsite, server_time )";
     return $changes;
 }
Esempio n. 10
0
 /**
  * Records in the DB the association between the visit and this action.
  *
  * @param int $idReferrerActionUrl is the ID of the last action done by the current visit.
  * @param $idReferrerActionName
  * @param Visitor $visitor
  */
 public function record(Visitor $visitor, $idReferrerActionUrl, $idReferrerActionName)
 {
     $this->loadIdsFromLogActionTable();
     $visitAction = array('idvisit' => $visitor->getVisitorColumn('idvisit'), 'idsite' => $this->request->getIdSite(), 'idvisitor' => $visitor->getVisitorColumn('idvisitor'), 'idaction_url' => $this->getIdActionUrl(), 'idaction_url_ref' => $idReferrerActionUrl, 'idaction_name_ref' => $idReferrerActionName);
     $dimensions = ActionDimension::getAllDimensions();
     foreach ($dimensions as $dimension) {
         $value = $dimension->onNewAction($this->request, $visitor, $this);
         if ($value !== false) {
             $visitAction[$dimension->getColumnName()] = $value;
         }
     }
     // idaction_name is NULLable. we only set it when applicable
     if ($this->isActionHasActionName()) {
         $visitAction['idaction_name'] = (int) $this->getIdActionName();
     }
     foreach ($this->actionIdsCached as $field => $idAction) {
         $visitAction[$field] = $idAction === false ? 0 : $idAction;
     }
     $customValue = $this->getCustomFloatValue();
     if (!empty($customValue)) {
         $visitAction[self::DB_COLUMN_CUSTOM_FLOAT] = $customValue;
     }
     $customVariables = $this->getCustomVariables();
     if (!empty($customVariables)) {
         Common::printDebug("Page level Custom Variables: ");
         Common::printDebug($customVariables);
     }
     $visitAction = array_merge($visitAction, $customVariables);
     $fields = implode(", ", array_keys($visitAction));
     $bind = array_values($visitAction);
     $values = Common::getSqlStringFieldsArray($visitAction);
     $sql = "INSERT INTO " . Common::prefixTable('log_link_visit_action') . " ({$fields}) VALUES ({$values})";
     Tracker::getDatabase()->query($sql, $bind);
     $this->idLinkVisitAction = Tracker::getDatabase()->lastInsertId();
     $visitAction['idlink_va'] = $this->idLinkVisitAction;
     Common::printDebug("Inserted new action:");
     Common::printDebug($visitAction);
     /**
      * Triggered after successfully persisting a [visit action entity](/guides/persistence-and-the-mysql-backend#visit-actions).
      *
      * @param Action $tracker Action The Action tracker instance.
      * @param array $visitAction The visit action entity that was persisted. Read
      *                           [this](/guides/persistence-and-the-mysql-backend#visit-actions) to see what it contains.
      */
     Piwik::postEvent('Tracker.recordAction', array($trackerAction = $this, $visitAction));
 }
Esempio n. 11
0
 /**
  * Records in the DB the association between the visit and this action.
  *
  * @param int $idReferrerActionUrl is the ID of the last action done by the current visit.
  * @param $idReferrerActionName
  * @param Visitor $visitor
  */
 public function record(Visitor $visitor, $idReferrerActionUrl, $idReferrerActionName)
 {
     $this->loadIdsFromLogActionTable();
     $visitAction = array('idvisit' => $visitor->getVisitorColumn('idvisit'), 'idsite' => $this->request->getIdSite(), 'idvisitor' => $visitor->getVisitorColumn('idvisitor'), 'idaction_url' => $this->getIdActionUrl(), 'idaction_url_ref' => $idReferrerActionUrl, 'idaction_name_ref' => $idReferrerActionName);
     /** @var ActionDimension[] $dimensions */
     $dimensions = ActionDimension::getAllDimensions();
     foreach ($dimensions as $dimension) {
         $value = $dimension->onNewAction($this->request, $visitor, $this);
         if ($value !== false) {
             if (is_float($value)) {
                 $value = Common::forceDotAsSeparatorForDecimalPoint($value);
             }
             $visitAction[$dimension->getColumnName()] = $value;
         }
     }
     // idaction_name is NULLable. we only set it when applicable
     if ($this->isActionHasActionName()) {
         $visitAction['idaction_name'] = (int) $this->getIdActionName();
     }
     foreach ($this->actionIdsCached as $field => $idAction) {
         $visitAction[$field] = $idAction === false ? 0 : $idAction;
     }
     $customValue = $this->getCustomFloatValue();
     if (!empty($customValue)) {
         $visitAction[self::DB_COLUMN_CUSTOM_FLOAT] = Common::forceDotAsSeparatorForDecimalPoint($customValue);
     }
     $visitAction = array_merge($visitAction, $this->customFields);
     $this->idLinkVisitAction = $this->getModel()->createAction($visitAction);
     $visitAction['idlink_va'] = $this->idLinkVisitAction;
     Common::printDebug("Inserted new action:");
     $visitActionDebug = $visitAction;
     $visitActionDebug['idvisitor'] = bin2hex($visitActionDebug['idvisitor']);
     Common::printDebug($visitActionDebug);
 }