PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / trunk
Matomo Analytics – Powerful, Privacy-First Insights for WordPress vtrunk
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 / Db / TransactionLevel.php
matomo / app / core / Db Last commit date
Adapter 1 month ago Schema 2 weeks ago Adapter.php 1 month ago AdapterInterface.php 1 month ago BatchInsert.php 6 months ago Schema.php 1 month ago SchemaInterface.php 1 month ago Settings.php 1 year ago TransactionLevel.php 1 year ago TransactionalDatabaseDynamicTrait.php 1 year ago TransactionalDatabaseInterface.php 1 year ago TransactionalDatabaseStaticTrait.php 1 year ago
TransactionLevel.php
81 lines
1 <?php
2
3 /**
4 * Matomo - free/libre analytics platform
5 *
6 * @link https://matomo.org
7 * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
8 */
9 namespace Piwik\Db;
10
11 use Piwik\Db;
12 use Piwik\Option;
13 class TransactionLevel
14 {
15 public const TEST_OPTION_NAME = 'TransactionLevel.testOption';
16 private $statusBackup;
17 /**
18 * @var TransactionalDatabaseInterface $transactionalDatabase
19 */
20 private $transactionalDatabase;
21 public function __construct(\Piwik\Db\TransactionalDatabaseInterface $transactionalDatabase)
22 {
23 $this->transactionalDatabase = $transactionalDatabase;
24 }
25 public function canLikelySetTransactionLevel()
26 {
27 $dbSettings = new Db\Settings();
28 return strtolower($dbSettings->getEngine()) === 'innodb';
29 }
30 /**
31 * @deprecated Use `setTransactionLevelForNonLockingReads`
32 */
33 public function setUncommitted()
34 {
35 return $this->setTransactionLevelForNonLockingReads();
36 }
37 public function setTransactionLevelForNonLockingReads() : bool
38 {
39 if ($this->transactionalDatabase->getSupportsTransactionLevelForNonLockingReads() === \false) {
40 // we know "Uncommitted" transaction level is not supported, we don't need to do anything as it won't work to set the status
41 return \false;
42 }
43 try {
44 $backup = $this->transactionalDatabase->getCurrentTransactionIsolationLevelForSession();
45 } catch (\Exception $e) {
46 $this->transactionalDatabase->setSupportsTransactionLevelForNonLockingReads(\false);
47 return \false;
48 }
49 try {
50 $this->transactionalDatabase->setTransactionIsolationLevel(\Piwik\Db\Schema::getInstance()->getSupportedReadIsolationTransactionLevel());
51 $this->statusBackup = $backup;
52 if ($this->transactionalDatabase->getSupportsTransactionLevelForNonLockingReads() === null) {
53 // the first time we need to check if the transaction level actually works by
54 // trying to set something w/ the new transaction isolation level
55 Option::set(self::TEST_OPTION_NAME, '1');
56 }
57 $this->transactionalDatabase->setSupportsTransactionLevelForNonLockingReads(\true);
58 } catch (\Exception $e) {
59 // setting the transaction level status did not work
60 // catch eg 1665 Cannot execute statement: impossible to write to binary log since BINLOG_FORMAT = STATEMENT and at least one table uses a storage engine limited to row-based logging. InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED
61 $this->transactionalDatabase->setSupportsTransactionLevelForNonLockingReads(\false);
62 $this->restorePreviousStatus();
63 return \false;
64 }
65 return \true;
66 }
67 public function restorePreviousStatus()
68 {
69 if ($this->statusBackup) {
70 $value = strtoupper($this->statusBackup);
71 $this->statusBackup = null;
72 $value = str_replace('-', ' ', $value);
73 if (in_array($value, array('REPEATABLE READ', 'READ COMMITTED', 'SERIALIZABLE'))) {
74 $this->transactionalDatabase->setTransactionIsolationLevel($value);
75 } elseif ($value !== 'READ UNCOMMITTED') {
76 $this->transactionalDatabase->setTransactionIsolationLevel('REPEATABLE READ');
77 }
78 }
79 }
80 }
81