diff options
-rw-r--r-- | core/Archive.php | 9 | ||||
-rw-r--r-- | core/Archive/Parameters.php | 3 | ||||
-rw-r--r-- | core/ArchiveProcessor.php | 15 | ||||
-rw-r--r-- | core/ArchiveProcessor/Loader.php | 11 | ||||
-rw-r--r-- | core/ArchiveProcessor/PluginsArchiver.php | 30 |
5 files changed, 28 insertions, 40 deletions
diff --git a/core/Archive.php b/core/Archive.php index 540a9879b5..d041963d3c 100644 --- a/core/Archive.php +++ b/core/Archive.php @@ -587,7 +587,6 @@ class Archive { $today = Date::today(); - /* @var Period $period */ foreach ($this->params->getPeriods() as $period) { $twoDaysBeforePeriod = $period->getDateStart()->subDay(2); $twoDaysAfterPeriod = $period->getDateEnd()->addDay(2); @@ -611,7 +610,7 @@ class Archive continue; } - $this->launchArchiveProcessor($archiveGroups, $site, $period); + $this->prepareArchives($archiveGroups, $site, $period); } } } @@ -780,10 +779,10 @@ class Archive * @param $site * @param $period */ - private function launchArchiveProcessor(array $archiveGroups, Site $site, Period $period) + private function prepareArchives(array $archiveGroups, Site $site, Period $period) { $parameters = new ArchiveProcessor\Parameters($site, $period, $this->params->getSegment()); - $processing = new ArchiveProcessor\Loader($parameters); + $archiveLoader = new ArchiveProcessor\Loader($parameters); $periodString = $period->getRangeString(); @@ -792,7 +791,7 @@ class Archive $doneFlag = $this->getDoneStringForPlugin($plugin); $this->initializeArchiveIdCache($doneFlag); - $idArchive = $processing->prepareArchive($plugin); + $idArchive = $archiveLoader->prepareArchive($plugin); if($idArchive) { $this->idarchives[$doneFlag][$periodString][] = $idArchive; diff --git a/core/Archive/Parameters.php b/core/Archive/Parameters.php index f55162a93c..093dc1b3d3 100644 --- a/core/Archive/Parameters.php +++ b/core/Archive/Parameters.php @@ -12,6 +12,7 @@ namespace Piwik\Archive; use Exception; +use Piwik\Period; use Piwik\Segment; class Parameters @@ -26,7 +27,7 @@ class Parameters /** * The list of Period's to query archive data for. * - * @var array + * @var Period[] */ private $periods = array(); diff --git a/core/ArchiveProcessor.php b/core/ArchiveProcessor.php index e1ad4f4753..060cd42c33 100644 --- a/core/ArchiveProcessor.php +++ b/core/ArchiveProcessor.php @@ -130,6 +130,17 @@ class ArchiveProcessor $this->archiveWriter = $archiveWriter; } + protected function getArchive() + { + if(empty($this->archive)) { + $subPeriods = $this->params->getPeriod()->getSubperiods(); + $idSite = $this->params->getSite()->getId(); + $this->archive = Archive::factory($this->params->getSegment(), $subPeriods, array($idSite)); + } + return $this->archive; + } + + public function setNumberOfVisits($visits, $visitsConverted) { $this->numberOfVisits = $visits; @@ -246,7 +257,7 @@ class ArchiveProcessor if (!is_array($columns)) { $columns = array($columns); } - $data = $this->archive->getNumeric($columns); + $data = $this->getArchive()->getNumeric($columns); $operationForColumn = $this->getOperationForColumns($columns, $operationToApply); $results = $this->aggregateDataArray($data, $operationForColumn); $results = $this->defaultColumnsToZero($columns, $results); @@ -345,7 +356,7 @@ class ArchiveProcessor $table->setMetadata(DataTable::COLUMN_AGGREGATION_OPS_METADATA_NAME, $columnAggregationOperations); } - $data = $this->archive->getDataTableExpanded($name, $idSubTable = null, $depth = null, $addMetadataSubtableId = false); +`` $data = $this->getArchive()->getDataTableExpanded($name, $idSubTable = null, $depth = null, $addMetadataSubtableId = false); if ($data instanceof DataTable\Map) { // as $date => $tableToSum foreach ($data->getDataTables() as $tableToSum) { diff --git a/core/ArchiveProcessor/Loader.php b/core/ArchiveProcessor/Loader.php index 7f3e5eff9e..3fee34543f 100644 --- a/core/ArchiveProcessor/Loader.php +++ b/core/ArchiveProcessor/Loader.php @@ -86,9 +86,8 @@ class Loader */ protected function prepareCoreMetricsArchive($visits, $visitsConverted) { - $createSeparateArchiveForCoreMetrics = - !$this->doesRequestedPluginIncludeVisitsSummary() - && $this->mustProcessVisitCount($visits); + $createSeparateArchiveForCoreMetrics = $this->mustProcessVisitCount($visits) + && !$this->doesRequestedPluginIncludeVisitsSummary(); if ($createSeparateArchiveForCoreMetrics) { $requestedPlugin = $this->params->getRequestedPlugin(); @@ -103,9 +102,6 @@ class Loader $visits = $metrics['nb_visits']; $visitsConverted = $metrics['nb_visits_converted']; - if($this->mustProcessVisitCount($visits)) { - throw new \Exception("Visit count should have been set in computeNewArchive()."); - } } return array($visits, $visitsConverted); } @@ -120,9 +116,6 @@ class Loader $visits = $metrics['nb_visits']; $visitsConverted = $metrics['nb_visits_converted']; } - if ($this->mustProcessVisitCount($visits)) { - throw new \Exception("Visit count should have been set in callAggregateCoreMetrics()."); - } if ($this->isThereSomeVisits($visits)) { $pluginsArchiver->callAggregateAllPlugins($visits, $visitsConverted); } diff --git a/core/ArchiveProcessor/PluginsArchiver.php b/core/ArchiveProcessor/PluginsArchiver.php index 4f1c245a9a..31e399f3c1 100644 --- a/core/ArchiveProcessor/PluginsArchiver.php +++ b/core/ArchiveProcessor/PluginsArchiver.php @@ -46,7 +46,9 @@ class PluginsArchiver $this->archiveWriter = new ArchiveWriter($this->params, $isTemporaryArchive); $this->archiveWriter->initNewArchive(); - $this->archiveProcessor = $this->makeArchiveProcessor($this->archiveWriter); + $this->archiveProcessor = new ArchiveProcessor($this->params, $this->archiveWriter); + + $this->isArchiveDay = $this->params->isDayArchive(); } /** @@ -56,7 +58,7 @@ class PluginsArchiver */ public function callAggregateCoreMetrics() { - if($this->params->isDayArchive()) { + if($this->isArchiveDay) { $metrics = $this->aggregateDayVisitsMetrics(); } else { $metrics = $this->aggregateMultipleVisitsMetrics(); @@ -82,8 +84,6 @@ class PluginsArchiver { $this->archiveProcessor->setNumberOfVisits($visits, $visitsConverted); - $isAggregateForDay = $this->archiveProcessor->getParams()->isDayArchive(); - $archivers = $this->getPluginArchivers(); foreach($archivers as $pluginName => $archiverClass) { @@ -91,7 +91,7 @@ class PluginsArchiver $archiver = new $archiverClass($this->archiveProcessor); if($this->shouldProcessReportsForPlugin($pluginName)) { - if($isAggregateForDay) { + if($this->isArchiveDay) { $archiver->aggregateDayReport(); } else { $archiver->aggregateMultipleReports(); @@ -99,7 +99,7 @@ class PluginsArchiver } } - if (!$isAggregateForDay && $visits) { + if (!$this->isArchiveDay && $visits) { ArchiveSelector::purgeOutdatedArchives($this->params->getPeriod()->getDateStart()); } } @@ -146,7 +146,6 @@ class PluginsArchiver */ protected function shouldProcessReportsForPlugin($pluginName) { - // If any other segment, only process if the requested report belong to this plugin if ($this->params->getRequestedPlugin() == $pluginName) { return true; } @@ -155,28 +154,13 @@ class PluginsArchiver $this->archiveProcessor->getParams()->getPeriod()->getLabel())) { return true; } + if (!\Piwik\Plugin\Manager::getInstance()->isPluginLoaded($this->params->getRequestedPlugin())) { return true; } return false; } - - /** - * @param $archiveWriter - * @return ArchiveProcessor - */ - protected function makeArchiveProcessor() - { - $archiveProcessor = new ArchiveProcessor($this->params, $this->archiveWriter); - - if (!$this->params->isDayArchive()) { - $subPeriods = $this->params->getPeriod()->getSubperiods(); - $archiveProcessor->archive = Archive::factory($this->params->getSegment(), $subPeriods, array($this->params->getSite()->getId())); - } - return $archiveProcessor; - } - protected function aggregateDayVisitsMetrics() { $query = $this->archiveProcessor->getLogAggregator()->queryVisitsByDimension(); |