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
path: root/core
diff options
context:
space:
mode:
authorThomas Steur <tsteur@users.noreply.github.com>2020-08-24 05:11:55 +0300
committerGitHub <noreply@github.com>2020-08-24 05:11:55 +0300
commit1001cd2868d39ecba2b921264dae907b86d5a1c0 (patch)
tree6d421889ae19ca0dbda23ad073a446d76062d46e /core
parent61c27749b1af2a330fa5c2b94f30adaaa871a920 (diff)
By default select site creation date if site was created today or if select date is before site creation date (#16287)
Diffstat (limited to 'core')
-rw-r--r--core/Plugin/Menu.php36
1 files changed, 34 insertions, 2 deletions
diff --git a/core/Plugin/Menu.php b/core/Plugin/Menu.php
index 73d335381b..e936fe3757 100644
--- a/core/Plugin/Menu.php
+++ b/core/Plugin/Menu.php
@@ -9,11 +9,14 @@
namespace Piwik\Plugin;
use Piwik\Common;
+use Piwik\Date;
use Piwik\Development;
use Piwik\Menu\MenuAdmin;
use Piwik\Menu\MenuTop;
+use Piwik\Period;
use Piwik\Plugin\Manager as PluginManager;
use Piwik\Plugins\UsersManager\UserPreferences;
+use Piwik\Site;
/**
* Base class of all plugin menu providers. Plugins that define their own menu items can extend this class to easily
@@ -194,11 +197,40 @@ class Menu
if (empty($websiteId)) {
throw new \Exception("A website ID was not specified and a website to default to could not be found.");
}
+ if (empty($defaultPeriod)) {
+ $defaultPeriod = $userPreferences->getDefaultPeriod(false);
+ }
if (empty($defaultDate)) {
$defaultDate = $userPreferences->getDefaultDate();
}
- if (empty($defaultPeriod)) {
- $defaultPeriod = $userPreferences->getDefaultPeriod(false);
+
+ if ($defaultPeriod !== 'range' && !empty($defaultDate) && $defaultDate !== 'today') {
+ // not easy to make it work for range... is rarely the default anyway especially when just setting up
+ // Matomo as this logic is basically only applied on the first day a site is created
+ // no need to run logic when today is selected. It basically runs currently only when "yesterday" is selected
+ // as a default date but would also support future new default dates like past month etc.
+ try {
+ $siteCreationDate = Site::getCreationDateFor($websiteId);
+ $siteTimezone = Site::getTimezoneFor($websiteId);
+
+ if (!empty($siteCreationDate)) {
+ if (is_numeric($defaultDate)) {
+ $defaultDate = (int) $defaultDate; //prevent possible exception should defaultDate be a string timestamp
+ }
+ $siteCreationDate = Date::factory($siteCreationDate, $siteTimezone);
+ $defaultDateObj = Date::factory($defaultDate, $siteTimezone);
+
+ $period = Period\Factory::build($defaultPeriod, $defaultDateObj);
+ $endDate = $period->getDateEnd();
+
+ if ($endDate->isEarlier($siteCreationDate)) {
+ // when selected date is before site creation date or it is the site creation day
+ $defaultDate = $siteCreationDate->toString();
+ }
+ }
+ } catch (\Exception $e) {
+ //ignore any error in case site was just deleted or the given date is not valid etc.
+ }
}
return array(
'idSite' => $websiteId,