mirror of
https://git.sekbaer.de/Friendica/friendica.git
synced 2025-06-12 01:54:26 +02:00
Fix DBA::lock() testability because of "autocommits"
This commit is contained in:
parent
10e8c5594d
commit
ea4b066df3
3 changed files with 45 additions and 25 deletions
|
@ -39,6 +39,9 @@ class StaticDatabase extends Database
|
|||
*/
|
||||
private static $staticConnection;
|
||||
|
||||
/** @var bool */
|
||||
private $_locked = false;
|
||||
|
||||
/**
|
||||
* Override the behaviour of connect, due there is just one, static connection at all
|
||||
*
|
||||
|
@ -77,6 +80,31 @@ class StaticDatabase extends Database
|
|||
return true;
|
||||
}
|
||||
|
||||
/** Mock for locking tables */
|
||||
public function lock($table)
|
||||
{
|
||||
if ($this->_locked) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->in_transaction = true;
|
||||
$this->_locked = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Mock for unlocking tables */
|
||||
public function unlock()
|
||||
{
|
||||
// See here: https://dev.mysql.com/doc/refman/5.7/en/lock-tables-and-transactions.html
|
||||
$this->performCommit();
|
||||
|
||||
$this->in_transaction = false;
|
||||
$this->_locked = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does a commit
|
||||
*
|
||||
|
@ -163,18 +191,6 @@ class StaticDatabase extends Database
|
|||
return self::$staticConnection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a global commit for every nested transaction of the static connection
|
||||
*/
|
||||
public static function statCommit()
|
||||
{
|
||||
if (isset(self::$staticConnection)) {
|
||||
while (self::$staticConnection->getTransactionDepth() > 0) {
|
||||
self::$staticConnection->commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a global rollback for every nested transaction of the static connection
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue