diff --git a/plugins/API/API.php b/plugins/API/API.php index 23cf814768322e42ec3dc2dfa095c05a444ec76d..5ca4e2156c1f42866a8ec377d60be23eca2ecfea 100644 --- a/plugins/API/API.php +++ b/plugins/API/API.php @@ -584,14 +584,6 @@ class Piwik_API_API // set metric documentation to default if it's not set $availableReport['metricsDocumentation'] = $this->getDefaultMetricsDocumentation(); } - - // if hide/show columns specified, hide/show metrics & docs - $availableReport['metrics'] = $this->hideShowMetrics($availableReport['metrics']); - $availableReport['processedMetrics'] = $this->hideShowMetrics($availableReport['processedMetrics']); - if (isset($availableReport['metricsDocumentation'])) { - $availableReport['metricsDocumentation'] = - $this->hideShowMetrics($availableReport['metricsDocumentation']); - } } // Some plugins need to add custom metrics after all plugins hooked in @@ -623,6 +615,16 @@ class Piwik_API_API } $availableReport['metrics'] = $cleanedMetrics; + // if hide/show columns specified, hide/show metrics & docs + $availableReport['metrics'] = $this->hideShowMetrics($availableReport['metrics']); + if (isset($availableReport['processedMetrics'])) { + $availableReport['processedMetrics'] = $this->hideShowMetrics($availableReport['processedMetrics']); + } + if (isset($availableReport['metricsDocumentation'])) { + $availableReport['metricsDocumentation'] = + $this->hideShowMetrics($availableReport['metricsDocumentation']); + } + // Remove array elements that are false (to clean up API output) foreach ($availableReport as $attributeName => $attributeValue) { if (empty($attributeValue)) { @@ -1057,8 +1059,10 @@ class Piwik_API_API $meta = Piwik_API_API::getInstance()->getReportMetadata($idSite, $period, $date); foreach ($meta as $reportMeta) { // scan all *.get reports - if ($reportMeta['action'] == 'get' && !isset($reportMeta['parameters']) + if ($reportMeta['action'] == 'get' + && !isset($reportMeta['parameters']) && $reportMeta['module'] != 'API' + && !empty($reportMeta['metrics']) ) { $plugin = $reportMeta['module']; foreach ($reportMeta['metrics'] as $column => $columnTranslation) { diff --git a/tests/PHPUnit/Integration/OneVisitorTwoVisitsTest.php b/tests/PHPUnit/Integration/OneVisitorTwoVisitsTest.php index f8d1468e3956a81b80947c1e2df46e21906859dd..9bd0eb113d24dd0dcc87186e6b1a2e3685213351 100755 --- a/tests/PHPUnit/Integration/OneVisitorTwoVisitsTest.php +++ b/tests/PHPUnit/Integration/OneVisitorTwoVisitsTest.php @@ -136,6 +136,17 @@ class Test_Piwik_Integration_OneVisitorTwoVisits extends IntegrationTestCase 'avg_time_generation,nb_hits_with_time_generation', 'expanded' => '1' ))), + + // test showColumns on API.get + array('API.get', array( + 'idSite' => $idSite, + 'date' => $dateTime, + 'periods' => 'day', + 'testSuffix' => '_showColumns', + 'otherRequestParameters' => array( + 'showColumns' => 'nb_uniq_visitors,nb_pageviews,bounce_rate' + ) + )), ); } diff --git a/tests/PHPUnit/Integration/expected/test_OneVisitorTwoVisits_showColumns__API.get_day.xml b/tests/PHPUnit/Integration/expected/test_OneVisitorTwoVisits_showColumns__API.get_day.xml new file mode 100644 index 0000000000000000000000000000000000000000..cdd370d354355fdab4e8a2d3e681e6ece2cc2ee6 --- /dev/null +++ b/tests/PHPUnit/Integration/expected/test_OneVisitorTwoVisits_showColumns__API.get_day.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="utf-8" ?> +<result> + <nb_uniq_visitors>1</nb_uniq_visitors> + <bounce_rate>50%</bounce_rate> + <nb_pageviews>4</nb_pageviews> +</result> \ No newline at end of file