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:
authordiosmosis <diosmosis@users.noreply.github.com>2020-11-30 06:23:54 +0300
committerGitHub <noreply@github.com>2020-11-30 06:23:54 +0300
commitc08811389bca65ae3e3eb878a001e71562fd7fed (patch)
tree1af0e3cce7a2d1a4b015438a442edee8caccef6d /core
parentfc2e8a5ea1d37a8db37e9e2330ba67faacdc71a2 (diff)
re-add missing condition for --skip-segments-today (#16777)
Diffstat (limited to 'core')
-rw-r--r--core/Archive.php14
-rw-r--r--core/CronArchive.php13
-rw-r--r--core/CronArchive/ArchiveFilter.php42
3 files changed, 52 insertions, 17 deletions
diff --git a/core/Archive.php b/core/Archive.php
index 8f3a5fdbfa..10aca77b8c 100644
--- a/core/Archive.php
+++ b/core/Archive.php
@@ -234,6 +234,14 @@ class Archive implements ArchiveQuery
$isMultipleDate);
}
+ public static function shouldSkipArchiveIfSkippingSegmentArchiveForToday(Site $site, Period $period, Segment $segment)
+ {
+ $now = Date::factory('now', $site->getTimezone());
+ return $period->getLabel() === 'day'
+ && !$segment->isEmpty()
+ && $period->getDateStart()->toString() === $now->toString();
+ }
+
/**
* Queries and returns metric data in an array.
*
@@ -580,10 +588,8 @@ class Archive implements ArchiveQuery
foreach ($this->params->getIdSites() as $idSite) {
$site = new Site($idSite);
- if ($period->getLabel() === 'day'
- && !$this->params->getSegment()->isEmpty()
- && Common::getRequestVar('skipArchiveSegmentToday', 0, 'int')
- && $period->getDateStart()->toString() === Date::factory('now', $site->getTimezone())->toString()
+ if (Common::getRequestVar('skipArchiveSegmentToday', 0, 'int')
+ && self::shouldSkipArchiveIfSkippingSegmentArchiveForToday($site, $period, $this->params->getSegment())
) {
Log::debug("Skipping archive %s for %s as segment today is disabled", $period->getLabel(), $period->getPrettyString());
continue;
diff --git a/core/CronArchive.php b/core/CronArchive.php
index fd16a424c7..a2335520fb 100644
--- a/core/CronArchive.php
+++ b/core/CronArchive.php
@@ -161,13 +161,6 @@ class CronArchive
*/
public $maxConcurrentArchivers = false;
- /**
- * If enabled, segments will be only archived for yesterday, but not today. If the segment was created recently,
- * then it will still be archived for today and the setting will be ignored for this segment.
- * @var bool
- */
- public $skipSegmentsToday = false;
-
private $archivingStartingTime;
private $formatter;
@@ -312,10 +305,6 @@ class CronArchive
$this->archiveFilter->logFilterInfo($this->logger);
}
- if ($this->skipSegmentsToday) {
- $this->logger->info('Will skip segments archiving for today unless they were created recently');
- }
-
/**
* This event is triggered after a CronArchive instance is initialized.
*
@@ -526,7 +515,7 @@ class CronArchive
$url = $this->makeRequestUrl($url);
if (!empty($segment)) {
- $shouldSkipToday = !$this->wasSegmentChangedRecently($segment,
+ $shouldSkipToday = $this->archiveFilter->isSkipSegmentsForToday() && !$this->wasSegmentChangedRecently($segment,
$this->segmentArchiving->getAllSegments());
if ($shouldSkipToday) {
diff --git a/core/CronArchive/ArchiveFilter.php b/core/CronArchive/ArchiveFilter.php
index 081426e249..7789ed556b 100644
--- a/core/CronArchive/ArchiveFilter.php
+++ b/core/CronArchive/ArchiveFilter.php
@@ -8,11 +8,15 @@
namespace Piwik\CronArchive;
+use Piwik\Archive;
use Piwik\Container\StaticContainer;
use Piwik\Date;
+use Piwik\Period\Factory;
use Piwik\Period\Factory as PeriodFactory;
use Piwik\Piwik;
use Piwik\Plugins\SegmentEditor\Model as SegmentEditorModel;
+use Piwik\Segment;
+use Piwik\Site;
use Psr\Log\LoggerInterface;
class ArchiveFilter
@@ -42,6 +46,13 @@ class ArchiveFilter
*/
private $periodIdsToLabels;
+ /**
+ * If enabled, segments will be only archived for yesterday, but not today. If the segment was created recently,
+ * then it will still be archived for today and the setting will be ignored for this segment.
+ * @var bool
+ */
+ private $skipSegmentsForToday = false;
+
public function __construct()
{
$this->setRestrictToPeriods('');
@@ -67,6 +78,15 @@ class ArchiveFilter
}
}
+ if (!empty($this->skipSegmentsForToday)) {
+ $site = new Site($archive['idsite']);
+ $period = Factory::build($this->periodIdsToLabels[$archive['period']], $archive['date1']);
+ $segment = new Segment($segment, [$archive['idsite']]);
+ if (Archive::shouldSkipArchiveIfSkippingSegmentArchiveForToday($site, $period, $segment)) {
+ return "skipping segment archives for today";
+ }
+ }
+
if (!empty($this->restrictToDateRange)
&& ($this->restrictToDateRange[0]->isLater(Date::factory($archive['date2']))
|| $this->restrictToDateRange[1]->isEarlier(Date::factory($archive['date1']))
@@ -89,6 +109,7 @@ class ArchiveFilter
{
$this->logForcedSegmentInfo($logger);
$this->logForcedPeriodInfo($logger);
+ $this->logSkipSegmentInfo($logger);
}
private function logForcedSegmentInfo(LoggerInterface $logger)
@@ -190,12 +211,24 @@ class ArchiveFilter
$this->segmentsToForce = $segments;
}
+ public function setSkipSegmentsForToday($skipSegmentsForToday)
+ {
+ $this->skipSegmentsForToday = $skipSegmentsForToday;
+ }
+
+ /**
+ * @return bool
+ */
+ public function isSkipSegmentsForToday(): bool
+ {
+ return $this->skipSegmentsForToday;
+ }
+
/**
* @return array
*/
private function getPeriodsToProcess()
{
-
return $this->restrictToPeriods;
}
@@ -229,4 +262,11 @@ class ArchiveFilter
$this->restrictToPeriods = array_intersect($this->restrictToPeriods, $this->getDefaultPeriodsToProcess());
$this->restrictToPeriods = array_intersect($this->restrictToPeriods, PeriodFactory::getPeriodsEnabledForAPI());
}
+
+ private function logSkipSegmentInfo(LoggerInterface $logger)
+ {
+ if ($this->skipSegmentsForToday) {
+ $logger->info('Will skip segments archiving for today unless they were created recently');
+ }
+ }
} \ No newline at end of file