diff --git a/core/API/DataTablePostProcessor.php b/core/API/DataTablePostProcessor.php index 955c51acd71..11f41264025 100644 --- a/core/API/DataTablePostProcessor.php +++ b/core/API/DataTablePostProcessor.php @@ -248,11 +248,33 @@ public function applyRequestedColumnDeletion($dataTable) || !empty($showColumns) ) { $dataTable->filter('ColumnDelete', array($hideColumns, $showColumns)); + } else { + $this->removeTemporaryMetrics($dataTable); } return $dataTable; } + /** + * @param DataTableInterface $dataTable + */ + public function removeTemporaryMetrics(DataTableInterface $dataTable) + { + $allColumns = !empty($this->report) ? $this->report->getAllMetrics() : array(); + + $report = $this->report; + $dataTable->filter(function (DataTable $table) use ($report, $allColumns) { + $processedMetrics = Report::getProcessedMetricsForTable($table, $this->report); + + $allTemporaryMetrics = array(); + foreach ($processedMetrics as $metric) { + $allTemporaryMetrics = array_merge($allTemporaryMetrics, $metric->getTemporaryMetrics()); + } + + $table->filter('ColumnDelete', array($allTemporaryMetrics)); + }); + } + /** * @param DataTableInterface $dataTable * @return DataTableInterface diff --git a/core/Plugin/ProcessedMetric.php b/core/Plugin/ProcessedMetric.php index 2280ea531e7..20201d08877 100644 --- a/core/Plugin/ProcessedMetric.php +++ b/core/Plugin/ProcessedMetric.php @@ -41,6 +41,19 @@ abstract public function compute(Row $row); */ abstract public function getDependentMetrics(); + /** + * Returns the array of metrics that are necessary for computing this metric, but should not + * be displayed to the user unless explicitly requested. These metrics are intermediate + * metrics that are not really valuable to the user. On a request, if showColumns or hideColumns + * is not used, they will be removed automatically. + * + * @return string[] + */ + public function getTemporaryMetrics() + { + return array(); + } + /** * Executed before computing all processed metrics for a report. Implementers can return `false` * to skip computing this metric. diff --git a/plugins/Actions/Columns/Metrics/AveragePageGenerationTime.php b/plugins/Actions/Columns/Metrics/AveragePageGenerationTime.php index f7df68aaaa4..6847a7322d8 100644 --- a/plugins/Actions/Columns/Metrics/AveragePageGenerationTime.php +++ b/plugins/Actions/Columns/Metrics/AveragePageGenerationTime.php @@ -40,6 +40,11 @@ public function getDependentMetrics() return array('sum_time_generation', 'nb_hits_with_time_generation'); } + public function getTemporaryMetrics() + { + return array('nb_hits_with_time_generation'); + } + public function compute(Row $row) { $sumGenerationTime = $this->getMetric($row, 'sum_time_generation'); diff --git a/tests/PHPUnit/System/TwoVisitorsTwoWebsitesDifferentDaysTest.php b/tests/PHPUnit/System/TwoVisitorsTwoWebsitesDifferentDaysTest.php index 78162537813..c9fd4f04c50 100755 --- a/tests/PHPUnit/System/TwoVisitorsTwoWebsitesDifferentDaysTest.php +++ b/tests/PHPUnit/System/TwoVisitorsTwoWebsitesDifferentDaysTest.php @@ -62,13 +62,7 @@ public function getApiForTesting() $singlePeriodApi = array('VisitsSummary.get', 'Goals.get'); $periods = array('day', 'week', 'month', 'year'); -return array( - array('Goals.get', array('idSite' => 'all', - 'date' => $dateTime, - 'periods' => array('day'), - 'setDateLastN' => false, - 'testSuffix' => '_NotLastNPeriods')) -); + $result = array( // Request data for the last 6 periods and idSite=all array($apiToCall, array('idSite' => 'all',