From bbafc1c02e5debf522c1e01a308d7ab36fb728d4 Mon Sep 17 00:00:00 2001 From: mattpiwik <matthieu.aubry@gmail.com> Date: Fri, 14 Oct 2011 05:27:58 +0000 Subject: [PATCH] Refs #2670 * Fixing few bugs found by integration tests and hopefully fixing build! git-svn-id: http://dev.piwik.org/svn/trunk@5298 59fd770c-687e-43c8-a1e3-f5a4ff64c105 --- plugins/API/API.php | 9 ++------- plugins/ImageGraph/API.php | 4 ++++ plugins/ImageGraph/ImageGraph.php | 20 ++++++++++++++++--- tests/integration/Integration.php | 2 ++ ...Site_lastN__API.getProcessedReport_day.xml | 2 +- ...Site_lastN__API.getProcessedReport_day.xml | 2 +- ...Site_lastN__API.getProcessedReport_day.xml | 2 +- ...Site_lastN__API.getProcessedReport_day.xml | 2 +- ...Site_lastN__API.getProcessedReport_day.xml | 2 +- ...Site_lastN__API.getProcessedReport_day.xml | 2 +- ...GetReportMetadata__API.getMetadata_day.xml | 2 +- ...rtMetadata__API.getProcessedReport_day.xml | 2 +- ...ormalAPI__API.getProcessedReport_range.xml | 4 ++-- 13 files changed, 35 insertions(+), 20 deletions(-) diff --git a/plugins/API/API.php b/plugins/API/API.php index ddb611b417..d3a1be0f99 100644 --- a/plugins/API/API.php +++ b/plugins/API/API.php @@ -346,14 +346,9 @@ class Piwik_API_API public function getMetadata($idSite, $apiModule, $apiAction, $apiParameters = array(), $language = false, $period = false, $date = false) { Piwik_Translate::getInstance()->reloadLanguage($language); - static $reportsMetadata = array(); - $cacheKey = $idSite.$language; - if(!isset($reportsMetadata[$cacheKey])) - { - $reportsMetadata[$cacheKey] = $this->getReportMetadata($idSite, $period, $date); - } + $reportsMetadata = $this->getReportMetadata($idSite, $period, $date); - foreach($reportsMetadata[$cacheKey] as $report) + foreach($reportsMetadata as $report) { // See ArchiveProcessing/Period.php - unique visitors are not processed for period != day if($period != 'day' diff --git a/plugins/ImageGraph/API.php b/plugins/ImageGraph/API.php index 84f92ae9be..dc8e8dd365 100644 --- a/plugins/ImageGraph/API.php +++ b/plugins/ImageGraph/API.php @@ -281,6 +281,10 @@ class Piwik_ImageGraph_API //Otherwise we have rows else if(!empty($metadata[0]['dimension'])) { + if(!($report["reportData"] instanceof Piwik_DataTable)) + { + throw new Exception("The graph cannot be drawn with the request 'date' and 'period' parameters."); + } foreach($report["reportData"]->getRows() as $rowId => $row) { $row = $row->getColumns(); diff --git a/plugins/ImageGraph/ImageGraph.php b/plugins/ImageGraph/ImageGraph.php index d2905414a3..38e77ae4f1 100644 --- a/plugins/ImageGraph/ImageGraph.php +++ b/plugins/ImageGraph/ImageGraph.php @@ -62,9 +62,18 @@ class Piwik_ImageGraph extends Piwik_Plugin $dateLastN = $info['date']; // If the date is not already a range, then we process the range to plot on Graph - if(!Piwik_Archive::isMultiplePeriod($info['date'], $info['period'])) + if($info['period'] != 'range') { - $dateLastN = Piwik_Controller::getDateRangeRelativeToEndDate($info['period'], $lastN, $info['date'], new Piwik_Site($idSite)); + if(!Piwik_Archive::isMultiplePeriod($info['date'], $info['period'])) + { + $dateLastN = Piwik_Controller::getDateRangeRelativeToEndDate($info['period'], $lastN, $info['date'], new Piwik_Site($idSite)); + } + // Period is not range, but date is already date1,date2 format + // so we draw the graph over the requested range + else + { + $info['period'] = 'range'; + } } $token_auth = Piwik_Common::getRequestVar('token_auth', false); @@ -93,7 +102,12 @@ class Piwik_ImageGraph extends Piwik_Plugin if(empty($report['dimension'])) { $parameters['graphType'] = 'evolution'; - $parameters['date'] = $dateLastN; + + // If period == range, then date is already a date range + if($info['period'] != 'range') + { + $parameters['date'] = $dateLastN; + } } $report['imageGraphUrl'] = $urlPrefix . Piwik_Url::getQueryStringFromParameters($parameters); diff --git a/tests/integration/Integration.php b/tests/integration/Integration.php index b1cab10e13..74a94b04a7 100644 --- a/tests/integration/Integration.php +++ b/tests/integration/Integration.php @@ -460,6 +460,8 @@ abstract class Test_Integration extends Test_Database $response = $this->removeXmlElement($response, 'sum_daily_nb_uniq_visitors'); $expected = $this->removeXmlElement($expected, 'nb_visits_converted'); $response = $this->removeXmlElement($response, 'nb_visits_converted'); + $expected = $this->removeXmlElement($expected, 'imageGraphUrl'); + $response = $this->removeXmlElement($response, 'imageGraphUrl'); $removeEndOfLines =true; } diff --git a/tests/integration/expected/test_TwoVisitors_twoWebsites_differentDays_Actions.getOutlinks_firstSite_lastN__API.getProcessedReport_day.xml b/tests/integration/expected/test_TwoVisitors_twoWebsites_differentDays_Actions.getOutlinks_firstSite_lastN__API.getProcessedReport_day.xml index cec8c6fdb4..4f25ff0fe5 100644 --- a/tests/integration/expected/test_TwoVisitors_twoWebsites_differentDays_Actions.getOutlinks_firstSite_lastN__API.getProcessedReport_day.xml +++ b/tests/integration/expected/test_TwoVisitors_twoWebsites_differentDays_Actions.getOutlinks_firstSite_lastN__API.getProcessedReport_day.xml @@ -19,7 +19,7 @@ </metricsDocumentation> <documentation>This report shows a hierarchical list of outlink URLs that were clicked by your visitors. An outlink is a link that leads the visitor away from your website (to another domain).<br />Use the plus and minus icons on the left to navigate.</documentation> - <imageGraphUrl>index.php?module=API&method=ImageGraph.get&idSite=1&apiModule=Actions&apiAction=getOutlinks&graphType=verticalBar&period=day&date=2011-04-05</imageGraphUrl> + <imageGraphUrl>index.php?module=API&method=ImageGraph.get&idSite=1&apiModule=Actions&apiAction=getOutlinks&graphType=verticalBar&period=range&date=2010-01-03,2010-01-09</imageGraphUrl> <uniqueId>Actions_getOutlinks</uniqueId> </metadata> diff --git a/tests/integration/expected/test_TwoVisitors_twoWebsites_differentDays_Actions.getPageTitles_firstSite_lastN__API.getProcessedReport_day.xml b/tests/integration/expected/test_TwoVisitors_twoWebsites_differentDays_Actions.getPageTitles_firstSite_lastN__API.getProcessedReport_day.xml index 8fa52d7a80..d4f983d345 100644 --- a/tests/integration/expected/test_TwoVisitors_twoWebsites_differentDays_Actions.getPageTitles_firstSite_lastN__API.getProcessedReport_day.xml +++ b/tests/integration/expected/test_TwoVisitors_twoWebsites_differentDays_Actions.getPageTitles_firstSite_lastN__API.getProcessedReport_day.xml @@ -27,7 +27,7 @@ </metricsDocumentation> <documentation>This report contains information about the titles of the pages that have been visited. <br /> The page title is the HTML <title> Tag that most browsers show in their window title.</documentation> - <imageGraphUrl>index.php?module=API&method=ImageGraph.get&idSite=1&apiModule=Actions&apiAction=getPageTitles&graphType=verticalBar&period=day&date=2011-04-05</imageGraphUrl> + <imageGraphUrl>index.php?module=API&method=ImageGraph.get&idSite=1&apiModule=Actions&apiAction=getPageTitles&graphType=verticalBar&period=range&date=2010-01-03,2010-01-09</imageGraphUrl> <uniqueId>Actions_getPageTitles</uniqueId> </metadata> diff --git a/tests/integration/expected/test_TwoVisitors_twoWebsites_differentDays_Actions.getPageUrls_firstSite_lastN__API.getProcessedReport_day.xml b/tests/integration/expected/test_TwoVisitors_twoWebsites_differentDays_Actions.getPageUrls_firstSite_lastN__API.getProcessedReport_day.xml index a83f2e97b1..f056b1735e 100644 --- a/tests/integration/expected/test_TwoVisitors_twoWebsites_differentDays_Actions.getPageUrls_firstSite_lastN__API.getProcessedReport_day.xml +++ b/tests/integration/expected/test_TwoVisitors_twoWebsites_differentDays_Actions.getPageUrls_firstSite_lastN__API.getProcessedReport_day.xml @@ -27,7 +27,7 @@ </metricsDocumentation> <documentation>This report contains information about the page URLs that have been visited. <br /> The table is organized hierarchically, the URLs are displayed as a folder structure.<br />Use the plus and minus icons on the left to navigate.</documentation> - <imageGraphUrl>index.php?module=API&method=ImageGraph.get&idSite=1&apiModule=Actions&apiAction=getPageUrls&graphType=verticalBar&period=day&date=2011-04-05</imageGraphUrl> + <imageGraphUrl>index.php?module=API&method=ImageGraph.get&idSite=1&apiModule=Actions&apiAction=getPageUrls&graphType=verticalBar&period=range&date=2010-01-03,2010-01-09</imageGraphUrl> <uniqueId>Actions_getPageUrls</uniqueId> </metadata> diff --git a/tests/integration/expected/test_TwoVisitors_twoWebsites_differentDays_Referers.getWebsites_firstSite_lastN__API.getProcessedReport_day.xml b/tests/integration/expected/test_TwoVisitors_twoWebsites_differentDays_Referers.getWebsites_firstSite_lastN__API.getProcessedReport_day.xml index 3cf03545d6..14802d8be5 100644 --- a/tests/integration/expected/test_TwoVisitors_twoWebsites_differentDays_Referers.getWebsites_firstSite_lastN__API.getProcessedReport_day.xml +++ b/tests/integration/expected/test_TwoVisitors_twoWebsites_differentDays_Referers.getWebsites_firstSite_lastN__API.getProcessedReport_day.xml @@ -43,7 +43,7 @@ <revenue_per_visit>Revenue per Visit</revenue_per_visit> </processedMetricsGoal> - <imageGraphUrl>index.php?module=API&method=ImageGraph.get&idSite=1&apiModule=Referers&apiAction=getWebsites&graphType=verticalBar&period=day&date=2011-04-05</imageGraphUrl> + <imageGraphUrl>index.php?module=API&method=ImageGraph.get&idSite=1&apiModule=Referers&apiAction=getWebsites&graphType=verticalBar&period=range&date=2010-01-03,2010-01-09</imageGraphUrl> <uniqueId>Referers_getWebsites</uniqueId> </metadata> diff --git a/tests/integration/expected/test_TwoVisitors_twoWebsites_differentDays_VisitFrequency.get_firstSite_lastN__API.getProcessedReport_day.xml b/tests/integration/expected/test_TwoVisitors_twoWebsites_differentDays_VisitFrequency.get_firstSite_lastN__API.getProcessedReport_day.xml index 1fb1297ee4..ad36f796c0 100644 --- a/tests/integration/expected/test_TwoVisitors_twoWebsites_differentDays_VisitFrequency.get_firstSite_lastN__API.getProcessedReport_day.xml +++ b/tests/integration/expected/test_TwoVisitors_twoWebsites_differentDays_VisitFrequency.get_firstSite_lastN__API.getProcessedReport_day.xml @@ -28,7 +28,7 @@ <exit_rate>The percentage of visits that left the website after viewing this page.</exit_rate> </metricsDocumentation> - <imageGraphUrl>index.php?module=API&method=ImageGraph.get&idSite=1&apiModule=VisitFrequency&apiAction=get&graphType=evolution&period=day&date=2011-03-07,2011-04-05</imageGraphUrl> + <imageGraphUrl>index.php?module=API&method=ImageGraph.get&idSite=1&apiModule=VisitFrequency&apiAction=get&graphType=evolution&period=range&date=2010-01-03,2010-01-09</imageGraphUrl> <uniqueId>VisitFrequency_get</uniqueId> </metadata> diff --git a/tests/integration/expected/test_TwoVisitors_twoWebsites_differentDays_VisitsSummary.get_firstSite_lastN__API.getProcessedReport_day.xml b/tests/integration/expected/test_TwoVisitors_twoWebsites_differentDays_VisitsSummary.get_firstSite_lastN__API.getProcessedReport_day.xml index 495be1c60e..e457e62ee9 100644 --- a/tests/integration/expected/test_TwoVisitors_twoWebsites_differentDays_VisitsSummary.get_firstSite_lastN__API.getProcessedReport_day.xml +++ b/tests/integration/expected/test_TwoVisitors_twoWebsites_differentDays_VisitsSummary.get_firstSite_lastN__API.getProcessedReport_day.xml @@ -30,7 +30,7 @@ <exit_rate>The percentage of visits that left the website after viewing this page.</exit_rate> </metricsDocumentation> - <imageGraphUrl>index.php?module=API&method=ImageGraph.get&idSite=1&apiModule=VisitsSummary&apiAction=get&graphType=evolution&period=day&date=2011-03-07,2011-04-05</imageGraphUrl> + <imageGraphUrl>index.php?module=API&method=ImageGraph.get&idSite=1&apiModule=VisitsSummary&apiAction=get&graphType=evolution&period=range&date=2010-01-03,2010-01-09</imageGraphUrl> <uniqueId>VisitsSummary_get</uniqueId> </metadata> diff --git a/tests/integration/expected/test_apiGetReportMetadata__API.getMetadata_day.xml b/tests/integration/expected/test_apiGetReportMetadata__API.getMetadata_day.xml index af44585280..d1f9fed978 100644 --- a/tests/integration/expected/test_apiGetReportMetadata__API.getMetadata_day.xml +++ b/tests/integration/expected/test_apiGetReportMetadata__API.getMetadata_day.xml @@ -40,7 +40,7 @@ <revenue_per_visit>Revenue per Visit</revenue_per_visit> </processedMetricsGoal> - <imageGraphUrl>index.php?module=API&method=ImageGraph.get&idSite=1&apiModule=UserCountry&apiAction=getCountry&graphType=verticalBar&period=day&date=2011-04-05</imageGraphUrl> + <imageGraphUrl>index.php?module=API&method=ImageGraph.get&idSite=1&apiModule=UserCountry&apiAction=getCountry&graphType=verticalBar&period=day&date=2009-01-04</imageGraphUrl> <uniqueId>UserCountry_getCountry</uniqueId> </row> diff --git a/tests/integration/expected/test_apiGetReportMetadata__API.getProcessedReport_day.xml b/tests/integration/expected/test_apiGetReportMetadata__API.getProcessedReport_day.xml index be5dbc47f6..100305accd 100644 --- a/tests/integration/expected/test_apiGetReportMetadata__API.getProcessedReport_day.xml +++ b/tests/integration/expected/test_apiGetReportMetadata__API.getProcessedReport_day.xml @@ -42,7 +42,7 @@ <revenue_per_visit>Revenue per Visit</revenue_per_visit> </processedMetricsGoal> - <imageGraphUrl>index.php?module=API&method=ImageGraph.get&idSite=1&apiModule=UserCountry&apiAction=getCountry&graphType=verticalBar&period=day&date=2011-04-05</imageGraphUrl> + <imageGraphUrl>index.php?module=API&method=ImageGraph.get&idSite=1&apiModule=UserCountry&apiAction=getCountry&graphType=verticalBar&period=day&date=2009-01-04</imageGraphUrl> <uniqueId>UserCountry_getCountry</uniqueId> </metadata> diff --git a/tests/integration/expected/test_periodIsRange_dateIsLastN_MetadataAndNormalAPI__API.getProcessedReport_range.xml b/tests/integration/expected/test_periodIsRange_dateIsLastN_MetadataAndNormalAPI__API.getProcessedReport_range.xml index bf1cc2f2fe..1dc2ea5e28 100644 --- a/tests/integration/expected/test_periodIsRange_dateIsLastN_MetadataAndNormalAPI__API.getProcessedReport_range.xml +++ b/tests/integration/expected/test_periodIsRange_dateIsLastN_MetadataAndNormalAPI__API.getProcessedReport_range.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="utf-8" ?> <result> <website>Piwik test</website> - <prettyDate>8 Oct 11 - 14 Oct 11</prettyDate> + <metadata> <category>Visitors</category> <name>Country</name> @@ -41,7 +41,7 @@ <revenue_per_visit>Revenue per Visit</revenue_per_visit> </processedMetricsGoal> - <imageGraphUrl>index.php?module=API&method=ImageGraph.get&idSite=1&apiModule=UserCountry&apiAction=getCountry&graphType=verticalBar&period=day&date=2011-04-05</imageGraphUrl> + <uniqueId>UserCountry_getCountry</uniqueId> </metadata> -- GitLab