diff options
author | Thomas Steur <tsteur@users.noreply.github.com> | 2019-06-17 07:42:33 +0300 |
---|---|---|
committer | diosmosis <diosmosis@users.noreply.github.com> | 2019-06-17 07:42:33 +0300 |
commit | ed267097edc29349ec8482fdfac86b47bc23c660 (patch) | |
tree | 1ad560f8fef5219075e33ba5c999241cdc87f94c /plugins | |
parent | 824204a88d80b229df3708d1edcf5416eeb2ea44 (diff) |
fix no data message may not be shown when deleteLogs is enabled (#14526)
* fix no data message may not be shown when deleteLogs is enabled
* apply review feedback making it simpler
* Adding tests.
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/CoreAdminHome/Tasks.php | 2 | ||||
-rw-r--r-- | plugins/SitesManager/SitesManager.php | 21 | ||||
-rw-r--r-- | plugins/SitesManager/tests/Integration/SitesManagerTest.php | 104 |
3 files changed, 118 insertions, 9 deletions
diff --git a/plugins/CoreAdminHome/Tasks.php b/plugins/CoreAdminHome/Tasks.php index 136dfdf7e0..fd21b0301c 100644 --- a/plugins/CoreAdminHome/Tasks.php +++ b/plugins/CoreAdminHome/Tasks.php @@ -112,7 +112,7 @@ class Tasks extends \Piwik\Plugin\Tasks { $this->rememberTrackingCodeReminderRan($idSite); - if (!SitesManager::hasTrackedAnyTraffic($idSite)) { + if (SitesManager::hasTrackedAnyTraffic($idSite)) { return; } diff --git a/plugins/SitesManager/SitesManager.php b/plugins/SitesManager/SitesManager.php index 054ecc2fce..cb7fe68547 100644 --- a/plugins/SitesManager/SitesManager.php +++ b/plugins/SitesManager/SitesManager.php @@ -13,9 +13,9 @@ use Piwik\API\Request; use Piwik\Common; use Piwik\Container\StaticContainer; use Piwik\Exception\UnexpectedWebsiteFoundException; +use Piwik\Option; use Piwik\Piwik; use Piwik\Plugins\CoreHome\SystemSummary; -use Piwik\Plugins\PrivacyManager\PrivacyManager; use Piwik\Settings\Storage\Backend\MeasurableSettingsTable; use Piwik\Tracker\Cache; use Piwik\Tracker\Model as TrackerModel; @@ -65,13 +65,18 @@ class SitesManager extends \Piwik\Plugin return; } - // Skip the screen if purging logs is enabled - $settings = PrivacyManager::getPurgeDataSettings(); - if ($settings['delete_logs_enable'] == 1) { + $hadTrafficKey = 'SitesManagerHadTrafficInPast_' . (int) $siteId; + $hadTrafficBefore = Option::get($hadTrafficKey); + if (!empty($hadTrafficBefore)) { + // user had traffic at some stage in the past... not needed to show tracking code return; - } - - if (self::hasTrackedAnyTraffic($siteId)) { + } elseif (self::hasTrackedAnyTraffic($siteId)) { + // remember the user had traffic in the past so we won't show the tracking screen again + // if all visits are deleted for example + Option::set($hadTrafficKey, 1); + return; + } else { + // never had any traffic $session = new SessionNamespace('siteWithoutData'); if (!empty($session->ignoreMessage)) { return; @@ -98,7 +103,7 @@ class SitesManager extends \Piwik\Plugin Piwik::postEvent('SitesManager.shouldPerformEmptySiteCheck', [&$shouldPerformEmptySiteCheck, $siteId]); $trackerModel = new TrackerModel(); - return $shouldPerformEmptySiteCheck && $trackerModel->isSiteEmpty($siteId); + return $shouldPerformEmptySiteCheck && !$trackerModel->isSiteEmpty($siteId); } public function onSiteDeleted($idSite) diff --git a/plugins/SitesManager/tests/Integration/SitesManagerTest.php b/plugins/SitesManager/tests/Integration/SitesManagerTest.php index 5676372776..2f62a39c5a 100644 --- a/plugins/SitesManager/tests/Integration/SitesManagerTest.php +++ b/plugins/SitesManager/tests/Integration/SitesManagerTest.php @@ -10,8 +10,12 @@ namespace Piwik\Plugins\SitesManager\tests\Integration; use Piwik\Cache; use Piwik\Archive\ArchiveInvalidator; +use Piwik\Common; use Piwik\Container\StaticContainer; use Piwik\Date; +use Piwik\Db; +use Piwik\Option; +use Piwik\Piwik; use Piwik\Plugins\SitesManager\SitesManager; use Piwik\Tests\Framework\Fixture; use Piwik\Tests\Framework\Mock\FakeAccess; @@ -74,6 +78,106 @@ class SitesManagerTest extends IntegrationTestCase $this->assertEquals($expected, $archive->getRememberedArchivedReportsThatShouldBeInvalidated()); } + /** + * @dataProvider getTestDataForRedirectDashboard + */ + public function test_redirectDashboardToWelcomePage_doesNothingIfModuleActionAreIncorrect($module, $action) + { + $originalModule = $module; + $originalAction = $action; + $params = []; + + Piwik::postEvent('Request.dispatch', [&$module, &$action, &$params]); + + $this->assertEquals($originalModule, $module); + $this->assertEquals($originalAction, $action); + } + + public function getTestDataForRedirectDashboard() + { + return [ + ['CoreHome', 'someothermethod'], + ['SitesManager', 'index'], + ]; + } + + public function test_redirectDashboardToWelcomePage_doesNothingIfThereIsNoIdSiteParam() + { + $module = 'CoreHome'; + $action = 'index'; + $params = []; + + Piwik::postEvent('Request.dispatch', [&$module, &$action, &$params]); + + $this->assertEquals('CoreHome', $module); + $this->assertEquals('index', $action); + } + + public function test_redirectDashboardToWelcomePage_doesNothingIfAVisitWasTrackedInThePast() + { + $module = 'CoreHome'; + $action = 'index'; + $params = []; + + $_GET['idSite'] = $this->siteId; + + $tracker = Fixture::getTracker($this->siteId, '2015-02-04 04:12:35'); + $tracker->setUrl('http://example.com/'); + Fixture::checkResponse($tracker->doTrackPageView('a test title')); + + $this->assertEquals(false, Option::get('SitesManagerHadTrafficInPast_' . $this->siteId)); + + Piwik::postEvent('Request.dispatch', [&$module, &$action, &$params]); + + $this->assertEquals('1', Option::get('SitesManagerHadTrafficInPast_' . $this->siteId)); + + $this->assertEquals('CoreHome', $module); + $this->assertEquals('index', $action); + } + + public function test_redirectDashboardToWelcomePage_doesNothingIfAVisitWasTrackedAndWasLaterPurged() + { + $module = 'CoreHome'; + $action = 'index'; + $params = []; + + $_GET['idSite'] = $this->siteId; + + $tracker = Fixture::getTracker($this->siteId, '2015-02-04 04:12:35'); + $tracker->setUrl('http://example.com/'); + Fixture::checkResponse($tracker->doTrackPageView('a test title')); + + Piwik::postEvent('Request.dispatch', [&$module, &$action, &$params]); + + Db::exec('TRUNCATE ' . Common::prefixTable('log_visit')); + + $module = 'CoreHome'; + $action = 'index'; + + $this->assertEquals('CoreHome', $module); + $this->assertEquals('index', $action); + } + + public function test_redirectDashboardToWelcomePage_redirectsIfThereIsNoDataAndAppropriateParams() + { + $module = 'CoreHome'; + $action = 'index'; + $params = []; + + $_GET['idSite'] = $this->siteId; + + Piwik::postEvent('Request.dispatch', [&$module, &$action, &$params]); + + $this->assertEquals('SitesManager', $module); + $this->assertEquals('siteWithoutData', $action); + } + + protected static function configureFixture($fixture) + { + parent::configureFixture($fixture); + $fixture->createSuperUser = true; + } + public function provideContainerConfig() { return array( |