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:
-rw-r--r--core/Tracker/Visit.php44
-rw-r--r--tests/PHPUnit/BaseFixture.php30
-rw-r--r--tests/PHPUnit/Fixtures/ManySitesImportedLogs.php29
-rw-r--r--tests/PHPUnit/Fixtures/ManyVisitsWithGeoIP.php5
-rwxr-xr-xtests/PHPUnit/Integration/ManyVisitorsOneWebsiteTest.php3
-rwxr-xr-xtests/PHPUnit/IntegrationTestCase.php8
-rw-r--r--tests/PHPUnit/Plugins/SegmentEditorTest.php16
7 files changed, 76 insertions, 59 deletions
diff --git a/core/Tracker/Visit.php b/core/Tracker/Visit.php
index fceb5bdaa3..d4b0b53eb9 100644
--- a/core/Tracker/Visit.php
+++ b/core/Tracker/Visit.php
@@ -1121,10 +1121,7 @@ class Piwik_Tracker_Visit implements Piwik_Tracker_Visit_Interface
";
$from = "FROM " . Piwik_Common::prefixTable('log_visit');
- $bindSql = array();
-
-
- $timeLookBack = $this->getWindowLookupPreviousVisit();
+ list($timeLookBack,$timeLookAhead) = $this->getWindowLookupThisVisit();
$shouldMatchOneFieldOnly = $this->shouldLookupOneVisitorFieldOnly($isVisitorIdToLookup);
@@ -1135,21 +1132,25 @@ class Piwik_Tracker_Visit implements Piwik_Tracker_Visit_Interface
// this page view to the wrong visitor, but this is better than creating artificial visits.
// 2) there is a visitor ID and we trust it (config setting trust_visitors_cookies, OR it was set using &cid= in tracking API),
// and in these cases, we force to look up this visitor id
+ $whereCommon = "visit_last_action_time >= ? AND visit_last_action_time <= ? AND idsite = ?";
+ $bindSql = array(
+ $timeLookBack,
+ $timeLookAhead,
+ $this->idsite
+ );
+
if ($shouldMatchOneFieldOnly) {
- $where = "visit_last_action_time >= ? AND idsite = ?";
- $bindSql[] = $timeLookBack;
- $bindSql[] = $this->idsite;
if (!$isVisitorIdToLookup) {
- $where .= ' AND config_id = ?';
+ $whereCommon .= ' AND config_id = ?';
$bindSql[] = $configId;
} else {
- $where .= ' AND idvisitor = ?';
+ $whereCommon .= ' AND idvisitor = ?';
$bindSql[] = $this->visitorInfo['idvisitor'];
}
$sql = "$select
$from
- WHERE " . $where . "
+ WHERE " . $whereCommon . "
ORDER BY visit_last_action_time DESC
LIMIT 1";
} // We have a config_id AND a visitor_id. We match on either of these.
@@ -1160,31 +1161,27 @@ class Piwik_Tracker_Visit implements Piwik_Tracker_Visit_Interface
// so we also backup by searching for matching config_id.
// We use a UNION here so that each sql query uses its own INDEX
else {
- $whereSameBothQueries = "visit_last_action_time >= ? AND idsite = ?";
-
-
// will use INDEX index_idsite_config_datetime (idsite, config_id, visit_last_action_time)
- $bindSql[] = $timeLookBack;
- $bindSql[] = $this->idsite;
$where = ' AND config_id = ?';
$bindSql[] = $configId;
$sqlConfigId = "$select ,
0 as priority
$from
- WHERE $whereSameBothQueries $where
+ WHERE $whereCommon $where
ORDER BY visit_last_action_time DESC
LIMIT 1
";
// will use INDEX index_idsite_idvisitor (idsite, idvisitor)
$bindSql[] = $timeLookBack;
+ $bindSql[] = $timeLookAhead;
$bindSql[] = $this->idsite;
$where = ' AND idvisitor = ?';
$bindSql[] = $this->visitorInfo['idvisitor'];
$sqlVisitorId = "$select ,
1 as priority
$from
- WHERE $whereSameBothQueries $where
+ WHERE $whereCommon $where
LIMIT 1
";
@@ -1261,10 +1258,14 @@ class Piwik_Tracker_Visit implements Piwik_Tracker_Visit_Interface
* In some cases, it is useful to look back and count unique visitors more accurately. You can set custom lookback window in
* [Tracker] window_look_back_for_visitor
*
- * @return string
+ * The returned value is the window range (Min, max) that the matched visitor should fall within
+ *
+ * Note: we must restrict in the future in case we import old data after having imported new data.
+ *
+ * @return array( datetimeMin, datetimeMax )
*
*/
- protected function getWindowLookupPreviousVisit()
+ protected function getWindowLookupThisVisit()
{
$lookbackNSeconds = Piwik_Config::getInstance()->Tracker['visit_standard_length'];
@@ -1273,9 +1274,12 @@ class Piwik_Tracker_Visit implements Piwik_Tracker_Visit_Interface
$lookbackNSeconds = $lookbackNSecondsCustom;
}
$timeLookBack = date('Y-m-d H:i:s', $this->getCurrentTimestamp() - $lookbackNSeconds);
- return $timeLookBack;
+ $timeLookAhead = date('Y-m-d H:i:s', $this->getCurrentTimestamp() + $lookbackNSeconds);
+
+ return array($timeLookBack, $timeLookAhead);
}
+
protected function shouldLookupOneVisitorFieldOnly($isVisitorIdToLookup)
{
// This setting would be enabled for Intranet websites, to ensure that visitors using all the same computer config, same IP
diff --git a/tests/PHPUnit/BaseFixture.php b/tests/PHPUnit/BaseFixture.php
index d9fc108698..8b1253299e 100644
--- a/tests/PHPUnit/BaseFixture.php
+++ b/tests/PHPUnit/BaseFixture.php
@@ -325,4 +325,34 @@ abstract class Test_Piwik_BaseFixture extends PHPUnit_Framework_Assert
throw new Exception("gunzip failed($return): " . implode("\n", $output));
}
}
+
+ protected static function executeLogImporter($logFile, $options)
+ {
+ $python = Piwik_Common::isWindows() ? "C:\Python27\python.exe" : 'python';
+
+ // create the command
+ $cmd = $python
+ . ' "' . PIWIK_INCLUDE_PATH . '/misc/log-analytics/import_logs.py" ' # script loc
+ . '-ddd ' // debug
+ . '--url="' . self::getRootUrl() . 'tests/PHPUnit/proxy/" ' # proxy so that piwik uses test config files
+ ;
+
+ foreach ($options as $name => $value) {
+ $cmd .= $name;
+ if ($value !== false) {
+ $cmd .= '="' . $value . '"';
+ }
+ $cmd .= ' ';
+ }
+
+ $cmd .= '"' . $logFile . '" 2>&1';
+
+ // run the command
+ exec($cmd, $output, $result);
+ if ($result !== 0) {
+ throw new Exception("log importer failed: " . implode("\n", $output) . "\n\ncommand used: $cmd");
+ }
+
+ return $output;
+ }
}
diff --git a/tests/PHPUnit/Fixtures/ManySitesImportedLogs.php b/tests/PHPUnit/Fixtures/ManySitesImportedLogs.php
index 80d0036a7d..43562844f6 100644
--- a/tests/PHPUnit/Fixtures/ManySitesImportedLogs.php
+++ b/tests/PHPUnit/Fixtures/ManySitesImportedLogs.php
@@ -136,33 +136,4 @@ class Test_Piwik_Fixture_ManySitesImportedLogs extends Test_Piwik_BaseFixture
self::executeLogImporter($logFile, $opts);
}
- private static function executeLogImporter($logFile, $options)
- {
- $python = Piwik_Common::isWindows() ? "C:\Python27\python.exe" : 'python';
-
- // create the command
- $cmd = $python
- . ' "' . PIWIK_INCLUDE_PATH . '/misc/log-analytics/import_logs.py" ' # script loc
- . '-ddd ' // debug
- . '--url="' . self::getRootUrl() . 'tests/PHPUnit/proxy/" ' # proxy so that piwik uses test config files
- ;
-
- foreach ($options as $name => $value) {
- $cmd .= $name;
- if ($value !== false) {
- $cmd .= '="' . $value . '"';
- }
- $cmd .= ' ';
- }
-
- $cmd .= '"' . $logFile . '" 2>&1';
-
- // run the command
- exec($cmd, $output, $result);
- if ($result !== 0) {
- throw new Exception("log importer failed: " . implode("\n", $output) . "\n\ncommand used: $cmd");
- }
-
- return $output;
- }
}
diff --git a/tests/PHPUnit/Fixtures/ManyVisitsWithGeoIP.php b/tests/PHPUnit/Fixtures/ManyVisitsWithGeoIP.php
index 88cd783ae1..07d4d9dde6 100644
--- a/tests/PHPUnit/Fixtures/ManyVisitsWithGeoIP.php
+++ b/tests/PHPUnit/Fixtures/ManyVisitsWithGeoIP.php
@@ -67,6 +67,9 @@ class Test_Piwik_Fixture_ManyVisitsWithGeoIP extends Test_Piwik_BaseFixture
private function trackVisits($visitorCount, $setIp = false, $useLocal = true, $doBulk = false)
{
+ static $calledCounter = 0;
+ $calledCounter++;
+
$dateTime = $this->dateTime;
$idSite = $this->idSite;
@@ -77,7 +80,7 @@ class Test_Piwik_Fixture_ManyVisitsWithGeoIP extends Test_Piwik_BaseFixture
$t->setTokenAuth(self::getTokenAuth());
}
for ($i = 0; $i != $visitorCount; ++$i) {
- $t->setVisitorId( substr(md5($i + 1000), 0, $t::LENGTH_VISITOR_ID));
+ $t->setVisitorId( substr(md5($i + $calledCounter * 1000), 0, $t::LENGTH_VISITOR_ID));
if ($setIp) {
$t->setIp(current($this->ips));
next($this->ips);
diff --git a/tests/PHPUnit/Integration/ManyVisitorsOneWebsiteTest.php b/tests/PHPUnit/Integration/ManyVisitorsOneWebsiteTest.php
index c8ee83e0a7..95c30bce13 100755
--- a/tests/PHPUnit/Integration/ManyVisitorsOneWebsiteTest.php
+++ b/tests/PHPUnit/Integration/ManyVisitorsOneWebsiteTest.php
@@ -77,6 +77,5 @@ class Test_Piwik_Integration_ManyVisitorsOneWebsiteTest extends IntegrationTestC
}
}
-Test_Piwik_Integration_ManyVisitorsOneWebsiteTest::$fixture
- = new Test_Piwik_Fixture_ManyVisitsWithGeoIP();
+Test_Piwik_Integration_ManyVisitorsOneWebsiteTest::$fixture = new Test_Piwik_Fixture_ManyVisitsWithGeoIP();
diff --git a/tests/PHPUnit/IntegrationTestCase.php b/tests/PHPUnit/IntegrationTestCase.php
index e7958db543..e4ca79e01f 100755
--- a/tests/PHPUnit/IntegrationTestCase.php
+++ b/tests/PHPUnit/IntegrationTestCase.php
@@ -158,6 +158,7 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase
// We need to be SU to create websites for tests
Piwik::setUserIsSuperUser();
+
Piwik_Tracker_Cache::deleteTrackerCache();
self::installAndLoadPlugins( $installPlugins = $createEmptyDatabase);
@@ -681,7 +682,11 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase
protected function _testApiUrl($testName, $apiId, $requestUrl)
{
- $isLiveMustDeleteDates = strpos($requestUrl, 'Live.getLastVisits') !== false;
+ $isTestLogImportReverseChronological = strpos($testName, 'ImportedInRandomOrderTest') === false;
+ $isLiveMustDeleteDates = strpos($requestUrl, 'Live.getLastVisits') !== false
+ // except for that particular test that we care about dates!
+ && $isTestLogImportReverseChronological;
+
$request = new Piwik_API_Request($requestUrl);
$dateTime = Piwik_Common::getRequestVar('date', '', 'string', Piwik_Common::getArrayFromQueryString($requestUrl));
@@ -1106,4 +1111,5 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase
Piwik_TablePartitioning::$tablesAlreadyInstalled = Piwik::getTablesInstalled($forceReload = true);
}
+
}
diff --git a/tests/PHPUnit/Plugins/SegmentEditorTest.php b/tests/PHPUnit/Plugins/SegmentEditorTest.php
index 89e215ea4c..f5e83d5c42 100644
--- a/tests/PHPUnit/Plugins/SegmentEditorTest.php
+++ b/tests/PHPUnit/Plugins/SegmentEditorTest.php
@@ -88,16 +88,20 @@ class SegmentEditorTest extends DatabaseTestCase
$this->assertEquals($segment, $expected);
// There is a segment to process for this particular site
- $segments = Piwik_SegmentEditor_API::getInstance()->getSegmentsToAutoArchive($idSite);
+ $segments = Piwik_SegmentEditor_API::getInstance()->getAll($idSite, $autoArchived = true);
unset($segments[0]['ts_created']);
$this->assertEquals($segments, array($expected));
- // There is no segment to process across all sites
- $segments = Piwik_SegmentEditor_API::getInstance()->getSegmentsToAutoArchive();
- $this->assertEquals($segments, array());
-
// There is no segment to process for a non existing site
- $segments = Piwik_SegmentEditor_API::getInstance()->getSegmentsToAutoArchive(33);
+ try {
+ $segments = Piwik_SegmentEditor_API::getInstance()->getAll(33, $autoArchived = true);
+ $this->fail();
+ } catch(Exception $e) {
+ // expected
+ }
+
+ // There is no segment to process across all sites
+ $segments = Piwik_SegmentEditor_API::getInstance()->getAll($idSite = false, $autoArchived = true);
$this->assertEquals($segments, array());
}