array("ADD COLUMN `$this->columnName` $this->columnType", "ADD INDEX ...") ); ``` * @api */ public function install() { if (empty($this->columnName) || empty($this->columnType)) { return array(); } return array( $this->tableName => array("ADD COLUMN `$this->columnName` $this->columnType") ); } /** * @see ActionDimension::update() * @return array * @ignore */ public function update() { if (empty($this->columnName) || empty($this->columnType)) { return array(); } return array( $this->tableName => array("MODIFY COLUMN `$this->columnName` $this->columnType") ); } /** * Uninstalls the dimension if a {@link $columnName} and {@link columnType} is set. In case you perform any custom * actions during {@link install()} - for instance adding an index - you should make sure to undo those actions by * overwriting this method. Make sure to call this parent method to make sure the uninstallation of the column * will be done. * @throws Exception * @api */ public function uninstall() { if (empty($this->columnName) || empty($this->columnType)) { return; } try { $sql = "ALTER TABLE `" . Common::prefixTable($this->tableName) . "` DROP COLUMN `$this->columnName`"; Db::exec($sql); } catch (Exception $e) { if (!Db::get()->isErrNo($e, '1091')) { throw $e; } } } /** * @see ActionDimension::getVersion() * @return string * @ignore */ public function getVersion() { return $this->columnType; } /** * Adds a new segment. It automatically sets the SQL segment depending on the column name in case none is set * already. * * @see \Piwik\Columns\Dimension::addSegment() * @param Segment $segment * @api */ protected function addSegment(Segment $segment) { $sqlSegment = $segment->getSqlSegment(); if (!empty($this->columnName) && empty($sqlSegment)) { $segment->setSqlSegment($this->tableName . '.' . $this->columnName); } parent::addSegment($segment); } /** * Get all conversion dimensions that are defined by all activated plugins. * @ignore */ public static function getAllDimensions() { $cacheId = CacheId::pluginAware('ConversionDimensions'); $cache = PiwikCache::getTransientCache(); if (!$cache->contains($cacheId)) { $plugins = PluginManager::getInstance()->getPluginsLoadedAndActivated(); $instances = array(); foreach ($plugins as $plugin) { foreach (self::getDimensions($plugin) as $instance) { $instances[] = $instance; } } $cache->save($cacheId, $instances); } return $cache->fetch($cacheId); } /** * Get all conversion dimensions that are defined by the given plugin. * @param Plugin $plugin * @return ConversionDimension[] * @ignore */ public static function getDimensions(Plugin $plugin) { $dimensions = $plugin->findMultipleComponents('Columns', '\\Piwik\\Plugin\\Dimension\\ConversionDimension'); $instances = array(); foreach ($dimensions as $dimension) { $instances[] = new $dimension(); } return $instances; } /** * This event is triggered when an ecommerce order is converted. Any returned value will be persist in the database. * Return boolean `false` if you do not want to change the value in some cases. * * @param Request $request * @param Visitor $visitor * @param Action|null $action * @param GoalManager $goalManager * * @return mixed|false * @api */ public function onEcommerceOrderConversion(Request $request, Visitor $visitor, $action, GoalManager $goalManager) { return false; } /** * This event is triggered when an ecommerce cart update is converted. Any returned value will be persist in the * database. Return boolean `false` if you do not want to change the value in some cases. * * @param Request $request * @param Visitor $visitor * @param Action|null $action * @param GoalManager $goalManager * * @return mixed|false * @api */ public function onEcommerceCartUpdateConversion(Request $request, Visitor $visitor, $action, GoalManager $goalManager) { return false; } /** * This event is triggered when an any custom goal is converted. Any returned value will be persist in the * database. Return boolean `false` if you do not want to change the value in some cases. * * @param Request $request * @param Visitor $visitor * @param Action|null $action * @param GoalManager $goalManager * * @return mixed|false * @api */ public function onGoalConversion(Request $request, Visitor $visitor, $action, GoalManager $goalManager) { return false; } }