diff options
author | mattab <matthieu.aubry@gmail.com> | 2013-11-08 04:26:52 +0400 |
---|---|---|
committer | mattab <matthieu.aubry@gmail.com> | 2013-11-08 04:26:52 +0400 |
commit | 25e7a79defefbe299746c7ddd30509625c17296f (patch) | |
tree | da9f49f08e89ee941618ff19bbce0b6e4b228e26 | |
parent | 9bdf699c77db6e90c20fb4dfcd5b8bdfc9a3389f (diff) |
Refs #4278 breaking down functions
-rw-r--r-- | core/Archive.php | 57 | ||||
-rw-r--r-- | core/ArchiveProcessor/Loader.php | 94 |
2 files changed, 94 insertions, 57 deletions
diff --git a/core/Archive.php b/core/Archive.php index 084abb17dd..e0232f698f 100644 --- a/core/Archive.php +++ b/core/Archive.php @@ -537,7 +537,12 @@ class Archive $doneFlags[$doneFlag] = true; if (!isset($this->idarchives[$doneFlag])) { - $archiveGroups[] = $this->getArchiveGroupOfPlugin($plugin); + $archiveGroup = $this->getArchiveGroupOfPlugin($plugin); + + if($archiveGroup == self::ARCHIVE_ALL_PLUGINS_FLAG) { + $archiveGroup = reset($plugins); + } + $archiveGroups[] = $archiveGroup; } } @@ -546,6 +551,7 @@ class Archive // cache id archives for plugins we haven't processed yet if (!empty($archiveGroups)) { if (!Rules::isArchivingDisabledFor($this->params->getSegment(), $this->getPeriodLabel())) { + $this->cacheArchiveIdsAfterLaunching($archiveGroups, $plugins); } else { $this->cacheArchiveIdsWithoutLaunching($plugins); @@ -583,8 +589,6 @@ class Archive /* @var Period $period */ foreach ($this->params->getPeriods() as $period) { - $periodStr = $period->getRangeString(); - $twoDaysBeforePeriod = $period->getDateStart()->subDay(2); $twoDaysAfterPeriod = $period->getDateEnd()->addDay(2); @@ -607,26 +611,7 @@ class Archive continue; } - $parameters = new ArchiveProcessor\Parameters($site, $period, $this->params->getSegment()); - $processing = new ArchiveProcessor\Loader($parameters); - - // process for each plugin as well - foreach ($archiveGroups as $plugin) { - if ($plugin == self::ARCHIVE_ALL_PLUGINS_FLAG) { - $plugin = reset($plugins); - } - - $doneFlag = $this->getDoneStringForPlugin($plugin); - $this->initializeArchiveIdCache($doneFlag); - - $parameters->setRequestedPlugin($plugin); - $idArchive = $processing->preProcessArchive(); - - $visits = $processing->getNumberOfVisits(); - if ($visits > 0) { - $this->idarchives[$doneFlag][$periodStr][] = $idArchive; - } - } + $this->launchArchiveProcessor($archiveGroups, $site, $period); } } } @@ -789,4 +774,30 @@ class Archive } return $plugin; } + + /**getNumberOfVisits + * @param $archiveGroups + * @param $site + * @param $period + */ + private function launchArchiveProcessor(array $archiveGroups, Site $site, Period $period) + { + $parameters = new ArchiveProcessor\Parameters($site, $period, $this->params->getSegment()); + $processing = new ArchiveProcessor\Loader($parameters); + + $periodString = $period->getRangeString(); + + // process for each plugin as well + foreach ($archiveGroups as $plugin) { + $doneFlag = $this->getDoneStringForPlugin($plugin); + $this->initializeArchiveIdCache($doneFlag); + + $parameters->setRequestedPlugin($plugin); + $idArchive = $processing->prepareArchiveId(); + + if($idArchive) { + $this->idarchives[$doneFlag][$periodString][] = $idArchive; + } + } + } }
\ No newline at end of file diff --git a/core/ArchiveProcessor/Loader.php b/core/ArchiveProcessor/Loader.php index 83ede3cd42..af379d919f 100644 --- a/core/ArchiveProcessor/Loader.php +++ b/core/ArchiveProcessor/Loader.php @@ -57,6 +57,16 @@ class Loader $this->params = $params; } + public function prepareArchiveId() + { + $idArchive = $this->prepareArchive(); + + if ($this->isThereSomeVisits()) { + return $idArchive; + } + return false; + } + /** * A flag mechanism to store whether visits were selected from archive * @@ -73,56 +83,74 @@ class Loader } } - public function getNumberOfVisits() + protected function getNumberOfVisits() { return $this->visitsMetricCached; } - public function getNumberOfVisitsConverted() + protected function getNumberOfVisitsConverted() { return $this->convertedVisitsMetricCached; } - public function preProcessArchive($enforceProcessCoreMetricsOnly = false) + /** + * @return bool + */ + protected function isThereSomeVisits() { - $this->idArchive = false; + return $this->getNumberOfVisits() > 0; + } - if (!$enforceProcessCoreMetricsOnly) { - $this->idArchive = $this->loadExistingArchiveIdFromDb(); - if ($this->isArchivingForcedToTrigger()) { - $this->idArchive = false; - $this->setNumberOfVisits(false); - } - if (!empty($this->idArchive)) { - return $this->idArchive; - } + /** + * @return bool + */ + protected function isVisitsCountAlreadyProcessed() + { + return $this->getNumberOfVisits() !== false; + } + + protected function prepareArchive() + { + $idArchive = $this->loadExistingArchiveIdFromDb(); + if ($this->isArchivingForcedToTrigger()) { + $idArchive = false; + $this->setNumberOfVisits(false); + } + if (!empty($idArchive)) { + return $idArchive; + } + $this->prepareCoreMetricsArchive(); + + return $this->computeNewArchive($enforceProcessCoreMetricsOnly = false); + } - $visitsNotKnownYet = $this->getNumberOfVisits() === false; + protected function prepareCoreMetricsArchive() + { + $createSeparateArchiveForCoreMetrics = + !$this->doesRequestedPluginIncludeVisitsSummary() + && !$this->isVisitsCountAlreadyProcessed(); + + if ($createSeparateArchiveForCoreMetrics) { + $requestedPlugin = $this->params->getRequestedPlugin(); - $createAnotherArchiveForVisitsSummary = !$this->doesRequestedPluginIncludeVisitsSummary() && $visitsNotKnownYet; + $this->params->setRequestedPlugin('VisitsSummary'); - if ($createAnotherArchiveForVisitsSummary) { - // recursive archive creation in case we create another separate one, for VisitsSummary core metrics - // We query VisitsSummary here, as it is needed in the call below ($this->getNumberOfVisits() > 0) - $requestedPlugin = $this->params->getRequestedPlugin(); - $this->params->setRequestedPlugin('VisitsSummary'); + $this->computeNewArchive($enforceProcessCoreMetricsOnly = true); - $this->preProcessArchive($pleaseProcessCoreMetricsOnly = true); + $this->params->setRequestedPlugin($requestedPlugin); - $this->params->setRequestedPlugin($requestedPlugin); - if ($this->getNumberOfVisits() === false) { - throw new \Exception("preProcessArchive() is expected to set number of visits to a numeric value."); - } + if (!$this->isVisitsCountAlreadyProcessed()) { + throw new \Exception("prepareArchive() is expected to set number of visits to a numeric value."); } } - - return $this->computeNewArchive($enforceProcessCoreMetricsOnly); } protected function doesRequestedPluginIncludeVisitsSummary() { - $processAllReportsIncludingVisitsSummary = Rules::shouldProcessReportsAllPlugins($this->params->getSegment(), $this->params->getPeriod()->getLabel()); - $doesRequestedPluginIncludeVisitsSummary = $processAllReportsIncludingVisitsSummary || $this->params->getRequestedPlugin() == 'VisitsSummary'; + $processAllReportsIncludingVisitsSummary = + Rules::shouldProcessReportsAllPlugins($this->params->getSegment(), $this->params->getPeriod()->getLabel()); + $doesRequestedPluginIncludeVisitsSummary = + $processAllReportsIncludingVisitsSummary || $this->params->getRequestedPlugin() == 'VisitsSummary'; return $doesRequestedPluginIncludeVisitsSummary; } @@ -170,8 +198,7 @@ class Loader $archiveProcessor = $this->makeArchiveProcessor($archiveWriter); - $visitsNotKnownYet = $this->getNumberOfVisits() === false; - if ($visitsNotKnownYet + if ($this->isVisitsCountAlreadyProcessed() || $this->doesRequestedPluginIncludeVisitsSummary() || $enforceProcessCoreMetricsOnly ) { @@ -192,8 +219,7 @@ class Loader $archiveProcessor = $this->makeArchiveProcessor($archiveWriter); - $wereThereVisits = $this->getNumberOfVisits() > 0; - if ($wereThereVisits + if ($this->isThereSomeVisits() && !$enforceProcessCoreMetricsOnly ) { $pluginsArchiver = new PluginsArchiver($archiveProcessor); @@ -202,7 +228,7 @@ class Loader $archiveWriter->finalizeArchive(); - if ($wereThereVisits && !$isArchiveDay) { + if ($this->isThereSomeVisits() && !$isArchiveDay) { ArchiveSelector::purgeOutdatedArchives($this->params->getPeriod()->getDateStart()); } |