diff options
author | diosmosis <diosmosis@users.noreply.github.com> | 2018-07-19 05:03:16 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-19 05:03:16 +0300 |
commit | 2020b122615789c36eaa0917e10b483f12793b3c (patch) | |
tree | cf81d97d51b825a2b941d7766f93b38ff7e4bb1c /core/ArchiveProcessor.php | |
parent | 105e007721b5c0ea12ff2596d8d82c721021fb4e (diff) |
Add ability for Archivers to initiate archiving for other plugins & use in Goals (#13105)
* Add required segments for Goals.get to known segments to archive list.
* Add test to ArchiveCronTest.
* Allow archiving dependent archives in Goals Archiver.
* Clean up last commit & use Segment::combine in more places.
* skip dependent processing if same plugin/segment
* Move ArchiveCronTest to CoreConsole plugin since it is rather long running.
* Fixing tests.
* Remove use statements.
* Fix tests dependent on archive tables.
* check w/ urlencoded/decoded segment/condition in Segment::combine().
* Another test fix
* final test fix
Diffstat (limited to 'core/ArchiveProcessor.php')
-rw-r--r-- | core/ArchiveProcessor.php | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/core/ArchiveProcessor.php b/core/ArchiveProcessor.php index 65e8cbe86e..2b5547b13b 100644 --- a/core/ArchiveProcessor.php +++ b/core/ArchiveProcessor.php @@ -17,6 +17,8 @@ use Piwik\DataAccess\LogAggregator; use Piwik\DataTable\Manager; use Piwik\DataTable\Map; use Piwik\DataTable\Row; +use Piwik\Segment\SegmentExpression; + /** * Used by {@link Piwik\Plugin\Archiver} instances to insert and aggregate archive data. * @@ -584,4 +586,44 @@ class ArchiveProcessor return $metrics; } + + /** + * Initiate archiving for a plugin during an ongoing archiving. The plugin can be another + * plugin or the same plugin. + * + * This method should be called during archiving when one plugin uses the report of another + * plugin with a segment. It will ensure reports for that segment & plugin will be archived + * without initiating archiving for every plugin with that segment (which would be a performance + * killer). + * + * @param string $plugin + * @param string $segment + */ + public function processDependentArchive($plugin, $segment) + { + $params = $this->getParams(); + if (!$params->isRootArchiveRequest()) { // prevent all recursion + return; + } + + $idSites = [$params->getSite()->getId()]; + + $newSegment = Segment::combine($params->getSegment()->getString(), SegmentExpression::AND_DELIMITER, $segment); + if ($newSegment === $segment && $params->getRequestedPlugin() === $plugin) { // being processed now + return; + } + + $newSegment = new Segment($newSegment, $idSites); + if (ArchiveProcessor\Rules::isSegmentPreProcessed($idSites, $newSegment)) { + // will be processed anyway + return; + } + + $parameters = new ArchiveProcessor\Parameters($params->getSite(), $params->getPeriod(), $newSegment); + $parameters->onlyArchiveRequestedPlugin(); + $parameters->setIsRootArchiveRequest(false); + + $archiveLoader = new ArchiveProcessor\Loader($parameters); + $archiveLoader->prepareArchive($plugin); + } } |