diff options
author | diosmosis <benaka@piwik.pro> | 2015-09-25 11:24:05 +0300 |
---|---|---|
committer | diosmosis <benaka@piwik.pro> | 2015-09-25 11:24:05 +0300 |
commit | ee7e1374fb8a5f833dae2326031657544ed86109 (patch) | |
tree | e44b0f622dff93d545d40cc4741b8989b7a5af6a /plugins/SitesManager | |
parent | dae25c25e2eb16bd61d6ebe662dfbf88903a994a (diff) |
Cover case in SitesManagerRequestProcess where ts_created is not found in tracker cache more explicitly. Make sure the site created time is not modified in this case.
Diffstat (limited to 'plugins/SitesManager')
-rw-r--r-- | plugins/SitesManager/Tracker/SitesManagerRequestProcessor.php | 11 | ||||
-rw-r--r-- | plugins/SitesManager/tests/Integration/TrackingTest.php | 22 |
2 files changed, 31 insertions, 2 deletions
diff --git a/plugins/SitesManager/Tracker/SitesManagerRequestProcessor.php b/plugins/SitesManager/Tracker/SitesManagerRequestProcessor.php index cb2b3f7f9d..8e88b6f5bd 100644 --- a/plugins/SitesManager/Tracker/SitesManagerRequestProcessor.php +++ b/plugins/SitesManager/Tracker/SitesManagerRequestProcessor.php @@ -42,6 +42,10 @@ class SitesManagerRequestProcessor extends RequestProcessor $idSite = $request->getIdSite(); $createdTimeTimestamp = $this->getSiteCreatedTime($idSite); + if (empty($createdTimeTimestamp)) { + return; + } + $requestTimestamp = Date::factory((int) $request->getCurrentTimestamp()); // replicating old Piwik logic, see: @@ -60,8 +64,11 @@ class SitesManagerRequestProcessor extends RequestProcessor private function getSiteCreatedTime($idSite) { $attributes = Cache::getCacheWebsiteAttributes($idSite); - $tsCreated = isset($attributes['ts_created']) ? $attributes['ts_created'] : 0; - return Date::factory($tsCreated); + if (!isset($attributes['ts_created'])) { + return null; + } + + return Date::factory($attributes['ts_created']); } private function updateSiteCreatedTime($idSite, Date $timestamp) diff --git a/plugins/SitesManager/tests/Integration/TrackingTest.php b/plugins/SitesManager/tests/Integration/TrackingTest.php index 0538c0bf17..5c49c42128 100644 --- a/plugins/SitesManager/tests/Integration/TrackingTest.php +++ b/plugins/SitesManager/tests/Integration/TrackingTest.php @@ -53,6 +53,23 @@ class TrackingTest extends IntegrationTestCase $this->assertEquals('2014-12-31 00:00:00', $createdTime); } + public function test_TrackingOldVisit_ForSiteWithNoTsCreatedTime_DoesNotResetCreatedTime() + { + Fixture::createWebsite('2015-01-01 00:00:00'); + + $this->unsetCreatedTime($idSite = 1); + + $createdTime = $this->getSiteCreatedTime($idSite = 1); + $this->assertEquals(null, $createdTime); + + $t = $this->getLocalTracker(); + $t->setForceVisitDateTime('2014-08-06 07:53:09'); + Fixture::checkResponse($t->doTrackPageView('page view')); + + $createdTime = $this->getSiteCreatedTime($idSite = 1); + $this->assertEquals(null, $createdTime); + } + private function getLocalTracker() { return self::$fixture->getTracker($idSite = 1, '2015-01-01', $defaultInit = true, $useLocalTracker = true); @@ -63,6 +80,11 @@ class TrackingTest extends IntegrationTestCase return Db::fetchOne("SELECT ts_created FROM " . Common::prefixTable('site') . " WHERE idsite = ?", array($idSite)); } + private function unsetCreatedTime($idSite) + { + Db::query("UPDATE " . Common::prefixTable('site') . " SET ts_created = NULL WHERE idsite = ?", array($idSite)); + } + protected static function configureFixture($fixture) { parent::configureFixture($fixture); |