37 public function lock(
string $namespace): bool {
42 $this->db->getConnection(
'write')->executeStatement(
"CREATE TABLE {$this->db->prefix}{$namespace}_lock (id INT)");
44 $this->
getLogger()->info(
"Locked mutex for {$namespace}");
48 $this->
getLogger()->warning(
"Cannot lock mutex for {$namespace}: already locked.");
62 $this->db->getConnection(
'write')->executeStatement(
"DROP TABLE {$this->db->prefix}{$namespace}_lock");
64 $this->
getLogger()->notice(
"Mutex unlocked for {$namespace}.");
74 public function isLocked(
string $namespace): bool {
77 $result = $this->db->getConnection(
'read')->executeQuery(
"SHOW TABLES LIKE '{$this->db->prefix}{$namespace}_lock'");
90 if (!ctype_alpha($namespace)) {
assertNamespace(string $namespace)
Assert that the namespace contains only characters [A-Za-z].
Exception thrown if an argument is not of the expected type.
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition plus the scripts used to control compilation and installation of the executable as a special the source code distributed need not include anything that is normally and so on of the operating system on which the executable unless that component itself accompanies the executable If distribution of executable or object code is made by offering access to copy from a designated then offering equivalent access to copy the source code from the same place counts as distribution of the source even though third parties are not compelled to copy the source along with the object code You may not or distribute the Program except as expressly provided under this License Any attempt otherwise to sublicense or distribute the Program is void
Provides database mutex that can be used to prevent race conditions between two processes that affect...
__construct(protected Database $db)
Constructor.
isLocked(string $namespace)
Checks if mutex is locked.
trait Loggable
Enables adding a logger.
foreach($recommendedExtensions as $extension) if(empty(ini_get('session.gc_probability'))||empty(ini_get('session.gc_divisor'))) $db
getLogger()
Returns logger.
lock(string $namespace)
Creates a table {prefix}{$namespace}_lock that is used as a mutex.
unlock(string $namespace)
Unlocks mutex.