Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormattab <matthieu.aubry@gmail.com>2014-05-02 05:31:49 +0400
committermattab <matthieu.aubry@gmail.com>2014-05-02 05:31:49 +0400
commit77fa82f580764931504a28c91490f66633408c92 (patch)
tree0a330fecd48744f4b824a1f049e981a3197bc33f
parentffdc6f0dfa908591897c0a15f6d2bd47b7fadc3c (diff)
Fixes #5037 You can now configure periods that are available in the UI and API
; The list of periods that are available in the Piwik calendar ; Example use case: custom date range requests are processed in real time, ; so they may take a few minutes on very high traffic website: you may remove "range" below to disable this period enabled_periods_UI = "day,week,month,year,range" enabled_periods_API = "day,week,month,year,range"
-rw-r--r--config/global.ini.php2
-rw-r--r--core/Archive.php2
-rw-r--r--core/Period.php2
-rw-r--r--core/Period/Factory.php25
-rw-r--r--plugins/Live/Controller.php2
5 files changed, 23 insertions, 10 deletions
diff --git a/config/global.ini.php b/config/global.ini.php
index cafd4ba47f..e3a929d3e7 100644
--- a/config/global.ini.php
+++ b/config/global.ini.php
@@ -105,7 +105,7 @@ enable_processing_unique_visitors_range = 0
; The list of periods that are available in the Piwik calendar
; Example use case: custom date range requests are processed in real time,
-; so they may take a few minutes on very high traffic website. You may remove "range" below.
+; so they may take a few minutes on very high traffic website: you may remove "range" below to disable this period
enabled_periods_UI = "day,week,month,year,range"
enabled_periods_API = "day,week,month,year,range"
diff --git a/core/Archive.php b/core/Archive.php
index f4732c2751..a271f40905 100644
--- a/core/Archive.php
+++ b/core/Archive.php
@@ -201,7 +201,7 @@ class Archive
$websiteIds = Site::getIdSitesFromIdSitesString($idSites, $_restrictSitesToLogin);
if (Period::isMultiplePeriod($strDate, $period)) {
- $oPeriod = new Range($period, $strDate);
+ $oPeriod = Factory::build($period, $strDate);
$allPeriods = $oPeriod->getSubperiods();
} else {
$timezone = count($websiteIds) == 1 ? Site::getTimezoneFor($websiteIds[0]) : false;
diff --git a/core/Period.php b/core/Period.php
index 8ec4bf3345..9fc808e13d 100644
--- a/core/Period.php
+++ b/core/Period.php
@@ -62,7 +62,7 @@ abstract class Period
}
/**
- * @deprecated
+ * @deprecated Use Factory::build instead
* @param $period
* @param $date
* @return Period
diff --git a/core/Period/Factory.php b/core/Period/Factory.php
index 7a909a182e..2494da0a50 100644
--- a/core/Period/Factory.php
+++ b/core/Period/Factory.php
@@ -28,15 +28,15 @@ class Factory
*/
static public function build($period, $date)
{
+ self::checkPeriodIsEnabled($period);
+
if (is_string($date)) {
if (Period::isMultiplePeriod($date, $period) || $period == 'range') {
- self::checkPeriodIsEnabled('range');
return new Range($period, $date);
}
$date = Date::factory($date);
}
- self::checkPeriodIsEnabled($period);
switch ($period) {
case 'day':
@@ -57,7 +57,7 @@ class Factory
}
}
- private static function checkPeriodIsEnabled($period)
+ public static function checkPeriodIsEnabled($period)
{
if(!self::isPeriodEnabledForAPI($period)) {
self::throwExceptionInvalidPeriod($period);
@@ -70,7 +70,9 @@ class Factory
*/
private static function throwExceptionInvalidPeriod($strPeriod)
{
- $message = Piwik::translate('General_ExceptionInvalidPeriod', array($strPeriod, 'day, week, month, year, range'));
+ $periods = self::getPeriodsEnabledForAPI();
+ $periods = implode(", ", $periods);
+ $message = Piwik::translate('General_ExceptionInvalidPeriod', array($strPeriod, $periods));
throw new Exception($message);
}
@@ -92,7 +94,8 @@ class Factory
}
if ($period == 'range') {
- $oPeriod = new Period\Range('range', $date, $timezone, Date::factory('today', $timezone));
+ self::checkPeriodIsEnabled('range');
+ $oPeriod = new Range('range', $date, $timezone, Date::factory('today', $timezone));
} else {
if (!($date instanceof Date)) {
if ($date == 'now' || $date == 'today') {
@@ -113,10 +116,18 @@ class Factory
*/
public static function isPeriodEnabledForAPI($period)
{
+ $enabledPeriodsInAPI = self::getPeriodsEnabledForAPI();
+ return in_array($period, $enabledPeriodsInAPI);
+ }
+
+ /**
+ * @return array
+ */
+ private static function getPeriodsEnabledForAPI()
+ {
$enabledPeriodsInAPI = Config::getInstance()->General['enabled_periods_API'];
$enabledPeriodsInAPI = explode(",", $enabledPeriodsInAPI);
$enabledPeriodsInAPI = array_map('trim', $enabledPeriodsInAPI);
-
- return in_array($period, $enabledPeriodsInAPI);
+ return $enabledPeriodsInAPI;
}
} \ No newline at end of file
diff --git a/plugins/Live/Controller.php b/plugins/Live/Controller.php
index 900010f157..06adb63627 100644
--- a/plugins/Live/Controller.php
+++ b/plugins/Live/Controller.php
@@ -105,7 +105,9 @@ class Controller extends \Piwik\Plugin\Controller
{
// hack, ensure we load today's visits by default
$_GET['date'] = 'today';
+ \Piwik\Period\Factory::checkPeriodIsEnabled('day');
$_GET['period'] = 'day';
+
$view = new View('@Live/getLastVisitsStart');
$view->idSite = $this->idSite;
$api = new Request("method=Live.getLastVisitsDetails&idSite={$this->idSite}&filter_limit=10&format=php&serialize=0&disable_generic_filters=1");