diff options
Diffstat (limited to 'core/Archiver/Request.php')
-rw-r--r-- | core/Archiver/Request.php | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/core/Archiver/Request.php b/core/Archiver/Request.php index e08b23ac54..58389384a6 100644 --- a/core/Archiver/Request.php +++ b/core/Archiver/Request.php @@ -31,7 +31,7 @@ class Request */ public function __construct($url) { - $this->url = $url; + $this->setUrl($url); } public function before($callable) @@ -69,8 +69,33 @@ class Request public function changeDate($newDate) { + $this->changeParam('date', $newDate); + } + + public function makeSureDateIsNotSingleDayRange() + { + // TODO: revisit in matomo 4 + // period=range&date=last1/period=range&date=previous1 can cause problems during archiving due to Parameters::isDayArchive() + if (preg_match('/[&?]period=range/', $this->url)) { + if (preg_match('/[&?]date=last1/', $this->url)) { + $this->changeParam('period', 'day'); + $this->changeParam('date', 'today'); + } else if (preg_match('/[&?]date=previous1/', $this->url)) { + $this->changeParam('period', 'day'); + $this->changeParam('date', 'yesterday'); + } else if (preg_match('/[&?]date=([^,]+),([^,&]+)/', $this->url, $matches) + && $matches[1] == $matches[2] + ) { + $this->changeParam('period', 'day'); + $this->changeParam('date', $matches[1]); + } + } + } + + public function changeParam($name, $newValue) + { $url = $this->getUrl(); - $url = preg_replace('/([&?])date=[^&]*/', '$1date=' . $newDate, $url); + $url = preg_replace('/([&?])' . preg_quote($name) . '=[^&]*/', '$1' . $name . '=' . $newValue, $url); $this->setUrl($url); } } |