diff --git a/core/API/DataTablePostProcessor.php b/core/API/DataTablePostProcessor.php index 955c51acd7114d46d85271c1e580f84e100bf46c..11f41264025c235dcc3484883c9a3af5405043ee 100644 --- a/core/API/DataTablePostProcessor.php +++ b/core/API/DataTablePostProcessor.php @@ -248,11 +248,33 @@ class DataTablePostProcessor || !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 2280ea531e785dc7c3a433128f64387a1879dc6c..20201d08877d87f7a922b63ba506a9e4db872e57 100644 --- a/core/Plugin/ProcessedMetric.php +++ b/core/Plugin/ProcessedMetric.php @@ -41,6 +41,19 @@ abstract class ProcessedMetric extends Metric */ 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 f7df68aaaa4f00dc8d9564625e1a70ebc126b6d2..6847a7322d875aa9dd9b89b80c2113300a396c8d 100644 --- a/plugins/Actions/Columns/Metrics/AveragePageGenerationTime.php +++ b/plugins/Actions/Columns/Metrics/AveragePageGenerationTime.php @@ -40,6 +40,11 @@ class AveragePageGenerationTime extends ProcessedMetric 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 781625378133d7b506a15da2774af0eb521611c7..c9fd4f04c50fbef6f2e352f39301a1561ab6f3de 100755 --- a/tests/PHPUnit/System/TwoVisitorsTwoWebsitesDifferentDaysTest.php +++ b/tests/PHPUnit/System/TwoVisitorsTwoWebsitesDifferentDaysTest.php @@ -62,13 +62,7 @@ class TwoVisitorsTwoWebsitesDifferentDaysTest extends SystemTestCase $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',