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:
authordiosmosis <diosmosis@users.noreply.github.com>2020-09-21 01:30:00 +0300
committerGitHub <noreply@github.com>2020-09-21 01:30:00 +0300
commit1cb41a757e96e5a0c19da9a0deaad7dc5593c759 (patch)
treecb81217f03514dab2ac9ffc3e229d46bd3d93286 /plugins/ExamplePlugin
parent62fcad39c4f0c5d8c0d75b2456a4ac07f7b106a5 (diff)
Add extra check for queue consumer to prevent duplicates and add duplicate check in tests. (#16406)
Diffstat (limited to 'plugins/ExamplePlugin')
-rw-r--r--plugins/ExamplePlugin/Archiver.php28
1 files changed, 13 insertions, 15 deletions
diff --git a/plugins/ExamplePlugin/Archiver.php b/plugins/ExamplePlugin/Archiver.php
index 89d79959b9..c206354382 100644
--- a/plugins/ExamplePlugin/Archiver.php
+++ b/plugins/ExamplePlugin/Archiver.php
@@ -87,10 +87,9 @@ class Archiver extends \Piwik\Plugin\Archiver
}
if ($this->isRequestedReport(self::EXAMPLEPLUGIN_CONST_METRIC_NAME)) {
- $archiveCount = $this->incrementArchiveCount();
- $archiveCount = 50 + $archiveCount;
- $archiveCount += 5 - ($archiveCount % 5); // round up to nearest 5 multiple to avoid random test failures
- $this->getProcessor()->insertNumericRecord(self::EXAMPLEPLUGIN_CONST_METRIC_NAME, $archiveCount);
+ $callCount = $this->getAndIncrementArchiveCallCount();
+ $metricValue = $callCount > 0 ? 1 : 0;
+ $this->getProcessor()->insertNumericRecord(self::EXAMPLEPLUGIN_CONST_METRIC_NAME, $metricValue);
}
}
@@ -124,16 +123,15 @@ class Archiver extends \Piwik\Plugin\Archiver
private function createSequence()
{
- $sequence = new Sequence('ExamplePlugin_archiveCount');
- if (!$sequence->exists()) {
- for ($i = 0; $i < 100; ++$i) {
- try {
- $sequence->create();
- break;
- } catch (\Exception $ex) {
- // ignore
- }
- }
- }
+ }
+
+ private function getAndIncrementArchiveCallCount()
+ {
+ $params = $this->getProcessor()->getParams();
+ $optionName = 'ExamplePlugin.metricValue.' . md5($params->getSite()->getId() . '.' . $params->getPeriod()->getRangeString()
+ . '.' . $params->getPeriod()->getLabel() . '.' . $params->getSegment()->getHash());
+ $value = (int) Option::get($optionName);
+ Option::set($optionName, $value + 1);
+ return $value;
}
}