diff --git a/plugins/API/API.php b/plugins/API/API.php index ddb611b417c3a527269f992bce3eff7834ee779b..d3a1be0f99077de5c96a95a0397fa04655f0a1b4 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 84f92ae9beda171cfe3e165eb0aa3ad0e2816560..dc8e8dd365cde85aaf2f9dc4e734dbc684b4d22e 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 d2905414a3887cc1cf6f93ffa440add8f49d1f0c..38e77ae4f10fd27e83627f4884e000b895ef0acc 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 b1cab10e135742dcaca4adb34390b302ecd3cec7..74a94b04a727157e9c2dd373d8f3dd5241524f9e 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 cec8c6fdb4f6a162bd01637f6de39e1ac1e585bf..4f25ff0fe593303bf9dfefe4f8964277b7c3cb99 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 8fa52d7a80c5967dca08e1ac564d5ad3729183b5..d4f983d345c3115c4579128dd0de9c3a756c9375 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 a83f2e97b12bcba2fc6fa90baccf9075699a758f..f056b1735e548bade2796bf0632594b26a2213ea 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 3cf03545d634c7074e6fd95637607de211c5c5ba..14802d8be5e206af525ca3f7528cdb51e536d242 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 1fb1297ee4d22170a9a0fd285cce2ddb64658503..ad36f796c08512d33ebf8081447b444f444d2573 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 495be1c60e063bc0d1e093178763da069475f55f..e457e62ee9acb3d3c9437b2a0e8c9290974c8b26 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 af44585280fe499cb4cbd45b4966fadee1569979..d1f9fed978c6152f391d583d69563c4ff6bdbfc4 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 be5dbc47f65a390fde9fef65de75df9fd92a7bb3..100305accd099bfee0ea59c746f7a1e7a7d00f9c 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 bf1cc2f2fea51b10ecf39e9e637522c134b03bbc..1dc2ea5e285728f3356def22de7ba4a7c3ec2838 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>