diff options
author | dizzy <diosmosis@users.noreply.github.com> | 2021-02-05 01:22:11 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-05 01:22:11 +0300 |
commit | 490dc3a1a09e4263b4893cbbbf600ba505d9add4 (patch) | |
tree | 2fca42614fec12907ecac1ae217e1305baa4144a /plugins/SegmentEditor | |
parent | bc53bc36ebebfe50d83d6ce381aa8bb6cd2cb15c (diff) |
Refactor segment re-archiving in past behavior to be on demand (#17005)
* Invalidate past archives on demand when adding/updating segments, rather than trying to check when running core:archive
* start on rewriting test
* rewrite SegmentArchivingTest and get to pass
* get sites as superuser
* add update to rearchive segments if they were created/update between last archive time and update time
* remove unused parameter
* fix build
* fix tests
* sanity check
* fix bug, we should not forget archives to invalidate unless all related archives are being invalidated
* fix tests and make fix more complete
* fix test
* update counts in test
* fix test for last time hopefully
* fix another test
* remove debugging code
Diffstat (limited to 'plugins/SegmentEditor')
-rw-r--r-- | plugins/SegmentEditor/API.php | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/plugins/SegmentEditor/API.php b/plugins/SegmentEditor/API.php index 56cbe91282..13f724782b 100644 --- a/plugins/SegmentEditor/API.php +++ b/plugins/SegmentEditor/API.php @@ -9,13 +9,20 @@ namespace Piwik\Plugins\SegmentEditor; use Exception; +use Piwik\Access; +use Piwik\Archive\ArchiveInvalidator; use Piwik\ArchiveProcessor\Rules; use Piwik\Common; +use Piwik\Container\StaticContainer; +use Piwik\CronArchive\SegmentArchiving; use Piwik\Date; use Piwik\Db; +use Piwik\Period\Range; use Piwik\Piwik; use Piwik\Config; use Piwik\Segment; +use Piwik\Site; +use Psr\Log\LoggerInterface; /** * The SegmentEditor API lets you add, update, delete custom Segments, and list saved segments. @@ -29,9 +36,18 @@ class API extends \Piwik\Plugin\API */ private $model; - public function __construct(Model $model) + /** + * @var SegmentArchiving + */ + private $segmentArchiving; + + private $processNewSegmentsFrom; + + public function __construct(Model $model, SegmentArchiving $segmentArchiving) { $this->model = $model; + $this->segmentArchiving = $segmentArchiving; + $this->processNewSegmentsFrom = StaticContainer::get('ini.General.process_new_segments_from'); } protected function checkSegmentValue($definition, $idSite) @@ -258,6 +274,10 @@ class API extends \Piwik\Plugin\API $this->getModel()->updateSegment($idSegment, $bind); + if ($autoArchive && !Rules::isBrowserTriggerEnabled()) { + $this->segmentArchiving->reArchiveSegment($bind); + } + return true; } @@ -294,6 +314,13 @@ class API extends \Piwik\Plugin\API $id = $this->getModel()->createSegment($bind); + if ($autoArchive + && !Rules::isBrowserTriggerEnabled() + && $this->processNewSegmentsFrom != SegmentArchiving::CREATION_TIME + ) { + $this->segmentArchiving->reArchiveSegment($bind); + } + return $id; } |