PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 5.0.3
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v5.0.3
5.12.1 5.12.0 5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / core / ArchiveProcessor / ArchivingStatus.php
matomo / app / core / ArchiveProcessor Last commit date
ArchivingStatus.php 2 years ago Loader.php 2 years ago LoaderLock.php 2 years ago Parameters.php 2 years ago PluginsArchiver.php 2 years ago PluginsArchiverException.php 2 years ago Record.php 2 years ago RecordBuilder.php 2 years ago Rules.php 2 years ago
ArchivingStatus.php
108 lines
1 <?php
2
3 /**
4 * Matomo - free/libre analytics platform
5 *
6 * @link https://matomo.org
7 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
8 *
9 */
10 namespace Piwik\ArchiveProcessor;
11
12 use Piwik\Concurrency\Lock;
13 use Piwik\Concurrency\LockBackend;
14 use Piwik\Container\StaticContainer;
15 class ArchivingStatus
16 {
17 const LOCK_KEY_PREFIX = 'Archiving';
18 const DEFAULT_ARCHIVING_TTL = 7200;
19 // 2 hours
20 /**
21 * @var LockBackend
22 */
23 private $lockBackend;
24 /**
25 * @var int
26 */
27 private $archivingTTLSecs;
28 /**
29 * @var Lock[]
30 */
31 private $lockStack = [];
32 public function __construct(LockBackend $lockBackend, $archivingTTLSecs = self::DEFAULT_ARCHIVING_TTL)
33 {
34 $this->lockBackend = $lockBackend;
35 $this->archivingTTLSecs = $archivingTTLSecs;
36 }
37 public function archiveStarted(\Piwik\ArchiveProcessor\Parameters $params)
38 {
39 $lock = $this->makeArchivingLock($params);
40 $locked = $lock->acquireLock('', $this->archivingTTLSecs);
41 if ($locked) {
42 array_push($this->lockStack, $lock);
43 }
44 return $locked;
45 }
46 /**
47 * Try to acquire the lock that is acquired before starting archiving. If it is acquired, it
48 * means archiving is not ongoing. If it is not acquired, then archiving is ongoing.
49 *
50 * @param Parameters $params
51 * @param $doneFlag
52 * @return Lock
53 */
54 public function acquireArchiveInProgressLock($idSite, $date1, $date2, $period, $doneFlag)
55 {
56 $lock = $this->makeArchivingLockFromDoneFlag($idSite, $date1, $date2, $period, $doneFlag);
57 $lock->acquireLock('', $ttl = 1);
58 return $lock;
59 }
60 public function archiveFinished()
61 {
62 $lock = array_pop($this->lockStack);
63 $lock->unlock();
64 }
65 public function getCurrentArchivingLock()
66 {
67 if (empty($this->lockStack)) {
68 return null;
69 }
70 return end($this->lockStack);
71 }
72 public function getSitesCurrentlyArchiving()
73 {
74 $lockMeta = new Lock($this->lockBackend, self::LOCK_KEY_PREFIX . '.');
75 $acquiredLocks = $lockMeta->getAllAcquiredLockKeys();
76 $sitesCurrentlyArchiving = [];
77 foreach ($acquiredLocks as $lockKey) {
78 $parts = explode('.', $lockKey);
79 if (!isset($parts[1])) {
80 continue;
81 }
82 $sitesCurrentlyArchiving[] = (int) $parts[1];
83 }
84 $sitesCurrentlyArchiving = array_unique($sitesCurrentlyArchiving);
85 $sitesCurrentlyArchiving = array_values($sitesCurrentlyArchiving);
86 return $sitesCurrentlyArchiving;
87 }
88 /**
89 * @return Lock
90 */
91 private function makeArchivingLock(\Piwik\ArchiveProcessor\Parameters $params)
92 {
93 $doneFlag = \Piwik\ArchiveProcessor\Rules::getDoneStringFlagFor([$params->getSite()->getId()], $params->getSegment(), $params->getPeriod()->getLabel(), $params->getRequestedPlugin());
94 return $this->makeArchivingLockFromDoneFlag($params->getSite()->getId(), $params->getSite()->getId(), $params->getPeriod()->getDateStart()->toString(), $params->getPeriod()->getDateEnd()->toString(), $doneFlag);
95 }
96 private function makeArchivingLockFromDoneFlag($idSite, $date1, $date2, $period, $doneFlag)
97 {
98 $lockKeyParts = [
99 self::LOCK_KEY_PREFIX,
100 $idSite,
101 // md5 to keep it within the 70 char limit in the table
102 md5($period . $date1 . ',' . $date2 . $doneFlag),
103 ];
104 $lockKeyPrefix = implode('.', $lockKeyParts);
105 return new Lock(StaticContainer::get(LockBackend::class), $lockKeyPrefix, $this->archivingTTLSecs);
106 }
107 }
108