diff options
-rw-r--r-- | core/ArchiveProcessor/Parameters.php | 10 | ||||
-rw-r--r-- | core/ArchiveProcessor/PluginsArchiver.php | 29 | ||||
-rw-r--r-- | plugins/Actions/Archiver.php | 24 | ||||
-rw-r--r-- | plugins/Contents/Archiver.php | 12 | ||||
-rw-r--r-- | plugins/Events/Archiver.php | 6 | ||||
-rw-r--r-- | tests/PHPUnit/Integration/ArchiveProcessor/PluginsArchiverTest.php | 23 |
6 files changed, 71 insertions, 33 deletions
diff --git a/core/ArchiveProcessor/Parameters.php b/core/ArchiveProcessor/Parameters.php index ed95b71c02..fdbfe3e4f0 100644 --- a/core/ArchiveProcessor/Parameters.php +++ b/core/ArchiveProcessor/Parameters.php @@ -196,13 +196,19 @@ class Parameters */ public function isSingleSiteDayArchive() { - $oneSite = $this->isSingleSite(); + return $this->isDayArchive() && $this->isSingleSite(); + } + /** + * @return bool + */ + public function isDayArchive() + { $period = $this->getPeriod(); $secondsInPeriod = $period->getDateEnd()->getTimestampUTC() - $period->getDateStart()->getTimestampUTC(); $oneDay = $secondsInPeriod <= Date::NUM_SECONDS_IN_DAY; - return $oneDay && $oneSite; + return $oneDay; } public function isSingleSite() diff --git a/core/ArchiveProcessor/PluginsArchiver.php b/core/ArchiveProcessor/PluginsArchiver.php index a075f094f7..8253604029 100644 --- a/core/ArchiveProcessor/PluginsArchiver.php +++ b/core/ArchiveProcessor/PluginsArchiver.php @@ -49,6 +49,12 @@ class PluginsArchiver */ public static $archivers = array(); + /** + * Defines if we should aggregate from raw data by using MySQL queries (when true) or aggregate archives (when false) + * @var bool + */ + private $shouldAggregateFromRawData; + public function __construct(Parameters $params, $isTemporaryArchive, ArchiveWriter $archiveWriter = null) { $this->params = $params; @@ -60,7 +66,24 @@ class PluginsArchiver $this->archiveProcessor = new ArchiveProcessor($this->params, $this->archiveWriter, $this->logAggregator); - $this->isSingleSiteDayArchive = $this->params->isSingleSiteDayArchive(); + $shouldAggregateFromRawData = $this->params->isSingleSiteDayArchive(); + + /** + * Triggered to detect if the archiver should aggregate from raw data by using MySQL queries (when true) + * or by aggregate archives (when false). Typically, data is aggregated from raw data for "day" period, and + * aggregregated from archives for all other periods. + * + * @param bool $shouldAggregateFromRawData Set to true, to aggregate from raw data, or false to aggregate multiple reports. + * @param Parameters $params + * @ignore + * @deprecated + * + * In Matomo 4.0 we should maybe remove this event, and instead maybe always archive from raw data when it is daily archive, + * no matter if single site or not. We cannot do this in Matomo 3.X as some custom plugin archivers may not be able to handle multiple sites. + */ + Piwik::postEvent('ArchiveProcessor.shouldAggregateFromRawData', array(&$shouldAggregateFromRawData, $this->params)); + + $this->shouldAggregateFromRawData = $shouldAggregateFromRawData; } /** @@ -72,7 +95,7 @@ class PluginsArchiver { $this->logAggregator->setQueryOriginHint('Core'); - if ($this->isSingleSiteDayArchive) { + if ($this->shouldAggregateFromRawData) { $metrics = $this->aggregateDayVisitsMetrics(); } else { $metrics = $this->aggregateMultipleVisitsMetrics(); @@ -126,7 +149,7 @@ class PluginsArchiver try { $timer = new Timer(); - if ($this->isSingleSiteDayArchive) { + if ($this->shouldAggregateFromRawData) { Log::debug("PluginsArchiver::%s: Archiving day reports for plugin '%s'.", __FUNCTION__, $pluginName); $archiver->aggregateDayReport(); diff --git a/plugins/Actions/Archiver.php b/plugins/Actions/Archiver.php index af84c385a6..f49e4e15c5 100644 --- a/plugins/Actions/Archiver.php +++ b/plugins/Actions/Archiver.php @@ -161,10 +161,8 @@ class Archiver extends \Piwik\Plugin\Archiver ) ); - $where = "log_link_visit_action.server_time >= ? - AND log_link_visit_action.server_time <= ? - AND log_link_visit_action.idsite = ? - AND log_link_visit_action.%s IS NOT NULL" + $where = $this->getLogAggregator()->getWhereStatement('log_link_visit_action', 'server_time'); + $where .= " AND log_link_visit_action.%s IS NOT NULL" . $this->getWhereClauseActionIsNotEvent(); $groupBy = "log_link_visit_action.%s"; @@ -285,10 +283,8 @@ class Archiver extends \Piwik\Plugin\Archiver sum(log_visit.visit_total_time) as `" . PiwikMetrics::INDEX_PAGE_ENTRY_SUM_VISIT_LENGTH . "`, sum(case log_visit.visit_total_actions when 1 then 1 when 0 then 1 else 0 end) as `" . PiwikMetrics::INDEX_PAGE_ENTRY_BOUNCE_COUNT . "`"; - $where = "log_visit.visit_last_action_time >= ? - AND log_visit.visit_last_action_time <= ? - AND log_visit.idsite = ? - AND log_visit.%s > 0"; + $where = $this->getLogAggregator()->getWhereStatement('log_visit', 'visit_last_action_time'); + $where .= " AND log_visit.%s > 0"; $groupBy = "log_visit.%s"; @@ -330,10 +326,8 @@ class Archiver extends \Piwik\Plugin\Archiver count(distinct log_visit.idvisitor) as `" . PiwikMetrics::INDEX_PAGE_EXIT_NB_UNIQ_VISITORS . "`, count(*) as `" . PiwikMetrics::INDEX_PAGE_EXIT_NB_VISITS . "`"; - $where = "log_visit.visit_last_action_time >= ? - AND log_visit.visit_last_action_time <= ? - AND log_visit.idsite = ? - AND log_visit.%s > 0"; + $where = $this->getLogAggregator()->getWhereStatement('log_visit', 'visit_last_action_time'); + $where .= " AND log_visit.%s > 0"; $groupBy = "log_visit.%s"; @@ -374,10 +368,8 @@ class Archiver extends \Piwik\Plugin\Archiver $select = "log_link_visit_action.%s as idaction, $extraSelects sum(log_link_visit_action.time_spent_ref_action) as `" . PiwikMetrics::INDEX_PAGE_SUM_TIME_SPENT . "`"; - $where = "log_link_visit_action.server_time >= ? - AND log_link_visit_action.server_time <= ? - AND log_link_visit_action.idsite = ? - AND log_link_visit_action.time_spent_ref_action > 0 + $where = $this->getLogAggregator()->getWhereStatement('log_link_visit_action', 'server_time'); + $where .= " AND log_link_visit_action.time_spent_ref_action > 0 AND log_link_visit_action.%s > 0" . $this->getWhereClauseActionIsNotEvent(); diff --git a/plugins/Contents/Archiver.php b/plugins/Contents/Archiver.php index ea922195b6..9a642e29bd 100644 --- a/plugins/Contents/Archiver.php +++ b/plugins/Contents/Archiver.php @@ -103,10 +103,8 @@ class Archiver extends \Piwik\Plugin\Archiver ) ); - $where = "log_link_visit_action.server_time >= ? - AND log_link_visit_action.server_time <= ? - AND log_link_visit_action.idsite = ? - AND log_link_visit_action.idaction_content_name IS NOT NULL + $where = $this->getLogAggregator()->getWhereStatement('log_link_visit_action', 'server_time'); + $where .= " AND log_link_visit_action.idaction_content_name IS NOT NULL AND log_link_visit_action.idaction_content_interaction IS NULL"; $groupBy = "log_link_visit_action.idaction_content_piece, @@ -161,10 +159,8 @@ class Archiver extends \Piwik\Plugin\Archiver ) ); - $where = "log_link_visit_action.server_time >= ? - AND log_link_visit_action.server_time <= ? - AND log_link_visit_action.idsite = ? - AND log_link_visit_action.idaction_content_name IS NOT NULL + $where = $this->getLogAggregator()->getWhereStatement('log_link_visit_action', 'server_time'); + $where .= " AND log_link_visit_action.idaction_content_name IS NOT NULL AND log_link_visit_action.idaction_content_interaction IS NOT NULL"; $groupBy = "log_action_content_piece.idaction, diff --git a/plugins/Events/Archiver.php b/plugins/Events/Archiver.php index 69531a5c81..0146fa738f 100644 --- a/plugins/Events/Archiver.php +++ b/plugins/Events/Archiver.php @@ -167,10 +167,8 @@ class Archiver extends \Piwik\Plugin\Archiver ) ); - $where = "log_link_visit_action.server_time >= ? - AND log_link_visit_action.server_time <= ? - AND log_link_visit_action.idsite = ? - AND log_link_visit_action.idaction_event_category IS NOT NULL"; + $where = $this->getLogAggregator()->getWhereStatement('log_link_visit_action', 'server_time'); + $where .= " AND log_link_visit_action.idaction_event_category IS NOT NULL"; $groupBy = "log_link_visit_action.idaction_event_category, log_link_visit_action.idaction_event_action, diff --git a/tests/PHPUnit/Integration/ArchiveProcessor/PluginsArchiverTest.php b/tests/PHPUnit/Integration/ArchiveProcessor/PluginsArchiverTest.php index 3c22fd934c..7cb234d91f 100644 --- a/tests/PHPUnit/Integration/ArchiveProcessor/PluginsArchiverTest.php +++ b/tests/PHPUnit/Integration/ArchiveProcessor/PluginsArchiverTest.php @@ -9,6 +9,7 @@ namespace Piwik\Tests\Integration\Archive; use Piwik\ArchiveProcessor\PluginsArchiver; use Piwik\Config; +use Piwik\Piwik; use Piwik\Segment; use Piwik\Site; use Piwik\Db; @@ -64,6 +65,8 @@ class PluginsArchiverTest extends IntegrationTestCase parent::setUp(); Fixture::createWebsite('2015-01-01 00:00:00'); + Fixture::createWebsite('2015-01-01 00:00:00'); + Fixture::createWebsite('2015-01-01 00:00:00'); $this->pluginsArchiver = new CustomPluginsArchiver($this->createArchiveProcessorParamaters(), $isTemporary = false); } @@ -88,4 +91,24 @@ class PluginsArchiverTest extends IntegrationTestCase $this->pluginsArchiver->callAggregateAllPlugins(1, 1); } + public function test_archiveMultipleSites() + { + Piwik::addAction('ArchiveProcessor.Parameters.getIdSites', function (&$idSites, $period) { + if (count($idSites) === 1 && reset($idSites) === 1) { + $idSites = array(2,3); + } + }); + + Piwik::addAction('ArchiveProcessor.shouldAggregateFromRawData', function (&$shouldAggregateRawData, Parameters $params) { + // needed as by default we would only aggregate for single site + if ($params->isDayArchive()) { + $shouldAggregateRawData = true; + } + }); + + $this->pluginsArchiver = new PluginsArchiver($this->createArchiveProcessorParamaters(), $isTemporary = false); + $this->pluginsArchiver->callAggregateCoreMetrics(); + $this->pluginsArchiver->callAggregateAllPlugins(1, 1, $forceArchivingWithoutVisits = true); + } + }
\ No newline at end of file |