diff --git a/core/ArchiveProcessing.php b/core/ArchiveProcessing.php index d285cfc53bed16254bd7442abda0bd637dd88d39..c8d41bbc58e28949442f2f94500e7495d02390a4 100644 --- a/core/ArchiveProcessing.php +++ b/core/ArchiveProcessing.php @@ -200,6 +200,8 @@ abstract class Piwik_ArchiveProcessing protected $startTimestampUTC; protected $endTimestampUTC; + protected $segmentsToProcess = null; + /** * Constructor */ @@ -468,35 +470,6 @@ abstract class Piwik_ArchiveProcessing return 'done' . $segment; } - protected function shouldProcessReportsAllPlugins($segment, $period) - { - return $segment->isEmpty() && $period->getLabel() != 'range'; - } - - /** - * When a segment is set, we shall only process the requested report (no more). - * The requested data set will return a lot faster if we only process these reports rather than all plugins. - * Similarly, when a period=range is requested, we shall only process the requested report for the range itself. - * - * @param string $pluginName - * @return bool - */ - public function shouldProcessReportsForPlugin($pluginName) - { - if($this->shouldProcessReportsAllPlugins($this->getSegment(), $this->period)) - { - return true; - } - - - // If segment, only process if the requested report belong to this plugin - // or process all plugins if the requested report plugin couldn't be guessed - $pluginBeingProcessed = self::getPluginBeingProcessed($this->getRequestedReport()); - return $pluginBeingProcessed == $pluginName - || !Piwik_PluginsManager::getInstance()->isPluginLoaded($pluginBeingProcessed) - ; - } - /** * Init the object before launching the real archive processing */ @@ -912,7 +885,10 @@ abstract class Piwik_ArchiveProcessing { return false; } - return !$this->isRequestAuthorizedToArchive(); + $isDisabled = !$this->isRequestAuthorizedToArchive(); + + + return $isDisabled; } protected function isRequestAuthorizedToArchive() @@ -923,4 +899,52 @@ abstract class Piwik_ArchiveProcessing && Piwik_Common::isArchivePhpTriggered()) ; } + + protected function shouldProcessReportsAllPlugins($segment, $period) + { + if($segment->isEmpty() && $period->getLabel() != 'range') + { + return true; + } + + if(is_null($this->segmentsToProcess)) + { + $this->segmentsToProcess = Piwik::getKnownSegmentsToArchive(); + } + if(!empty($this->segmentsToProcess)) + { + // If the requested segment is one of the segments to pre-process + // we ensure that any call to the API will trigger archiving of all reports for this segment + $segment = $this->getSegment()->getString(); + if(in_array($segment, $this->segmentsToProcess)) + { + return true; + } + } + return false; + } + + /** + * When a segment is set, we shall only process the requested report (no more). + * The requested data set will return a lot faster if we only process these reports rather than all plugins. + * Similarly, when a period=range is requested, we shall only process the requested report for the range itself. + * + * @param string $pluginName + * @return bool + */ + public function shouldProcessReportsForPlugin($pluginName) + { + if($this->shouldProcessReportsAllPlugins($this->getSegment(), $this->period)) + { + return true; + } + + // If any other segment, only process if the requested report belong to this plugin + // or process all plugins if the requested report plugin couldn't be guessed + $pluginBeingProcessed = self::getPluginBeingProcessed($this->getRequestedReport()); + return $pluginBeingProcessed == $pluginName + || !Piwik_PluginsManager::getInstance()->isPluginLoaded($pluginBeingProcessed) + ; + } + } diff --git a/core/ArchiveProcessing/Day.php b/core/ArchiveProcessing/Day.php index 978236d94739bb7a893689cad7b64f9305f6b15c..c407faf3a629a36064a26c9ea3f50576339d970e 100644 --- a/core/ArchiveProcessing/Day.php +++ b/core/ArchiveProcessing/Day.php @@ -68,7 +68,7 @@ class Piwik_ArchiveProcessing_Day extends Piwik_ArchiveProcessing // If no specified Segment // Or if a segment is passed and we specifically process VisitsSummary // Then we check the logs. This is to ensure that this query is ran only once for this day/site/segment (rather than running it for every plugin) - if(empty($sqlSegment) + if($this->shouldProcessReportsAllPlugins($this->getSegment(), $this->period) || self::getPluginBeingProcessed($this->getRequestedReport()) == 'VisitsSummary') { $query = "SELECT count(distinct idvisitor) as nb_uniq_visitors, diff --git a/core/Piwik.php b/core/Piwik.php index 1457aebf928cecc4a0f315c8f888bec84c27f78c..a27ec3b4b31c09fb68395b3fa219145f70f9bd07 100644 --- a/core/Piwik.php +++ b/core/Piwik.php @@ -1526,6 +1526,15 @@ class Piwik Zend_Registry::get('config')->General->autocomplete_min_sites); return (int)$count; } + + /** + * Segments to pre-process + */ + static public function getKnownSegmentsToArchive() + { + $segments = Zend_Registry::get('config')->Segments->toArray(); + return isset($segments['Segments']) ? $segments['Segments'] : ''; + } /* * Access diff --git a/plugins/CoreAdminHome/API.php b/plugins/CoreAdminHome/API.php index 48427bbf8bbb37af02f20f829b93924e1d1aaf41..a4910801f950850aaaa50b53f5c1013433eca241 100644 --- a/plugins/CoreAdminHome/API.php +++ b/plugins/CoreAdminHome/API.php @@ -16,6 +16,9 @@ class Piwik_CoreAdminHome_API { static private $instance = null; + /** + * @return Piwik_CoreAdminHome_API + */ static public function getInstance() { if (self::$instance == null) @@ -38,7 +41,6 @@ class Piwik_CoreAdminHome_API public function getKnownSegmentsToArchive() { Piwik::checkUserIsSuperUser(); - $segments = Zend_Registry::get('config')->Segments->toArray(); - return isset($segments['Segments']) ? $segments['Segments'] : ''; + return Piwik::getKnownSegmentsToArchive(); } }