From 9efc7341f98058bbe37f70d0a93e9ea47d7caf4c Mon Sep 17 00:00:00 2001
From: Thomas Steur <tsteur@users.noreply.github.com>
Date: Thu, 1 Sep 2016 18:28:13 +1200
Subject: [PATCH] Remove deprecated events (#10455)

* remove some deprecated events

* fix unit tests wants to establish a DB connection, read it from cache

* fix possible bug

* fix some integration tests

* fix tests

* fix category was not set

* fix some tests

* fix integration test

* trying to fix pivot tests

* add new events

* update submodule
---
 CHANGELOG.md                                  | 24 +++++-
 core/Columns/Dimension.php                    | 85 +++++++++++++------
 core/Menu/MenuAdmin.php                       |  6 --
 core/Menu/MenuTop.php                         |  6 --
 core/Plugin/ReportsProvider.php               | 37 ++++++++
 core/Segment.php                              |  4 -
 core/Tracker/Action.php                       | 12 ---
 core/Tracker/GoalManager.php                  | 31 +------
 core/Tracker/Visit.php                        | 34 --------
 core/Tracker/VisitorRecognizer.php            |  2 +-
 core/ViewDataTable/Factory.php                | 20 +----
 core/ViewDataTable/Manager.php                | 37 ++++----
 plugins/API/SegmentMetadata.php               | 48 -----------
 .../CoreVisualizations/CoreVisualizations.php |  5 +-
 plugins/CustomDimensions                      |  2 +-
 plugins/CustomVariables/Columns/Base.php      | 26 +++++-
 .../Columns/CustomVariableName.php            |  1 +
 .../Columns/CustomVariableValue.php           |  1 +
 plugins/CustomVariables/CustomVariables.php   | 52 ++----------
 plugins/CustomVariables/Segment.php           | 21 +++++
 .../tests/Integration/CustomVariablesTest.php |  7 +-
 plugins/Goals/Goals.php                       | 66 +++-----------
 plugins/Login/SessionInitializer.php          | 39 ---------
 .../Integration/Columns/DimensionTest.php     | 10 ++-
 .../DataTable/Filter/PivotByDimensionTest.php |  6 ++
 .../screenshot-override/override.css          |  6 +-
 26 files changed, 229 insertions(+), 359 deletions(-)
 create mode 100644 plugins/CustomVariables/Segment.php

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 44e75d7235..51cf8d2525 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -49,7 +49,23 @@ The Product Changelog at **[piwik.org/changelog](http://piwik.org/changelog)** l
 * The creation of settings has slightly changed to improve performance. It is now possible to create new settings via the method `$this->makeSetting()` see `Piwik\Plugins\ExampleSettingsPlugin\SystemSettings` for an example.
 * It is no possible to define an introduction text for settings.
 * If requesting multipe periods for one report, the keys that define the range are no longer translated. For example before 3.0 an API response may contain: `<result date="From 2010-02-01 to 2010-02-07">` which is now `<result date="2010-02-01,2010-02-07">`.
-
+* The following deprecated events have been removed as mentioned.
+ * `Tracker.existingVisitInformation` Use [dimensions](http://developer.piwik.org/guides/dimensions) instead of using `Tracker` events.
+ * `Tracker.newVisitorInformation`
+ * `Tracker.recordAction`
+ * `Tracker.recordEcommerceGoal`
+ * `Tracker.recordStandardGoals`
+ * `API.getSegmentDimensionMetadata` Define segments in [Dimension](http://developer.piwik.org/guides/dimensions) instead
+ * `Menu.Admin.addItems` Create a [Menu](http://developer.piwik.org/guides/menus) instead of using `Menu` events
+ * `Menu.Reporting.addItems`
+ * `Menu.Top.addItems`
+ * `ViewDataTable.addViewDataTable` Create a [Visualization](http://developer.piwik.org/guides/visualizing-report-data) instead
+ * `ViewDataTable.getDefaultType` Specify the default type in a [Report](http://developer.piwik.org/guides/custom-reports) instead
+ * `Goals.getReportsWithGoalMetrics` Specify a report has goal metrics in a [Report](http://developer.piwik.org/guides/custom-reports) instead
+ * `Login.authenticate`  Create a custom SessionInitializer instead of using `Login` events
+ * `Login.initSession.end`
+ * `Login.authenticate.successful`
+ 
 Read more about migrating a plugin from Piwik 2.X to Piwik 3 on our [Migration guide](https://developer.piwik.org/guides/migrate-piwik-2-to-3).
 
 ### Deprecations
@@ -67,6 +83,12 @@ Read more about migrating a plugin from Piwik 2.X to Piwik 3 on our [Migration g
 * The JavaScript AjaxHelper has a new method `ajaxHelper.withTokenInUrl()` to easily send a token along a XHR. Within the Controller the existence of this token can be checked via `$this->checkTokenInUrl();` to prevent CSRF attacks.
 * The new class `Piwik\Updater\Migration\Factory` lets you easily create migrations that can be executed during an update. For example database or plugin related migrations. To generate a new update with migrations execute `./console generate:update`.
 * The new method `Piwik\Updater::executeMigration` lets you execute a single migration.
+* The following events have been added:
+ * `ViewDataTable.filterViewDataTable` let's you filter available visualizations
+ * `Dimension.addDimension` let's you add custom dimensions
+ * `Dimension.filterDimension` let's you filter any dimensions
+ * `Report.addReports` let's you add dynamically created reports
+ * `Report.filterReports` let's you filter any report
 
 ### New features
 * New "Sparklines" visualization that let's you create a widget showing multiple sparklines
diff --git a/core/Columns/Dimension.php b/core/Columns/Dimension.php
index c89ae637a5..3f31073bea 100644
--- a/core/Columns/Dimension.php
+++ b/core/Columns/Dimension.php
@@ -9,12 +9,16 @@
 namespace Piwik\Columns;
 
 use Exception;
+use Piwik\CacheId;
+use Piwik\Piwik;
 use Piwik\Plugin;
 use Piwik\Plugin\ComponentFactory;
 use Piwik\Plugin\Dimension\ActionDimension;
 use Piwik\Plugin\Dimension\ConversionDimension;
 use Piwik\Plugin\Dimension\VisitDimension;
 use Piwik\Plugin\Segment;
+use Piwik\Cache as PiwikCache;
+use Piwik\Plugin\Manager as PluginManager;
 
 /**
  * @api
@@ -171,40 +175,71 @@ abstract class Dimension
      */
     public static function getAllDimensions()
     {
-        $dimensions = array();
-
-        foreach (VisitDimension::getAllDimensions() as $dimension) {
-            $dimensions[] = $dimension;
-        }
-
-        foreach (ActionDimension::getAllDimensions() as $dimension) {
-            $dimensions[] = $dimension;
-        }
-
-        foreach (ConversionDimension::getAllDimensions() as $dimension) {
-            $dimensions[] = $dimension;
+        $cacheId = CacheId::pluginAware('AllDimensions');
+        $cache   = PiwikCache::getTransientCache();
+
+        if (!$cache->contains($cacheId)) {
+            $plugins   = PluginManager::getInstance()->getPluginsLoadedAndActivated();
+            $instances = array();
+
+            /**
+             * Triggered to add new dimensions that cannot be picked up automatically by the platform.
+             * This is useful if the plugin allows a user to create reports / dimensions dynamically. For example
+             * CustomDimensions or CustomVariables. There are a variable number of dimensions in this case and it
+             * wouldn't be really possible to create a report file for one of these dimensions as it is not known
+             * how many Custom Dimensions will exist.
+             *
+             * **Example**
+             *
+             *     public function addDimension(&$dimensions)
+             *     {
+             *         $dimensions[] = new MyCustomDimension();
+             *     }
+             *
+             * @param Dimension[] $reports An array of dimensions
+             */
+            Piwik::postEvent('Dimension.addDimensions', array(&$instances));
+
+            foreach ($plugins as $plugin) {
+                foreach (self::getDimensions($plugin) as $instance) {
+                    $instances[] = $instance;
+                }
+            }
+
+            /**
+             * Triggered to filter / restrict dimensions.
+             *
+             * **Example**
+             *
+             *     public function filterDimensions(&$dimensions)
+             *     {
+             *         foreach ($dimensions as $index => $dimension) {
+             *              if ($dimension->getName() === 'Page URL') {}
+             *                  unset($dimensions[$index]); // remove this dimension
+             *              }
+             *         }
+             *     }
+             *
+             * @param Dimension[] $dimensions An array of dimensions
+             */
+            Piwik::postEvent('Dimension.filterDimensions', array(&$instances));
+
+            $cache->save($cacheId, $instances);
         }
 
-        return $dimensions;
+        return $cache->fetch($cacheId);
     }
 
     public static function getDimensions(Plugin $plugin)
     {
-        $dimensions = array();
-
-        foreach (VisitDimension::getDimensions($plugin) as $dimension) {
-            $dimensions[] = $dimension;
-        }
-
-        foreach (ActionDimension::getDimensions($plugin) as $dimension) {
-            $dimensions[] = $dimension;
-        }
+        $dimensions = $plugin->findMultipleComponents('Columns', '\\Piwik\\Columns\\Dimension');
+        $instances  = array();
 
-        foreach (ConversionDimension::getDimensions($plugin) as $dimension) {
-            $dimensions[] = $dimension;
+        foreach ($dimensions as $dimension) {
+            $instances[] = new $dimension();
         }
 
-        return $dimensions;
+        return $instances;
     }
 
     /**
diff --git a/core/Menu/MenuAdmin.php b/core/Menu/MenuAdmin.php
index e13dfe2c6f..48951171b2 100644
--- a/core/Menu/MenuAdmin.php
+++ b/core/Menu/MenuAdmin.php
@@ -128,12 +128,6 @@ class MenuAdmin extends MenuAbstract
     {
         if (!$this->menu) {
 
-            /**
-             * @ignore
-             * @deprecated
-             */
-            Piwik::postEvent('Menu.Admin.addItems', array());
-
             foreach ($this->getAllMenus() as $menu) {
                 $menu->configureAdminMenu($this);
             }
diff --git a/core/Menu/MenuTop.php b/core/Menu/MenuTop.php
index 47a62640fb..bd97c1b84a 100644
--- a/core/Menu/MenuTop.php
+++ b/core/Menu/MenuTop.php
@@ -66,12 +66,6 @@ class MenuTop extends MenuAbstract
     {
         if (!$this->menu) {
 
-            /**
-             * @ignore
-             * @deprecated
-             */
-            Piwik::postEvent('Menu.Top.addItems', array());
-
             foreach ($this->getAllMenus() as $menu) {
                 $menu->configureTopMenu($this);
             }
diff --git a/core/Plugin/ReportsProvider.php b/core/Plugin/ReportsProvider.php
index 1a00c0aa7c..f134009881 100644
--- a/core/Plugin/ReportsProvider.php
+++ b/core/Plugin/ReportsProvider.php
@@ -10,6 +10,7 @@ namespace Piwik\Plugin;
 
 use Piwik\CacheId;
 use Piwik\Category\CategoryList;
+use Piwik\Piwik;
 use Piwik\Plugin;
 use Piwik\Cache as PiwikCache;
 
@@ -86,10 +87,46 @@ class ReportsProvider
         if (!$cache->contains($cacheId)) {
             $instances = array();
 
+            /**
+             * Triggered to add new reports that cannot be picked up automatically by the platform.
+             * This is useful if the plugin allows a user to create reports / dimensions dynamically. For example
+             * CustomDimensions or CustomVariables. There are a variable number of dimensions in this case and it
+             * wouldn't be really possible to create a report file for one of these dimensions as it is not known
+             * how many Custom Dimensions will exist.
+             *
+             * **Example**
+             *
+             *     public function addReport(&$reports)
+             *     {
+             *         $reports[] = new MyCustomReport();
+             *     }
+             *
+             * @param Report[] $reports An array of reports
+             */
+            Piwik::postEvent('Report.addReports', array(&$instances));
+
             foreach ($reports as $report) {
                 $instances[] = new $report();
             }
 
+            /**
+             * Triggered to filter / restrict reports.
+             *
+             * **Example**
+             *
+             *     public function filterReports(&$reports)
+             *     {
+             *         foreach ($reports as $index => $report) {
+             *              if ($report->getCategory() === 'Actions') {}
+             *                  unset($reports[$index]); // remove all reports having this action
+             *              }
+             *         }
+             *     }
+             *
+             * @param Report[] $reports An array of reports
+             */
+            Piwik::postEvent('Report.filterReports', array(&$instances));
+
             usort($instances, array($this, 'sort'));
 
             $cache->save($cacheId, $instances);
diff --git a/core/Segment.php b/core/Segment.php
index 0ba687740e..81c661278d 100644
--- a/core/Segment.php
+++ b/core/Segment.php
@@ -21,10 +21,6 @@ use Piwik\Segment\SegmentExpression;
  * select visits that have a specific browser or come from a specific
  * country, or both.
  *
- * Individual segment dimensions (such as `browserCode` and `countryCode`)
- * are defined by plugins. Read about the {@hook API.getSegmentDimensionMetadata}
- * event to learn more.
- *
  * Plugins that aggregate data stored in Piwik can support segments by
  * using this class when generating aggregation SQL queries.
  *
diff --git a/core/Tracker/Action.php b/core/Tracker/Action.php
index 143e53ad57..8326df8deb 100644
--- a/core/Tracker/Action.php
+++ b/core/Tracker/Action.php
@@ -400,18 +400,6 @@ abstract class 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));
     }
 
     public function writeDebugInfo()
diff --git a/core/Tracker/GoalManager.php b/core/Tracker/GoalManager.php
index 3e1312fef3..3721957732 100644
--- a/core/Tracker/GoalManager.php
+++ b/core/Tracker/GoalManager.php
@@ -342,22 +342,6 @@ class GoalManager
         if ($recorded) {
             $this->recordEcommerceItems($conversion, $items);
         }
-
-        /**
-         * Triggered after successfully persisting an ecommerce conversion.
-         *
-         * _Note: Subscribers should be wary of doing any expensive computation here as it may slow
-         * the tracker down._
-         *
-         * This event is deprecated, use [Dimensions](http://developer.piwik.org/guides/dimensions) instead.
-         *
-         * @param array $conversion The conversion entity that was just persisted. See what information
-         *                          it contains [here](/guides/persistence-and-the-mysql-backend#conversions).
-         * @param array $visitInformation The visit entity that we are tracking a conversion for. See what
-         *                                information it contains [here](/guides/persistence-and-the-mysql-backend#visits).
-         * @deprecated
-         */
-        Piwik::postEvent('Tracker.recordEcommerceGoal', array($conversion, $visitProperties->getProperties()));
     }
 
     /**
@@ -693,20 +677,6 @@ class GoalManager
             $conversion = $this->triggerHookOnDimensions($request, $conversionDimensions, 'onGoalConversion', $visitor, $action, $conversion);
 
             $this->insertNewConversion($conversion, $visitProperties->getProperties(), $request);
-
-            /**
-             * Triggered after successfully recording a non-ecommerce conversion.
-             *
-             * _Note: Subscribers should be wary of doing any expensive computation here as it may slow
-             * the tracker down._
-             *
-             * This event is deprecated, use [Dimensions](http://developer.piwik.org/guides/dimensions) instead.
-             *
-             * @param array $conversion The conversion entity that was just persisted. See what information
-             *                          it contains [here](/guides/persistence-and-the-mysql-backend#conversions).
-             * @deprecated
-             */
-            Piwik::postEvent('Tracker.recordStandardGoals', array($conversion));
         }
     }
 
@@ -732,6 +702,7 @@ class GoalManager
          *                                information it contains [here](/guides/persistence-and-the-mysql-backend#visits).
          * @param \Piwik\Tracker\Request $request An object describing the tracking request being processed.
          * @deprecated
+         * @ignore
          */
         Piwik::postEvent('Tracker.newConversionInformation', array(&$conversion, $visitInformation, $request));
 
diff --git a/core/Tracker/Visit.php b/core/Tracker/Visit.php
index 9de1490424..3d306a71f8 100644
--- a/core/Tracker/Visit.php
+++ b/core/Tracker/Visit.php
@@ -211,22 +211,6 @@ class Visit implements VisitInterface
             $this->visitProperties->setProperty($name, $value);
         }
 
-        /**
-         * Triggered before a [visit entity](/guides/persistence-and-the-mysql-backend#visits) is updated when
-         * tracking an action for an existing visit.
-         *
-         * This event can be used to modify the visit properties that will be updated before the changes
-         * are persisted.
-         *
-         * This event is deprecated, use [Dimensions](http://developer.piwik.org/guides/dimensions) instead.
-         *
-         * @param array &$valuesToUpdate Visit entity properties that will be updated.
-         * @param array $visit The entire visit entity. Read [this](/guides/persistence-and-the-mysql-backend#visits)
-         *                     to see what it contains.
-         * @deprecated
-         */
-        Piwik::postEvent('Tracker.existingVisitInformation', array(&$valuesToUpdate, $this->visitProperties->getProperties()));
-
         foreach ($this->requestProcessors as $processor) {
             $processor->onExistingVisit($valuesToUpdate, $this->visitProperties, $this->request);
         }
@@ -278,24 +262,6 @@ class Visit implements VisitInterface
             $this->triggerHookOnDimensions($dimensions, 'onConvertedVisit');
         }
 
-        $properties = &$this->visitProperties->getProperties();
-
-        /**
-         * Triggered before a new [visit entity](/guides/persistence-and-the-mysql-backend#visits) is persisted.
-         *
-         * This event can be used to modify the visit entity or add new information to it before it is persisted.
-         * The UserCountry plugin, for example, uses this event to add location information for each visit.
-         *
-         * This event is deprecated, use [Dimensions](http://developer.piwik.org/guides/dimensions) instead.
-         *
-         * @param array &$visit The visit entity. Read [this](/guides/persistence-and-the-mysql-backend#visits) to see
-         *                      what information it contains.
-         * @param \Piwik\Tracker\Request $request An object describing the tracking request being processed.
-         *
-         * @deprecated
-         */
-        Piwik::postEvent('Tracker.newVisitorInformation', array(&$properties, $this->request));
-
         foreach ($this->requestProcessors as $processor) {
             $processor->onNewVisit($this->visitProperties, $this->request);
         }
diff --git a/core/Tracker/VisitorRecognizer.php b/core/Tracker/VisitorRecognizer.php
index d5f5e3c502..a21ea063e0 100644
--- a/core/Tracker/VisitorRecognizer.php
+++ b/core/Tracker/VisitorRecognizer.php
@@ -249,7 +249,7 @@ class VisitorRecognizer
              *
              * This event is deprecated, use [Dimensions](http://developer.piwik.org/guides/dimensions) instead.
              *
-             * @deprecated 
+             * @deprecated
              */
             $this->eventDispatcher->postEvent('Tracker.getVisitFieldsToPersist', array(&$fields));
 
diff --git a/core/ViewDataTable/Factory.php b/core/ViewDataTable/Factory.php
index c20bf0fb97..90a44281e4 100644
--- a/core/ViewDataTable/Factory.php
+++ b/core/ViewDataTable/Factory.php
@@ -190,8 +190,7 @@ class Factory
             return $report->getDefaultTypeViewDataTable();
         }
 
-        $defaultViewTypes = self::getDefaultTypeViewDataTable();
-        return isset($defaultViewTypes[$apiAction]) ? $defaultViewTypes[$apiAction] : false;
+        return false;
     }
 
     /**
@@ -209,23 +208,6 @@ class Factory
         return false;
     }
 
-    /**
-     * Returns a list of default viewDataTables ID to use when determining which visualization to use for multiple
-     * reports.
-     */
-    private static function getDefaultTypeViewDataTable()
-    {
-        if (null === self::$defaultViewTypes) {
-            self::$defaultViewTypes = array();
-            /**
-             * @ignore
-             */
-            Piwik::postEvent('ViewDataTable.getDefaultType', array(&self::$defaultViewTypes));
-        }
-
-        return self::$defaultViewTypes;
-    }
-
     /**
      * @param string $klass
      * @param string $controllerAction
diff --git a/core/ViewDataTable/Manager.php b/core/ViewDataTable/Manager.php
index 23d5f46790..d087ad7c70 100644
--- a/core/ViewDataTable/Manager.php
+++ b/core/ViewDataTable/Manager.php
@@ -78,25 +78,6 @@ class Manager
         /** @var string[] $visualizations */
         $visualizations = PluginManager::getInstance()->findMultipleComponents('Visualizations', $klassToExtend);
 
-        /**
-         * Triggered when gathering all available DataTable visualizations.
-         *
-         * Plugins that want to expose new DataTable visualizations should subscribe to
-         * this event and add visualization class names to the incoming array.
-         *
-         * **Example**
-         *
-         *     public function addViewDataTable(&$visualizations)
-         *     {
-         *         $visualizations[] = 'Piwik\\Plugins\\MyPlugin\\MyVisualization';
-         *     }
-         *
-         * @param array &$visualizations The array of all available visualizations.
-         * @ignore
-         * @deprecated since 2.5.0 Place visualization in a "Visualizations" directory instead.
-         */
-        Piwik::postEvent('ViewDataTable.addViewDataTable', array(&$visualizations));
-
         $result = array();
 
         foreach ($visualizations as $viz) {
@@ -117,6 +98,24 @@ class Manager
             $result[$vizId] = $viz;
         }
 
+        /**
+         * Triggered to filter available DataTable visualizations.
+         *
+         * Plugins that want to disable certain visualizations should subscribe to
+         * this event and remove visualizations from the incoming array.
+         *
+         * **Example**
+         *
+         *     public function filterViewDataTable(&$visualizations)
+         *     {
+         *         unset($visualizations[HtmlTable::ID]);
+         *     }
+         *
+         * @param array &$visualizations An array of all available visualizations indexed by visualization ID.
+         * @since Piwik 3.0.0
+         */
+        Piwik::postEvent('ViewDataTable.filterViewDataTable', array(&$result));
+
         $cache->save($cacheId, $result);
 
         return $result;
diff --git a/plugins/API/SegmentMetadata.php b/plugins/API/SegmentMetadata.php
index 4be514978c..fbe73a774f 100644
--- a/plugins/API/SegmentMetadata.php
+++ b/plugins/API/SegmentMetadata.php
@@ -27,54 +27,6 @@ class SegmentMetadata
             }
         }
 
-        /**
-         * Triggered when gathering all available segment dimensions.
-         *
-         * This event can be used to make new segment dimensions available.
-         *
-         * **Example**
-         *
-         *     public function getSegmentsMetadata(&$segments, $idSites)
-         *     {
-         *         $segments[] = array(
-         *             'type'           => 'dimension',
-         *             'category'       => Piwik::translate('General_Visit'),
-         *             'name'           => 'General_VisitorIP',
-         *             'segment'        => 'visitIp',
-         *             'acceptedValues' => '13.54.122.1, etc.',
-         *             'sqlSegment'     => 'log_visit.location_ip',
-         *             'sqlFilter'      => array('Piwik\IP', 'P2N'),
-         *             'permission'     => $isAuthenticatedWithViewAccess,
-         *         );
-         *     }
-         *
-         * @param array &$dimensions The list of available segment dimensions. Append to this list to add
-         *                           new segments. Each element in this list must contain the
-         *                           following information:
-         *
-         *                           - **type**: Either `'metric'` or `'dimension'`. `'metric'` means
-         *                                       the value is a numeric and `'dimension'` means it is
-         *                                       a string. Also, `'metric'` values will be displayed
-         *                                       under **Visit (metrics)** in the Segment Editor.
-         *                           - **category**: The segment category name. This can be an existing
-         *                                           segment category visible in the segment editor.
-         *                           - **name**: The pretty name of the segment. Can be a translation token.
-         *                           - **segment**: The segment name, eg, `'visitIp'` or `'searches'`.
-         *                           - **acceptedValues**: A string describing one or two exacmple values, eg
-         *                                                 `'13.54.122.1, etc.'`.
-         *                           - **sqlSegment**: The table column this segment will segment by.
-         *                                             For example, `'log_visit.location_ip'` for the
-         *                                             **visitIp** segment.
-         *                           - **sqlFilter**: A PHP callback to apply to segment values before
-         *                                            they are used in SQL.
-         *                           - **permission**: True if the current user has view access to this
-         *                                             segment, false if otherwise.
-         * @param array $idSites The list of site IDs we're getting the available segments
-         *                       for. Some segments (such as Goal segments) depend on the
-         *                       site.
-         */
-        Piwik::postEvent('API.getSegmentDimensionMetadata', array(&$segments, $idSites));
-
         $segments[] = array(
             'type'           => 'dimension',
             'category'       => Piwik::translate('General_Visit'),
diff --git a/plugins/CoreVisualizations/CoreVisualizations.php b/plugins/CoreVisualizations/CoreVisualizations.php
index 0aec35fb3e..b832903228 100644
--- a/plugins/CoreVisualizations/CoreVisualizations.php
+++ b/plugins/CoreVisualizations/CoreVisualizations.php
@@ -9,7 +9,6 @@
 
 namespace Piwik\Plugins\CoreVisualizations;
 
-use Piwik\Common;
 use Piwik\ViewDataTable\Manager as ViewDataTableManager;
 
 require_once PIWIK_INCLUDE_PATH . '/plugins/CoreVisualizations/JqplotDataGenerator.php';
@@ -21,7 +20,7 @@ require_once PIWIK_INCLUDE_PATH . '/plugins/CoreVisualizations/JqplotDataGenerat
 class CoreVisualizations extends \Piwik\Plugin
 {
     /**
-     * @see Piwik\Plugin::registerEvents
+     * @see \Piwik\Plugin::registerEvents
      */
     public function registerEvents()
     {
@@ -29,7 +28,7 @@ class CoreVisualizations extends \Piwik\Plugin
             'AssetManager.getStylesheetFiles'        => 'getStylesheetFiles',
             'AssetManager.getJavaScriptFiles'        => 'getJsFiles',
             'Translate.getClientSideTranslationKeys' => 'getClientSideTranslationKeys',
-            'UsersManager.deleteUser'                => 'deleteUser'
+            'UsersManager.deleteUser'                => 'deleteUser',
         );
     }
 
diff --git a/plugins/CustomDimensions b/plugins/CustomDimensions
index 8e088b3530..7bbbfd6734 160000
--- a/plugins/CustomDimensions
+++ b/plugins/CustomDimensions
@@ -1 +1 @@
-Subproject commit 8e088b3530dd85d2632ab2e264d2cb7492532ba0
+Subproject commit 7bbbfd673469bea91c9164e3a4feeee1368e6ff8
diff --git a/plugins/CustomVariables/Columns/Base.php b/plugins/CustomVariables/Columns/Base.php
index 4c6a4ea542..4cebcb0688 100644
--- a/plugins/CustomVariables/Columns/Base.php
+++ b/plugins/CustomVariables/Columns/Base.php
@@ -8,10 +8,9 @@
 
 namespace Piwik\Plugins\CustomVariables\Columns;
 
-use Piwik\DataTable;
 use Piwik\Piwik;
 use Piwik\Plugin\Dimension\VisitDimension;
-use Piwik\Plugin\Segment;
+use Piwik\Plugins\CustomVariables\Segment;
 use Piwik\Plugins\CustomVariables\CustomVariables;
 
 class Base extends VisitDimension
@@ -24,7 +23,6 @@ class Base extends VisitDimension
         $segment->setType('dimension');
         $segment->setSegment('customVariable' . $segmentNameSuffix);
         $segment->setName($this->getName() . ' (' . Piwik::translate('CustomVariables_ScopeVisit') . ')');
-        $segment->setCategory('CustomVariables_CustomVariables');
         $segment->setUnionOfSegments($this->getSegmentColumns('customVariable' . $segmentNameSuffix, $numCustomVariables));
         $this->addSegment($segment);
 
@@ -32,9 +30,29 @@ class Base extends VisitDimension
         $segment->setType('dimension');
         $segment->setSegment('customVariablePage' . $segmentNameSuffix);
         $segment->setName($this->getName() . ' (' . Piwik::translate('CustomVariables_ScopePage') . ')');
-        $segment->setCategory('CustomVariables_CustomVariables');
         $segment->setUnionOfSegments($this->getSegmentColumns('customVariablePage' . $segmentNameSuffix, $numCustomVariables));
         $this->addSegment($segment);
+
+        $segmentSuffix = 'v';
+        if (strtolower($segmentNameSuffix) === 'name') {
+            $segmentSuffix = 'k';
+        }
+
+        for ($i = 1; $i <= $numCustomVariables; $i++) {
+            $segment = new Segment();
+            $segment->setSegment('customVariable' . $segmentNameSuffix . $i);
+            $segment->setSqlSegment('log_visit.custom_var_' . $segmentSuffix . $i);
+            $segment->setName(Piwik::translate('CustomVariables_ColumnCustomVariable' . $segmentNameSuffix) . ' ' . $i
+                    . ' (' . Piwik::translate('CustomVariables_ScopeVisit') . ')');
+            $this->addSegment($segment);
+
+            $segment = new Segment();
+            $segment->setSegment('customVariablePage' . $segmentNameSuffix . $i);
+            $segment->setSqlSegment('log_link_visit_action.custom_var_' . $segmentSuffix . $i);
+            $segment->setName(Piwik::translate('CustomVariables_ColumnCustomVariable' . $segmentNameSuffix) . ' ' . $i
+                    . ' (' . Piwik::translate('CustomVariables_ScopePage') . ')');
+            $this->addSegment($segment);
+        }
     }
 
     private function getSegmentColumns($column, $numCustomVariables)
diff --git a/plugins/CustomVariables/Columns/CustomVariableName.php b/plugins/CustomVariables/Columns/CustomVariableName.php
index b42f2e8ae7..982ce1e264 100644
--- a/plugins/CustomVariables/Columns/CustomVariableName.php
+++ b/plugins/CustomVariables/Columns/CustomVariableName.php
@@ -21,4 +21,5 @@ class CustomVariableName extends Base
     {
         return Piwik::translate('CustomVariables_ColumnCustomVariableName');
     }
+
 }
\ No newline at end of file
diff --git a/plugins/CustomVariables/Columns/CustomVariableValue.php b/plugins/CustomVariables/Columns/CustomVariableValue.php
index a565a8136c..10c146f2e1 100644
--- a/plugins/CustomVariables/Columns/CustomVariableValue.php
+++ b/plugins/CustomVariables/Columns/CustomVariableValue.php
@@ -21,4 +21,5 @@ class CustomVariableValue extends Base
     {
         return Piwik::translate('CustomVariables_ColumnCustomVariableValue');
     }
+
 }
\ No newline at end of file
diff --git a/plugins/CustomVariables/CustomVariables.php b/plugins/CustomVariables/CustomVariables.php
index 9059482c33..78a779e5f9 100644
--- a/plugins/CustomVariables/CustomVariables.php
+++ b/plugins/CustomVariables/CustomVariables.php
@@ -8,24 +8,22 @@
  */
 namespace Piwik\Plugins\CustomVariables;
 
-use Piwik\ArchiveProcessor;
-use Piwik\Piwik;
 use Piwik\Tracker\Cache;
-use Piwik\Tracker;
 
 class CustomVariables extends \Piwik\Plugin
 {
+    const MAX_NUM_CUSTOMVARS_CACHEKEY = 'CustomVariables.MaxNumCustomVariables';
+
     /**
-     * @see Piwik\Plugin::registerEvents
+     * @see \Piwik\Plugin::registerEvents
      */
     public function registerEvents()
     {
         return array(
-            'API.getSegmentDimensionMetadata' => 'getSegmentsMetadata',
             'Live.getAllVisitorDetails'       => 'extendVisitorDetails',
             'AssetManager.getJavaScriptFiles' => 'getJsFiles',
             'Translate.getClientSideTranslationKeys' => 'getClientSideTranslationKeys',
-            'AssetManager.getStylesheetFiles'        => 'getStylesheetFiles',
+            'AssetManager.getStylesheetFiles'  => 'getStylesheetFiles',
         );
     }
 
@@ -77,7 +75,7 @@ class CustomVariables extends \Piwik\Plugin
     public static function getNumUsableCustomVariables()
     {
         $cache    = Cache::getCacheGeneral();
-        $cacheKey = 'CustomVariables.NumUsableCustomVariables';
+        $cacheKey = self::MAX_NUM_CUSTOMVARS_CACHEKEY;
 
         if (!array_key_exists($cacheKey, $cache)) {
 
@@ -107,46 +105,6 @@ class CustomVariables extends \Piwik\Plugin
         return $cache[$cacheKey];
     }
 
-    public function getSegmentsMetadata(&$segments)
-    {
-        $maxCustomVariables = self::getNumUsableCustomVariables();
-
-        for ($i = 1; $i <= $maxCustomVariables; $i++) {
-            $segments[] = array(
-                'type'       => 'dimension',
-                'category'   => 'CustomVariables_CustomVariables',
-                'name'       => Piwik::translate('CustomVariables_ColumnCustomVariableName') . ' ' . $i
-                    . ' (' . Piwik::translate('CustomVariables_ScopeVisit') . ')',
-                'segment'    => 'customVariableName' . $i,
-                'sqlSegment' => 'log_visit.custom_var_k' . $i,
-            );
-            $segments[] = array(
-                'type'       => 'dimension',
-                'category'   => 'CustomVariables_CustomVariables',
-                'name'       => Piwik::translate('CustomVariables_ColumnCustomVariableValue') . ' ' . $i
-                    . ' (' . Piwik::translate('CustomVariables_ScopeVisit') . ')',
-                'segment'    => 'customVariableValue' . $i,
-                'sqlSegment' => 'log_visit.custom_var_v' . $i,
-            );
-            $segments[] = array(
-                'type'       => 'dimension',
-                'category'   => 'CustomVariables_CustomVariables',
-                'name'       => Piwik::translate('CustomVariables_ColumnCustomVariableName') . ' ' . $i
-                    . ' (' . Piwik::translate('CustomVariables_ScopePage') . ')',
-                'segment'    => 'customVariablePageName' . $i,
-                'sqlSegment' => 'log_link_visit_action.custom_var_k' . $i,
-            );
-            $segments[] = array(
-                'type'       => 'dimension',
-                'category'   => 'CustomVariables_CustomVariables',
-                'name'       => Piwik::translate('CustomVariables_ColumnCustomVariableValue') . ' ' . $i
-                    . ' (' . Piwik::translate('CustomVariables_ScopePage') . ')',
-                'segment'    => 'customVariablePageValue' . $i,
-                'sqlSegment' => 'log_link_visit_action.custom_var_v' . $i,
-            );
-        }
-    }
-
     public function getClientSideTranslationKeys(&$translationKeys)
     {
         $translationKeys[] = 'CustomVariables_CustomVariables';
diff --git a/plugins/CustomVariables/Segment.php b/plugins/CustomVariables/Segment.php
new file mode 100644
index 0000000000..fc1c3fd0a7
--- /dev/null
+++ b/plugins/CustomVariables/Segment.php
@@ -0,0 +1,21 @@
+<?php
+/**
+ * Piwik - free/libre analytics platform
+ *
+ * @link http://piwik.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ *
+ */
+namespace Piwik\Plugins\CustomVariables;
+
+/**
+ * CustomVariables segment base class
+ */
+class Segment extends \Piwik\Plugin\Segment
+{
+    protected  function init()
+    {
+        $this->setCategory('CustomVariables_CustomVariables');
+    }
+}
+
diff --git a/plugins/CustomVariables/tests/Integration/CustomVariablesTest.php b/plugins/CustomVariables/tests/Integration/CustomVariablesTest.php
index e24bbf0090..421b19bd0d 100644
--- a/plugins/CustomVariables/tests/Integration/CustomVariablesTest.php
+++ b/plugins/CustomVariables/tests/Integration/CustomVariablesTest.php
@@ -6,7 +6,8 @@
  * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
  */
 
-namespace Piwik\Plugins\CustomVariables\tests;
+namespace Piwik\Plugins\CustomVariables\tests\Integration;
+
 use Piwik\Plugins\CustomVariables\CustomVariables;
 use Piwik\Plugins\CustomVariables\Model;
 use Piwik\Tracker\Cache;
@@ -30,13 +31,13 @@ class CustomVariablesTest extends IntegrationTestCase
         CustomVariables::getNumUsableCustomVariables();
         $cache = Cache::getCacheGeneral();
 
-        $this->assertSame(5, $cache['CustomVariables.NumUsableCustomVariables']);
+        $this->assertSame(5, $cache[CustomVariables::MAX_NUM_CUSTOMVARS_CACHEKEY]);
     }
 
     public function test_getNumUsableCustomVariables_ShouldReadFromCacheIfPossible()
     {
         $cache = Cache::getCacheGeneral();
-        $cache['CustomVariables.NumUsableCustomVariables'] = 10;
+        $cache[CustomVariables::MAX_NUM_CUSTOMVARS_CACHEKEY] = 10;
         Cache::setCacheGeneral($cache);
 
         $this->assertSame(10, CustomVariables::getNumUsableCustomVariables());
diff --git a/plugins/Goals/Goals.php b/plugins/Goals/Goals.php
index b478be5b16..0d228cadb6 100644
--- a/plugins/Goals/Goals.php
+++ b/plugins/Goals/Goals.php
@@ -67,7 +67,7 @@ class Goals extends \Piwik\Plugin
     }
 
     /**
-     * @see Piwik\Plugin::registerEvents
+     * @see \Piwik\Plugin::registerEvents
      */
     public function registerEvents()
     {
@@ -77,7 +77,6 @@ class Goals extends \Piwik\Plugin
             'Tracker.Cache.getSiteAttributes'        => 'fetchGoalsFromDb',
             'API.getReportMetadata.end'              => 'getReportMetadataEnd',
             'SitesManager.deleteSite.end'            => 'deleteSiteGoals',
-            'Goals.getReportsWithGoalMetrics'        => 'getActualReportsWithGoalMetrics',
             'Translate.getClientSideTranslationKeys' => 'getClientSideTranslationKeys',
             'Metrics.getDefaultMetricTranslations'   => 'addMetricTranslations',
             'Category.addSubcategories' => 'addSubcategories'
@@ -194,67 +193,28 @@ class Goals extends \Piwik\Plugin
                     'name'     => $report->getName(),
                     'module'   => $report->getModule(),
                     'action'   => $report->getAction(),
+                    'parameters' => $report->getParameters()
                 );
             }
         }
 
-        /**
-         * Triggered when gathering all reports that contain Goal metrics. The list of reports
-         * will be displayed on the left column of the bottom of every _Goals_ page.
-         *
-         * If plugins define reports that contain goal metrics (such as **conversions** or **revenue**),
-         * they can use this event to make sure their reports can be viewed on Goals pages.
-         *
-         * **Example**
-         *
-         *     public function getReportsWithGoalMetrics(&$reports)
-         *     {
-         *         $reports[] = array(
-         *             'category' => Piwik::translate('MyPlugin_myReportCategory'),
-         *             'name' => Piwik::translate('MyPlugin_myReportDimension'),
-         *             'module' => 'MyPlugin',
-         *             'action' => 'getMyReport'
-         *         );
-         *     }
-         *
-         * @param array &$reportsWithGoals The list of arrays describing reports that have Goal metrics.
-         *                                 Each element of this array must be an array with the following
-         *                                 properties:
-         *
-         *                                 - **category**: The report category. This should be a translated string.
-         *                                 - **name**: The report's translated name.
-         *                                 - **module**: The plugin the report is in, eg, `'UserCountry'`.
-         *                                 - **action**: The API method of the report, eg, `'getCountry'`.
-         * @ignore
-         * @deprecated since 2.5.0
-         */
-        Piwik::postEvent('Goals.getReportsWithGoalMetrics', array(&$reportsWithGoals));
-
-        return $reportsWithGoals;
-    }
-
-    /**
-     * This function executes when the 'Goals.getReportsWithGoalMetrics' event fires. It
-     * adds the 'visits to conversion' report metadata to the list of goal reports so
-     * this report will be displayed.
-     */
-    public function getActualReportsWithGoalMetrics(&$dimensions)
-    {
         $reportWithGoalMetrics = array(
             array('category' => 'General_Visit',
-                  'name'     => Piwik::translate('Goals_VisitsUntilConv'),
-                  'module'   => 'Goals',
-                  'action'   => 'getVisitsUntilConversion',
-                  'viewDataTable' => 'table',
+                'name'     => Piwik::translate('Goals_VisitsUntilConv'),
+                'module'   => 'Goals',
+                'action'   => 'getVisitsUntilConversion',
+                'viewDataTable' => 'table',
             ),
             array('category' => 'General_Visit',
-                  'name'     => Piwik::translate('Goals_DaysToConv'),
-                  'module'   => 'Goals',
-                  'action'   => 'getDaysToConversion',
-                  'viewDataTable' => 'table',
+                'name'     => Piwik::translate('Goals_DaysToConv'),
+                'module'   => 'Goals',
+                'action'   => 'getDaysToConversion',
+                'viewDataTable' => 'table',
             )
         );
-        $dimensions = array_merge($dimensions, $reportWithGoalMetrics);
+        $reportsWithGoals = array_merge($reportsWithGoals, $reportWithGoalMetrics);
+
+        return $reportsWithGoals;
     }
 
     public function getJsFiles(&$jsFiles)
diff --git a/plugins/Login/SessionInitializer.php b/plugins/Login/SessionInitializer.php
index a3c5f9a648..72013d2b8c 100644
--- a/plugins/Login/SessionInitializer.php
+++ b/plugins/Login/SessionInitializer.php
@@ -118,11 +118,6 @@ class SessionInitializer
         } else {
             $this->processSuccessfulSession($authResult, $rememberMe);
         }
-
-        /**
-         * @deprecated Create a custom SessionInitializer instead.
-         */
-        Piwik::postEvent('Login.initSession.end');
     }
 
     /**
@@ -136,29 +131,6 @@ class SessionInitializer
      */
     protected function doAuthenticateSession(AuthInterface $auth)
     {
-        $login = $auth->getLogin();
-        $tokenAuthSecret = null;
-
-        try {
-            $tokenAuthSecret = $auth->getTokenAuthSecret();
-        } catch (Exception $ex) {
-            Log::debug("SessionInitializer::doAuthenticateSession: token_auth secret for %s not available before user"
-                     . " is authenticated.", $login);
-        }
-
-        $tokenAuth = empty($tokenAuthSecret) ? null : $this->usersManagerAPI->getTokenAuth($login, $tokenAuthSecret);
-
-        /**
-         * @deprecated Create a custom SessionInitializer instead.
-         */
-        Piwik::postEvent(
-            'Login.authenticate',
-            array(
-                $auth->getLogin(),
-                $tokenAuth
-            )
-        );
-
         return $auth->authenticate();
     }
 
@@ -201,17 +173,6 @@ class SessionInitializer
      */
     protected function processSuccessfulSession(AuthResult $authResult, $rememberMe)
     {
-        /**
-         * @deprecated Create a custom SessionInitializer instead.
-         */
-        Piwik::postEvent(
-            'Login.authenticate.successful',
-            array(
-                $authResult->getIdentity(),
-                $authResult->getTokenAuth()
-            )
-        );
-
         $cookie = $this->getAuthCookie($rememberMe);
         $cookie->set('login', $authResult->getIdentity());
         $cookie->set('token_auth', $this->getHashTokenAuth($authResult->getIdentity(), $authResult->getTokenAuth()));
diff --git a/tests/PHPUnit/Integration/Columns/DimensionTest.php b/tests/PHPUnit/Integration/Columns/DimensionTest.php
index 990032af18..0e51177673 100644
--- a/tests/PHPUnit/Integration/Columns/DimensionTest.php
+++ b/tests/PHPUnit/Integration/Columns/DimensionTest.php
@@ -102,9 +102,9 @@ namespace Piwik\Tests\Integration\Columns
             $this->assertSame('', $this->dimension->getName());
         }
 
-        public function test_getAllDimensions_shouldReturnActionVisitAndConversionDimensions()
+        public function test_getAllDimensions_shouldReturnAllKindOfDimensions()
         {
-            Manager::getInstance()->loadPlugins(array('Actions', 'Events', 'DevicesDetector', 'Goals'));
+            Manager::getInstance()->loadPlugins(array('Actions', 'Events', 'DevicesDetector', 'Goals', 'CustomVariables'));
 
             $dimensions = Dimension::getAllDimensions();
 
@@ -113,6 +113,7 @@ namespace Piwik\Tests\Integration\Columns
             $foundConversion = false;
             $foundVisit      = false;
             $foundAction     = false;
+            $foundNormal     = false;
 
             foreach ($dimensions as $dimension) {
                 if ($dimension instanceof ConversionDimension) {
@@ -121,16 +122,19 @@ namespace Piwik\Tests\Integration\Columns
                     $foundAction = true;
                 } else if ($dimension instanceof VisitDimension) {
                     $foundVisit = true;
+                } else if ($dimension instanceof Dimension) {
+                    $foundNormal = true;
                 } else {
                     $this->fail('Unexpected dimension class found');
                 }
 
-                $this->assertRegExp('/Piwik.Plugins.(Actions|Events|DevicesDetector|Goals).Columns/', get_class($dimension));
+                $this->assertRegExp('/Piwik.Plugins.(Actions|Events|DevicesDetector|Goals|CustomVariables).Columns/', get_class($dimension));
             }
 
             $this->assertTrue($foundConversion);
             $this->assertTrue($foundAction);
             $this->assertTrue($foundVisit);
+            $this->assertTrue($foundNormal);
         }
 
         public function test_getDimensions_shouldReturnAllKindOfDimensionsThatBelongToASpecificPlugin()
diff --git a/tests/PHPUnit/Integration/DataTable/Filter/PivotByDimensionTest.php b/tests/PHPUnit/Integration/DataTable/Filter/PivotByDimensionTest.php
index 94fd174836..967c77a862 100644
--- a/tests/PHPUnit/Integration/DataTable/Filter/PivotByDimensionTest.php
+++ b/tests/PHPUnit/Integration/DataTable/Filter/PivotByDimensionTest.php
@@ -8,6 +8,8 @@
 namespace Piwik\Tests\Core\DataTable\Filter;
 
 use Piwik\API\Proxy;
+use Piwik\Plugins\CustomVariables\CustomVariables;
+use Piwik\Tracker\Cache;
 use Piwik\Config;
 use Piwik\DataTable;
 use Piwik\DataTable\Filter\PivotByDimension;
@@ -223,6 +225,8 @@ class PivotByDimensionTest extends IntegrationTestCase
 
     public function test_filter_CorrectlyCreatesPivotTable_WhenSubtablesHaveNoRows()
     {
+        Cache::setCacheGeneral(array(CustomVariables::MAX_NUM_CUSTOMVARS_CACHEKEY => 5));
+
         $this->loadPlugins('Referrers', 'UserCountry', 'CustomVariables');
 
         $table = $this->getTableToFilter(false);
@@ -236,6 +240,8 @@ class PivotByDimensionTest extends IntegrationTestCase
             array('label' => 'row 2'),
             array('label' => 'row 3')
         );
+
+        Cache::clearCacheGeneral();
         $this->assertTableRowsEquals($expectedRows, $table);
     }
 
diff --git a/tests/resources/screenshot-override/override.css b/tests/resources/screenshot-override/override.css
index 111b83f73c..a332017bdb 100644
--- a/tests/resources/screenshot-override/override.css
+++ b/tests/resources/screenshot-override/override.css
@@ -37,12 +37,16 @@ body > .widget {
     border-style: solid;
 }
 
+.loadingPiwik {
+    display: none !important;
+}
+
 /* do not display RSS feed widget's contents */
 #widgetExampleRssWidgetrssPiwik .rss {
     display:none;
 }
 
-body * {
+html body div *, body * {
     -webkit-transition: none !important;
     transition: none !important;
     -webkit-animation: none !important;
-- 
GitLab