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/CronArchive/QueueConsumer.php7
-rw-r--r--tests/PHPUnit/Integration/CronArchive/QueueConsumerTest.php95
2 files changed, 101 insertions, 1 deletions
diff --git a/core/CronArchive/QueueConsumer.php b/core/CronArchive/QueueConsumer.php
index 546d26e496..e527ac0e7c 100644
--- a/core/CronArchive/QueueConsumer.php
+++ b/core/CronArchive/QueueConsumer.php
@@ -237,8 +237,13 @@ class QueueConsumer
list($isUsableExists, $archivedTime) = $this->usableArchiveExists($invalidatedArchive);
if ($isUsableExists) {
$now = Date::now()->getDatetime();
- $this->logger->debug("Found invalidation with usable archive (not yet outdated, ts_archived of existing = $archivedTime, now = $now) skipping until archive is out of date: $invalidationDesc");
$this->addInvalidationToExclude($invalidatedArchive);
+ if (empty($invalidatedArchive['plugin'])) {
+ $this->logger->debug("Found invalidation with usable archive (not yet outdated, ts_archived of existing = $archivedTime, now = $now) skipping until archive is out of date: $invalidationDesc");
+ } else {
+ $this->logger->debug("Found invalidation with usable archive (not yet outdated, ts_archived of existing = $archivedTime, now = $now) ignoring and deleting: $invalidationDesc");
+ $this->model->deleteInvalidations([$invalidatedArchive]);
+ }
continue;
} else {
$now = Date::now()->getDatetime();
diff --git a/tests/PHPUnit/Integration/CronArchive/QueueConsumerTest.php b/tests/PHPUnit/Integration/CronArchive/QueueConsumerTest.php
index 70ce73e8f8..a2e6a488a2 100644
--- a/tests/PHPUnit/Integration/CronArchive/QueueConsumerTest.php
+++ b/tests/PHPUnit/Integration/CronArchive/QueueConsumerTest.php
@@ -504,6 +504,82 @@ class QueueConsumerTest extends IntegrationTestCase
$this->assertEquals(0, $count);
}
+
+
+ public function test_pluginInvalidationDeletedIfUsableArchiveExists()
+ {
+ Fixture::createWebsite('2015-02-03');
+
+ // force archiving so we don't skip those without visits
+ Piwik::addAction('Archiving.getIdSitesToArchiveWhenNoVisits', function (&$idSites) {
+ $idSites[] = 1;
+ });
+
+ $cronArchive = new MockCronArchive();
+ $cronArchive->init();
+
+ $archiveFilter = $this->makeTestArchiveFilter();
+
+ $queueConsumer = new QueueConsumer(
+ StaticContainer::get(LoggerInterface::class),
+ new FixedSiteIds([1]),
+ 3,
+ 24,
+ new Model(),
+ new SegmentArchiving('beginning_of_time'),
+ $cronArchive,
+ new RequestParser(true),
+ $archiveFilter
+ );
+
+ Date::$now = strtotime('2018-03-04 01:00:00');
+
+ $invalidations = [
+ ['idarchive' => 1, 'name' => "done.Actions", 'idsite' => 1, 'date1' => '2018-03-04', 'date2' => '2018-03-04', 'period' => 1, 'report' => null],
+ ['idarchive' => 1, 'name' => 'done', 'idsite' => 1, 'date1' => '2018-03-04', 'date2' => '2018-03-04', 'period' => 3, 'report' => null],
+ ];
+
+ shuffle($invalidations);
+
+ $this->insertInvalidations($invalidations);
+
+ $usableArchive = ['idarchive' => 1, 'name' => 'done', 'idsite' => 1, 'date1' => '2018-03-04', 'date2' => '2018-03-04', 'period' => 1, 'ts_archived' => Date::now()->getDatetime(), 'value' => 3.0];
+ $this->insertArchive($usableArchive);
+
+ $iteratedInvalidations = [];
+ while (true) {
+ $next = $queueConsumer->getNextArchivesToProcess();
+ if ($next === null) {
+ break;
+ }
+
+ foreach ($next as &$item) {
+ $this->simulateJobStart($item['idinvalidation']);
+
+ unset($item['periodObj']);
+ unset($item['idinvalidation']);
+ unset($item['ts_invalidated']);
+ }
+
+ $iteratedInvalidations[] = $next;
+ }
+
+ $expectedInvalidationsFound = [
+ array(
+ ['idarchive' => '1', 'idsite' => '1', 'date1' => '2018-03-04', 'date2' => '2018-03-04', 'period' => '3', 'name' => 'done', 'report' => null, 'plugin' => null, 'segment' => '', 'ts_started' => null, 'status' => '0']
+ ),
+ array()
+ ];
+
+ $this->assertEquals($expectedInvalidationsFound, $iteratedInvalidations, "Invalidations inserted:\n" . var_export($invalidations, true));
+
+ // check that our plugin invalidation is no longer in the invalidations table
+ $count = Db::fetchOne('SELECT COUNT(*) FROM ' . Common::prefixTable('archive_invalidations') . ' WHERE name = ?', [
+ "done.Actions",
+ ]);
+ $this->assertEquals(0, $count);
+ }
+
public function test_skipSegmentsToday()
{
Date::$now = strtotime('2018-03-04 01:00:00');
@@ -680,6 +756,25 @@ class QueueConsumerTest extends IntegrationTestCase
}
}
+ private function insertArchive(array $archive)
+ {
+ $table = ArchiveTableCreator::getNumericTable(Date::now());
+
+ $bind = [
+ $archive['idarchive'],
+ $archive['name'],
+ $archive['idsite'],
+ $archive['date1'],
+ $archive['date2'],
+ $archive['period'],
+ $archive['ts_archived'],
+ $archive['value']
+ ];
+
+ Db::query("INSERT INTO `$table` (idarchive, name, idsite, date1, date2, period, ts_archived, value)
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?)", $bind);
+ }
+
public function test_canSkipArchiveBecauseNoPoint_returnsTrueIfDateRangeHasNoVisits()
{
Fixture::createWebsite('2010-04-06');