diff options
author | diosmosis <benaka.moorthi@gmail.com> | 2013-04-17 12:27:00 +0400 |
---|---|---|
committer | diosmosis <benaka.moorthi@gmail.com> | 2013-04-17 12:27:00 +0400 |
commit | 08cfe92f278e987fb43ca6584b1822d61774dceb (patch) | |
tree | 73126d2f0fcbbc2923f7678e4f85c65ee17adadd | |
parent | 540a0bbed6eb9600d5f9ace55c8346b2e8938325 (diff) |
Fixes #3868, make sure show/hideColumns query params affect metrics when report metadata doesn't provide a translation for metrics, and make sure if no columns are displayed for a report, API.get doesn't fail.
-rw-r--r-- | plugins/API/API.php | 22 | ||||
-rwxr-xr-x | tests/PHPUnit/Integration/OneVisitorTwoVisitsTest.php | 11 | ||||
-rw-r--r-- | tests/PHPUnit/Integration/expected/test_OneVisitorTwoVisits_showColumns__API.get_day.xml | 6 |
3 files changed, 30 insertions, 9 deletions
diff --git a/plugins/API/API.php b/plugins/API/API.php index 23cf814768..5ca4e2156c 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 f8d1468e39..9bd0eb113d 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 0000000000..cdd370d354 --- /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 |