-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix loose typing of constructor for transaction level, and remove pub…
…lic property. (#22535) * Fix loose typing of constructor for transaction level, and remove public property. * Change interface to support mix of static vs non-static methods * Add retry logic back for transactions * reintroduce exception variable for php72 * reintroduce exception variable for php72 * fix broken integration test * fix broken integration test * fix broken integration test * fix broken integration test * Reorder methods * Move duplicate logic into traits
- Loading branch information
Showing
10 changed files
with
106 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace Piwik\Db; | ||
|
||
trait TransactionalDatabaseDynamicTrait | ||
{ | ||
private $supportsTransactionLevelForNonLockingReads; | ||
|
||
public function getCurrentTransactionIsolationLevelForSession(): string | ||
{ | ||
try { | ||
return $this->fetchOne('SELECT @@TX_ISOLATION'); | ||
} catch (Exception $e) { | ||
return $this->fetchOne('SELECT @@transaction_isolation'); | ||
} | ||
} | ||
|
||
public function setTransactionIsolationLevel(string $level): void | ||
{ | ||
$this->query("SET SESSION TRANSACTION ISOLATION LEVEL $level"); | ||
} | ||
|
||
public function getSupportsTransactionLevelForNonLockingReads(): ?bool | ||
{ | ||
return $this->supportsTransactionLevelForNonLockingReads; | ||
} | ||
|
||
public function setSupportsTransactionLevelForNonLockingReads(bool $supports = null): void | ||
{ | ||
$this->supportsTransactionLevelForNonLockingReads = $supports; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace Piwik\Db; | ||
|
||
interface TransactionalDatabaseInterface | ||
{ | ||
public function getCurrentTransactionIsolationLevelForSession(): string; | ||
public function setTransactionIsolationLevel(string $level): void; | ||
public function getSupportsTransactionLevelForNonLockingReads(): ?bool; | ||
public function setSupportsTransactionLevelForNonLockingReads(bool $supports = null): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace Piwik\Db; | ||
|
||
trait TransactionalDatabaseStaticTrait | ||
{ | ||
private $supportsTransactionLevelForNonLockingReads; | ||
|
||
public function setTransactionIsolationLevel(string $level): void | ||
{ | ||
static::query("SET SESSION TRANSACTION ISOLATION LEVEL $level"); | ||
} | ||
|
||
public function getCurrentTransactionIsolationLevelForSession(): string | ||
{ | ||
try { | ||
return static::fetchOne('SELECT @@TX_ISOLATION'); | ||
} catch (Exception $e) { | ||
return static::fetchOne('SELECT @@transaction_isolation'); | ||
} | ||
} | ||
|
||
public function setSupportsTransactionLevelForNonLockingReads(bool $supports = null): void | ||
{ | ||
$this->supportsTransactionLevelForNonLockingReads = $supports; | ||
} | ||
|
||
public function getSupportsTransactionLevelForNonLockingReads(): ?bool | ||
{ | ||
return $this->supportsTransactionLevelForNonLockingReads; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters