Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormattab <matthieu.aubry@gmail.com>2013-10-20 07:54:21 +0400
committermattab <matthieu.aubry@gmail.com>2013-10-20 07:54:21 +0400
commited9cd9eb2bd61b2db833092f31606fe68d7ae396 (patch)
tree2633315e7e020456aa16dd1ad80c1824cd5b82b9 /plugins/Actions/Archiver.php
parentcab7c1472b7c135314d4da7b1055af25ff7f0009 (diff)
Some refactoring and preparations for custom events ref #472
PHP Tracker and Tests fixtures Schema updates
Diffstat (limited to 'plugins/Actions/Archiver.php')
-rw-r--r--plugins/Actions/Archiver.php126
1 files changed, 19 insertions, 107 deletions
diff --git a/plugins/Actions/Archiver.php b/plugins/Actions/Archiver.php
index 99cabed9b3..6c8fcf5107 100644
--- a/plugins/Actions/Archiver.php
+++ b/plugins/Actions/Archiver.php
@@ -10,9 +10,6 @@
*/
namespace Piwik\Plugins\Actions;
-use Piwik\Config;
-use Piwik\DataTable\Manager;
-use Piwik\DataTable\Row\DataTableSummaryRow;
use Piwik\DataTable;
use Piwik\Metrics;
use Piwik\RankingQuery;
@@ -55,10 +52,10 @@ class Archiver extends \Piwik\Plugin\Archiver
);
public static $actionTypes = array(
- Action::TYPE_ACTION_URL,
+ Action::TYPE_PAGE_URL,
Action::TYPE_OUTLINK,
Action::TYPE_DOWNLOAD,
- Action::TYPE_ACTION_NAME,
+ Action::TYPE_PAGE_TITLE,
Action::TYPE_SITE_SEARCH,
);
static protected $invalidSummedColumnNameToRenamedNameFromPeriodArchive = array(
@@ -66,7 +63,7 @@ class Archiver extends \Piwik\Plugin\Archiver
Metrics::INDEX_PAGE_ENTRY_NB_UNIQ_VISITORS => Metrics::INDEX_PAGE_ENTRY_SUM_DAILY_NB_UNIQ_VISITORS,
Metrics::INDEX_PAGE_EXIT_NB_UNIQ_VISITORS => Metrics::INDEX_PAGE_EXIT_SUM_DAILY_NB_UNIQ_VISITORS,
);
- static protected $invalidSummedColumnNameToDeleteFromDayArchive = array(
+ static public $invalidSummedColumnNameToDeleteFromDayArchive = array(
Metrics::INDEX_NB_UNIQ_VISITORS,
Metrics::INDEX_PAGE_ENTRY_NB_UNIQ_VISITORS,
Metrics::INDEX_PAGE_EXIT_NB_UNIQ_VISITORS,
@@ -91,34 +88,7 @@ class Archiver extends \Piwik\Plugin\Archiver
*/
public function archiveDay()
{
- $rankingQueryLimit = self::getRankingQueryLimit();
-
- // FIXME: This is a quick fix for #3482. The actual cause of the bug is that
- // the site search & performance metrics additions to
- // ArchivingHelper::updateActionsTableWithRowQuery expect every
- // row to have 'type' data, but not all of the SQL queries that are run w/o
- // ranking query join on the log_action table and thus do not select the
- // log_action.type column.
- //
- // NOTES: Archiving logic can be generalized as follows:
- // 0) Do SQL query over log_link_visit_action & join on log_action to select
- // some metrics (like visits, hits, etc.)
- // 1) For each row, cache the action row & metrics. (This is done by
- // updateActionsTableWithRowQuery for result set rows that have
- // name & type columns.)
- // 2) Do other SQL queries for metrics we can't put in the first query (like
- // entry visits, exit vists, etc.) w/o joining log_action.
- // 3) For each row, find the cached row by idaction & add the new metrics to
- // it. (This is done by updateActionsTableWithRowQuery for result set rows
- // that DO NOT have name & type columns.)
- //
- // The site search & performance metrics additions expect a 'type' all the time
- // which breaks the original pre-rankingquery logic. Ranking query requires a
- // join, so the bug is only seen when ranking query is disabled.
- if ($rankingQueryLimit === 0) {
- $rankingQueryLimit = 100000;
- }
-
+ $rankingQueryLimit = ArchivingHelper::getRankingQueryLimit();
ArchivingHelper::reloadConfig();
$this->initActionsTables();
@@ -133,26 +103,6 @@ class Archiver extends \Piwik\Plugin\Archiver
}
/**
- * Returns the limit to use with RankingQuery for this plugin.
- *
- * @return int
- */
- private static function getRankingQueryLimit()
- {
- $configGeneral = Config::getInstance()->General;
- $configLimit = $configGeneral['archiving_ranking_query_row_limit'];
- return $configLimit == 0 ? 0 : max(
- $configLimit,
- $configGeneral['datatable_archiving_maximum_rows_actions'],
- $configGeneral['datatable_archiving_maximum_rows_subtable_actions']
- );
- }
-
- /*
- * Page URLs and Page names, general stats
- */
-
- /**
* Initializes the DataTables created by the archiveDay function.
*/
private function initActionsTables()
@@ -162,8 +112,8 @@ class Archiver extends \Piwik\Plugin\Archiver
$dataTable = new DataTable();
$dataTable->setMaximumAllowedRows(ArchivingHelper::$maximumRowsInDataTableLevelZero);
- if ($type == Action::TYPE_ACTION_URL
- || $type == Action::TYPE_ACTION_NAME
+ if ($type == Action::TYPE_PAGE_URL
+ || $type == Action::TYPE_PAGE_TITLE
) {
// for page urls and page titles, performance metrics exist and have to be aggregated correctly
$dataTable->setColumnAggregationOperations(self::$actionColumnAggregationOperations);
@@ -239,7 +189,10 @@ class Archiver extends \Piwik\Plugin\Archiver
// 2) For each page view, count number of times the referrer page was a Site Search
if ($this->isSiteSearchEnabled()) {
$selectFlagNoResultKeywords = ",
- CASE WHEN (MAX(log_link_visit_action.custom_var_v" . Action::CVAR_INDEX_SEARCH_COUNT . ") = 0 AND log_link_visit_action.custom_var_k" . Action::CVAR_INDEX_SEARCH_COUNT . " = '" . Action::CVAR_KEY_SEARCH_COUNT . "') THEN 1 ELSE 0 END AS `" . Metrics::INDEX_SITE_SEARCH_HAS_NO_RESULT . "`";
+ CASE WHEN (MAX(log_link_visit_action.custom_var_v" . Action::CVAR_INDEX_SEARCH_COUNT . ") = 0
+ AND log_link_visit_action.custom_var_k" . Action::CVAR_INDEX_SEARCH_COUNT . " = '" . Action::CVAR_KEY_SEARCH_COUNT . "')
+ THEN 1 ELSE 0 END
+ AS `" . Metrics::INDEX_SITE_SEARCH_HAS_NO_RESULT . "`";
//we need an extra JOIN to know whether the referrer "idaction_name_ref" was a Site Search request
$from[] = array(
@@ -248,11 +201,13 @@ class Archiver extends \Piwik\Plugin\Archiver
"joinOn" => "log_link_visit_action.idaction_name_ref = log_action_name_ref.idaction"
);
- $selectSiteSearchFollowingPages = ",
- SUM(CASE WHEN log_action_name_ref.type = " . Action::TYPE_SITE_SEARCH . " THEN 1 ELSE 0 END) AS `" . Metrics::INDEX_PAGE_IS_FOLLOWING_SITE_SEARCH_NB_HITS . "`";
+ $selectPageIsFollowingSiteSearch = ",
+ SUM( CASE WHEN log_action_name_ref.type = " . Action::TYPE_SITE_SEARCH. "
+ THEN 1 ELSE 0 END)
+ AS `" . Metrics::INDEX_PAGE_IS_FOLLOWING_SITE_SEARCH_NB_HITS . "`";
$select .= $selectFlagNoResultKeywords
- . $selectSiteSearchFollowingPages;
+ . $selectPageIsFollowingSiteSearch;
}
$this->archiveDayQueryProcess($select, $from, $where, $orderBy, $groupBy, "idaction_name", $rankingQuery);
@@ -267,9 +222,6 @@ class Archiver extends \Piwik\Plugin\Archiver
protected function archiveDayQueryProcess($select, $from, $where, $orderBy, $groupBy, $sprintfField, $rankingQuery = false)
{
- // idaction field needs to be set in select clause before calling getSelectQuery().
- // if a complex segmentation join is needed, the field needs to be propagated
- // to the outer select. therefore, $segment needs to know about it.
$select = sprintf($select, $sprintfField);
// get query with segmentation
@@ -446,7 +398,7 @@ class Archiver extends \Piwik\Plugin\Archiver
protected function recordPageUrlsReports()
{
- $dataTable = $this->getDataTable(Action::TYPE_ACTION_URL);
+ $dataTable = $this->getDataTable(Action::TYPE_PAGE_URL);
$this->recordDataTable($dataTable, self::PAGE_URLS_RECORD_NAME);
$records = array(
@@ -467,53 +419,13 @@ class Archiver extends \Piwik\Plugin\Archiver
return $this->actionsTablesByType[$typeId];
}
- protected function recordDataTable($dataTable, $recordName)
+ protected function recordDataTable(DataTable $dataTable, $recordName)
{
- self::deleteInvalidSummedColumnsFromDataTable($dataTable);
+ ArchivingHelper::deleteInvalidSummedColumnsFromDataTable($dataTable);
$s = $dataTable->getSerialized(ArchivingHelper::$maximumRowsInDataTableLevelZero, ArchivingHelper::$maximumRowsInSubDataTable, ArchivingHelper::$columnToSortByBeforeTruncation);
$this->getProcessor()->insertBlobRecord($recordName, $s);
}
- /**
- * For rows which have subtables (eg. directories with sub pages),
- * deletes columns which don't make sense when all values of sub pages are summed.
- *
- * @param $dataTable DataTable
- */
- static public function deleteInvalidSummedColumnsFromDataTable($dataTable)
- {
- foreach ($dataTable->getRows() as $id => $row) {
- if (($idSubtable = $row->getIdSubDataTable()) !== null
- || $id === DataTable::ID_SUMMARY_ROW
- ) {
- if ($idSubtable !== null) {
- $subtable = Manager::getInstance()->getTable($idSubtable);
- self::deleteInvalidSummedColumnsFromDataTable($subtable);
- }
-
- if ($row instanceof DataTableSummaryRow) {
- $row->recalculate();
- }
-
- foreach (self::$invalidSummedColumnNameToDeleteFromDayArchive as $name) {
- $row->deleteColumn($name);
- }
- }
- }
-
- // And this as well
- self::removeEmptyColumns($dataTable);
- }
-
- static protected function removeEmptyColumns($dataTable)
- {
- // Delete all columns that have a value of zero
- $dataTable->filter('ColumnDelete', array(
- $columnsToRemove = array(Metrics::INDEX_PAGE_IS_FOLLOWING_SITE_SEARCH_NB_HITS),
- $columnsToKeep = array(),
- $deleteIfZeroOnly = true
- ));
- }
protected function recordDownloadsReports()
{
@@ -535,7 +447,7 @@ class Archiver extends \Piwik\Plugin\Archiver
protected function recordPageTitlesReports()
{
- $dataTable = $this->getDataTable(Action::TYPE_ACTION_NAME);
+ $dataTable = $this->getDataTable(Action::TYPE_PAGE_TITLE);
$this->recordDataTable($dataTable, self::PAGE_TITLES_RECORD_NAME);
}