diff options
Diffstat (limited to 'plugins/UserId/Archiver.php')
-rw-r--r-- | plugins/UserId/Archiver.php | 48 |
1 files changed, 44 insertions, 4 deletions
diff --git a/plugins/UserId/Archiver.php b/plugins/UserId/Archiver.php index 584f364d3c..b5a5f908b0 100644 --- a/plugins/UserId/Archiver.php +++ b/plugins/UserId/Archiver.php @@ -10,7 +10,8 @@ namespace Piwik\Plugins\UserId; use Piwik\Config; use Piwik\DataArray; use Piwik\DataTable; -use Piwik\Metrics; +use Piwik\Metrics as PiwikMetrics; +use Piwik\RankingQuery; /** * Archiver that aggregates metrics per user ID (user_id field). @@ -77,11 +78,24 @@ class Archiver extends \Piwik\Plugin\Archiver $userIdFieldName = self::USER_ID_FIELD; $visitorIdFieldName = self::VISITOR_ID_FIELD; + $rankingQueryLimit = $this->getRankingQueryLimit(); + + $rankingQuery = false; + if ($rankingQueryLimit > 0) { + $rankingQuery = new RankingQuery($rankingQueryLimit); + $rankingQuery->setOthersLabel(DataTable::LABEL_SUMMARY_ROW); + $rankingQuery->addLabelColumn($userIdFieldName); + $rankingQuery->addLabelColumn($visitorIdFieldName); + } + /** @var \Zend_Db_Statement $query */ $query = $this->getLogAggregator()->queryVisitsByDimension( array(self::USER_ID_FIELD), "log_visit.$userIdFieldName IS NOT NULL AND log_visit.$userIdFieldName != ''", - array("LOWER(HEX($visitorIdFieldName)) as $visitorIdFieldName") + array("LOWER(HEX($visitorIdFieldName)) as $visitorIdFieldName"), + $metrics = false, + $rankingQuery, + self::USER_ID_FIELD . ' ASC' ); if ($query === false) { @@ -89,7 +103,7 @@ class Archiver extends \Piwik\Plugin\Archiver } $rowsCount = 0; - while ($row = $query->fetch()) { + foreach ($query as $row) { $rowsCount++; $this->arrays->sumMetricsVisits($row[$userIdFieldName], $row); $this->rememberVisitorId($row); @@ -105,8 +119,23 @@ class Archiver extends \Piwik\Plugin\Archiver { /** @var DataTable $dataTable */ $dataTable = $this->arrays->asDataTable(); + + // deal w/ ranking query summary row + $rankingQuerySummaryRow = $dataTable->getRowFromLabel(DataTable::LABEL_SUMMARY_ROW); + if ($rankingQuerySummaryRow) { + $rankingQuerySummaryRowId = $dataTable->getRowIdFromLabel(DataTable::LABEL_SUMMARY_ROW); + $dataTable->deleteRow($rankingQuerySummaryRowId); + + $actualSummaryRow = $dataTable->getRowFromId(DataTable::ID_SUMMARY_ROW); + if ($actualSummaryRow) { + $actualSummaryRow->sumRow($rankingQuerySummaryRow); + } else { + $dataTable->addSummaryRow($rankingQuerySummaryRow); + } + } + $this->setVisitorIds($dataTable); - $report = $dataTable->getSerialized($this->maximumRowsInDataTableLevelZero, null, Metrics::INDEX_NB_VISITS); + $report = $dataTable->getSerialized($this->maximumRowsInDataTableLevelZero, null, PiwikMetrics::INDEX_NB_VISITS); $this->getProcessor()->insertBlobRecord(self::USERID_ARCHIVE_RECORD, $report); } @@ -137,4 +166,15 @@ class Archiver extends \Piwik\Plugin\Archiver } } + private function getRankingQueryLimit() + { + $configGeneral = Config::getInstance()->General; + $configLimit = $configGeneral['archiving_ranking_query_row_limit']; + $limit = $configLimit == 0 ? 0 : max( + $configLimit, + $this->maximumRowsInDataTableLevelZero + ); + return $limit; + } + }
\ No newline at end of file |