From 4b4277b3acab454b69ded4557deba3271ff93b9b Mon Sep 17 00:00:00 2001 From: diosmosis <benaka.moorthi@gmail.com> Date: Sat, 13 Apr 2013 06:21:48 +0000 Subject: [PATCH] Fixes #3482, apply quick fix so Piwik works when ranking query is disabled and added test for disabled ranking query. Added FIXME comment to make sure underlying issue is eventually dealt with. --- plugins/Actions/Archiving.php | 27 ++++++++++++++++ plugins/Actions/ArchivingHelper.php | 2 ++ .../Integration/BlobReportLimitingTest.php | 32 +++++++++++++++++++ 3 files changed, 61 insertions(+) diff --git a/plugins/Actions/Archiving.php b/plugins/Actions/Archiving.php index 3abe7a45f0..fa514b6ef9 100644 --- a/plugins/Actions/Archiving.php +++ b/plugins/Actions/Archiving.php @@ -106,6 +106,33 @@ class Piwik_Actions_Archiving public function archiveDay(Piwik_ArchiveProcessing $archiveProcessing) { $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 + // Piwik_Actions_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; + } + Piwik_Actions_ArchivingHelper::reloadConfig(); $this->initActionsTables(); diff --git a/plugins/Actions/ArchivingHelper.php b/plugins/Actions/ArchivingHelper.php index 3b4df0fee8..e5773d96e6 100644 --- a/plugins/Actions/ArchivingHelper.php +++ b/plugins/Actions/ArchivingHelper.php @@ -22,6 +22,8 @@ class Piwik_Actions_ArchivingHelper const OTHERS_ROW_KEY = ''; /** + * FIXME See FIXME related to this function at Piwik_Actions_Archiving::archiveDay. + * * @param Zend_Db_Statement|PDOStatement $query * @param string|bool $fieldQueried * @param array $actionsTablesByType diff --git a/tests/PHPUnit/Integration/BlobReportLimitingTest.php b/tests/PHPUnit/Integration/BlobReportLimitingTest.php index b18c7707d8..e64a77e44d 100755 --- a/tests/PHPUnit/Integration/BlobReportLimitingTest.php +++ b/tests/PHPUnit/Integration/BlobReportLimitingTest.php @@ -48,6 +48,15 @@ class Test_Piwik_Integration_BlobReportLimitingTest extends IntegrationTestCase 'periods' => 'day')), ); } + + public function getRankingQueryDisabledApiForTesting() + { + return array( + array('Actions.getPageUrls', array('idSite' => self::$fixture->idSite, + 'date' => self::$fixture->dateTime, + 'periods' => array('day'))), + ); + } /** * @dataProvider getApiForTesting @@ -82,6 +91,29 @@ class Test_Piwik_Integration_BlobReportLimitingTest extends IntegrationTestCase $this->runApiTests($apiToCall, $params); } } + + /** + * @group Integration + * @group BlobReportLimiting + */ + public function testApiWithRankingQueryDisabled() + { + self::deleteArchiveTables(); + $generalConfig =& Piwik_Config::getInstance()->General; + $generalConfig['datatable_archiving_maximum_rows_referers'] = 500; + $generalConfig['datatable_archiving_maximum_rows_subtable_referers'] = 500; + $generalConfig['datatable_archiving_maximum_rows_actions'] = 500; + $generalConfig['datatable_archiving_maximum_rows_subtable_actions'] = 500; + $generalConfig['datatable_archiving_maximum_rows_standard'] = 500; + $generalConfig['archiving_ranking_query_row_limit'] = 0; + + foreach ($this->getRankingQueryDisabledApiForTesting() as $pair) { + list($apiToCall, $params) = $pair; + $params['testSuffix'] = '_rankingQueryDisabled'; + + $this->runApiTests($apiToCall, $params); + } + } public function getOutputPrefix() { -- GitLab