Skip to content
Extraits de code Groupes Projets
Valider 49cb0c57 rédigé par Thomas Steur's avatar Thomas Steur
Parcourir les fichiers

refs #5054 some code improvements

parent da9cd11a
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -103,7 +103,6 @@ class ReportsPurger ...@@ -103,7 +103,6 @@ class ReportsPurger
*/ */
public function purgeData($optimize = false) public function purgeData($optimize = false)
{ {
// find archive tables to purge
list($oldNumericTables, $oldBlobTables) = $this->getArchiveTablesToPurge(); list($oldNumericTables, $oldBlobTables) = $this->getArchiveTablesToPurge();
// process blob tables first, since archive status is stored in the numeric archives // process blob tables first, since archive status is stored in the numeric archives
...@@ -122,9 +121,7 @@ class ReportsPurger ...@@ -122,9 +121,7 @@ class ReportsPurger
} }
} }
// deal with numeric tables
if (!empty($oldNumericTables)) { if (!empty($oldNumericTables)) {
foreach ($oldNumericTables as $table) { foreach ($oldNumericTables as $table) {
$conditions = array("name NOT LIKE 'done%'"); $conditions = array("name NOT LIKE 'done%'");
$bind = array(); $bind = array();
......
...@@ -37,10 +37,9 @@ class Test_Piwik_Integration_PurgeDataTest extends IntegrationTestCase ...@@ -37,10 +37,9 @@ class Test_Piwik_Integration_PurgeDataTest extends IntegrationTestCase
$this->assertHasOneDownload('year'); $this->assertHasOneDownload('year');
$deleteReportsOlderThan = 1; $deleteReportsOlderThan = 1;
$keepBasicMetrics = true; $keepBasicMetrics = true;
$reportPeriodsToKeep = array(2,3,4,5); $reportPeriodsToKeep = array(2,3,4,5);
$purger = $this->createReportsPurger($deleteReportsOlderThan, $reportPeriodsToKeep, $keepBasicMetrics); $this->purgeData($deleteReportsOlderThan, $reportPeriodsToKeep, $keepBasicMetrics);
$purger->purgeData();
$this->assertHasNoDownload('day'); $this->assertHasNoDownload('day');
$this->assertHasOneDownload('week'); $this->assertHasOneDownload('week');
...@@ -56,11 +55,12 @@ class Test_Piwik_Integration_PurgeDataTest extends IntegrationTestCase ...@@ -56,11 +55,12 @@ class Test_Piwik_Integration_PurgeDataTest extends IntegrationTestCase
$this->assertHasOneDownload('year'); $this->assertHasOneDownload('year');
$deleteReportsOlderThan = 1; $deleteReportsOlderThan = 1;
$keepBasicMetrics = true; $keepBasicMetrics = true;
$reportPeriodsToKeep = array(1); $reportPeriodsToKeep = array(1);
$purger = $this->createReportsPurger($deleteReportsOlderThan, $reportPeriodsToKeep, $keepBasicMetrics); $this->purgeData($deleteReportsOlderThan, $reportPeriodsToKeep, $keepBasicMetrics);
$purger->purgeData();
$this->assertNumVisits(2, 'day');
$this->assertNumVisits(2, 'week');
$this->assertHasOneDownload('day'); $this->assertHasOneDownload('day');
$this->assertHasNoDownload('week'); $this->assertHasNoDownload('week');
$this->assertHasNoDownload('month'); $this->assertHasNoDownload('month');
...@@ -75,10 +75,9 @@ class Test_Piwik_Integration_PurgeDataTest extends IntegrationTestCase ...@@ -75,10 +75,9 @@ class Test_Piwik_Integration_PurgeDataTest extends IntegrationTestCase
$this->assertHasOneDownload('year'); $this->assertHasOneDownload('year');
$deleteReportsOlderThan = 1000; $deleteReportsOlderThan = 1000;
$keepBasicMetrics = true; $keepBasicMetrics = true;
$reportPeriodsToKeep = array(1,2,3,4,5); $reportPeriodsToKeep = array(1,2,3,4,5);
$purger = $this->createReportsPurger($deleteReportsOlderThan, $reportPeriodsToKeep, $keepBasicMetrics); $this->purgeData($deleteReportsOlderThan, $reportPeriodsToKeep, $keepBasicMetrics);
$purger->purgeData();
$this->assertHasOneDownload('day'); $this->assertHasOneDownload('day');
$this->assertHasOneDownload('week'); $this->assertHasOneDownload('week');
...@@ -94,10 +93,9 @@ class Test_Piwik_Integration_PurgeDataTest extends IntegrationTestCase ...@@ -94,10 +93,9 @@ class Test_Piwik_Integration_PurgeDataTest extends IntegrationTestCase
$this->assertHasOneDownload('year'); $this->assertHasOneDownload('year');
$deleteReportsOlderThan = 1; $deleteReportsOlderThan = 1;
$keepBasicMetrics = true; $keepBasicMetrics = true;
$reportPeriodsToKeep = array(); $reportPeriodsToKeep = array();
$purger = $this->createReportsPurger($deleteReportsOlderThan, $reportPeriodsToKeep, $keepBasicMetrics); $this->purgeData($deleteReportsOlderThan, $reportPeriodsToKeep, $keepBasicMetrics);
$purger->purgeData();
$this->assertNumVisits(2, 'day'); $this->assertNumVisits(2, 'day');
$this->assertNumVisits(2, 'week'); $this->assertNumVisits(2, 'week');
...@@ -117,10 +115,9 @@ class Test_Piwik_Integration_PurgeDataTest extends IntegrationTestCase ...@@ -117,10 +115,9 @@ class Test_Piwik_Integration_PurgeDataTest extends IntegrationTestCase
$this->assertHasOneDownload('year'); $this->assertHasOneDownload('year');
$deleteReportsOlderThan = 1; $deleteReportsOlderThan = 1;
$keepBasicMetrics = false; $keepBasicMetrics = false;
$reportPeriodsToKeep = array(); $reportPeriodsToKeep = array();
$purger = $this->createReportsPurger($deleteReportsOlderThan, $reportPeriodsToKeep, $keepBasicMetrics); $this->purgeData($deleteReportsOlderThan, $reportPeriodsToKeep, $keepBasicMetrics);
$purger->purgeData();
$this->assertNumVisits(0, 'day'); $this->assertNumVisits(0, 'day');
$this->assertNumVisits(0, 'week'); $this->assertNumVisits(0, 'week');
...@@ -132,42 +129,6 @@ class Test_Piwik_Integration_PurgeDataTest extends IntegrationTestCase ...@@ -132,42 +129,6 @@ class Test_Piwik_Integration_PurgeDataTest extends IntegrationTestCase
$this->assertHasNoDownload('year'); $this->assertHasNoDownload('year');
} }
private function getDownloadApiRequestUrl($period)
{
return 'method=Actions.getDownloads'
. '&idSite=' . self::$fixture->idSite
. '&date=' . self::$fixture->dateTime
. '&period='. $period
. '&format=original';
}
private function createReportsPurger($deleteReportsOlderThan, $reportPeriodsToKeep, $keepBasicMetrics)
{
$metricsToKeep = PrivacyManager::getAllMetricsToKeep();
$maxRowsToDeletePerQuery = 100000;
$keepSegmentReports = false;
return new ReportsPurger($deleteReportsOlderThan, $keepBasicMetrics, $reportPeriodsToKeep,
$keepSegmentReports, $metricsToKeep, $maxRowsToDeletePerQuery);
}
public function getApiForTesting()
{
$idSite = self::$fixture->idSite;
$dateTime = self::$fixture->dateTime;
$apiToCall = array('Actions.getDownloads');
$apiToTest = array(
array($apiToCall,
array('idSite' => $idSite,
'date' => $dateTime,
'periods' => array('month')))
);
return $apiToTest;
}
private function assertNumVisits($expectedNumVisits, $period) private function assertNumVisits($expectedNumVisits, $period)
{ {
$url = 'method=VisitsSummary.getVisits' $url = 'method=VisitsSummary.getVisits'
...@@ -193,6 +154,26 @@ class Test_Piwik_Integration_PurgeDataTest extends IntegrationTestCase ...@@ -193,6 +154,26 @@ class Test_Piwik_Integration_PurgeDataTest extends IntegrationTestCase
$table = $api->process(); $table = $api->process();
$this->assertEquals(0, $table->getRowsCount(), $period . ' should not have a download but has one'); $this->assertEquals(0, $table->getRowsCount(), $period . ' should not have a download but has one');
} }
private function getDownloadApiRequestUrl($period)
{
return 'method=Actions.getDownloads'
. '&idSite=' . self::$fixture->idSite
. '&date=' . self::$fixture->dateTime
. '&period='. $period
. '&format=original';
}
private function purgeData($deleteReportsOlderThan, $reportPeriodsToKeep, $keepBasicMetrics)
{
$metricsToKeep = PrivacyManager::getAllMetricsToKeep();
$maxRowsToDeletePerQuery = 100000;
$keepSegmentReports = false;
$purger = new ReportsPurger($deleteReportsOlderThan, $keepBasicMetrics, $reportPeriodsToKeep,
$keepSegmentReports, $metricsToKeep, $maxRowsToDeletePerQuery);
$purger->purgeData();
}
} }
Test_Piwik_Integration_PurgeDataTest::$fixture = new Test_Piwik_Fixture_OneVisitorTwoVisits(); Test_Piwik_Integration_PurgeDataTest::$fixture = new Test_Piwik_Fixture_OneVisitorTwoVisits();
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter