PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 4.13.3
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v4.13.3
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 / LoaderLock.php
matomo / app / core / ArchiveProcessor Last commit date
ArchivingStatus.php 4 years ago Loader.php 3 years ago LoaderLock.php 4 years ago Parameters.php 4 years ago PluginsArchiver.php 3 years ago PluginsArchiverException.php 5 years ago Rules.php 4 years ago
LoaderLock.php
66 lines
1 <?php
2 /**
3 * Matomo - free/libre analytics platform
4 *
5 * @link https://matomo.org
6 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
7 *
8 */
9 namespace Piwik\ArchiveProcessor;
10
11 use Piwik\Db;
12 use Piwik\SettingsPiwik;
13
14 class LoaderLock
15 {
16
17 const MAX_LEN_LOCK_NAME = 64;
18 const MAX_LOCK_TIME = 60; //in seconds
19 protected $id;
20
21 /**
22 * @param string $id
23 * @throws \Exception
24 */
25 public function __construct($id)
26 {
27 // instanceId is needed for multi tenant database solution
28 $id = SettingsPiwik::getPiwikInstanceId() . $id;
29
30 if (mb_strlen($id) >= self::MAX_LEN_LOCK_NAME) {
31 //convert ot prefix and md5 full length
32 $id = mb_substr($id, 0, 32) . md5($id);
33 }
34
35 $this->id = $id;
36 }
37
38 public function setLock()
39 {
40 Db::fetchOne('SELECT GET_LOCK(?,?)', array($this->id, self::MAX_LOCK_TIME));
41 }
42
43 public function unLock()
44 {
45 Db::query('DO RELEASE_LOCK(?)', array($this->id));
46 }
47
48 public function getId()
49 {
50 return $this->id;
51 }
52
53 /**
54 * @description check if the lock is available to user
55 * @param string $key
56 * @return bool
57 * @throws \Exception
58 */
59 public static function isLockAvailable($key)
60 {
61 return (bool)Db::fetchOne('SELECT IS_FREE_LOCK(?)', [$key]);
62
63 }
64
65 }
66