7 use Elgg\Traits\Loggable;
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.");
59 public function unlock(
string $namespace): void {
60 $this->assertNamespace($namespace);
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 {
75 $this->assertNamespace($namespace);
77 $result = $this->db->getConnection(
'read')->executeQuery(
"SHOW TABLES LIKE '{$this->db->prefix}{$namespace}_lock'");
90 if (!ctype_alpha($namespace)) {
Provides database mutex that can be used to prevent race conditions between two processes that affect...
assertNamespace(string $namespace)
Assert that the namespace contains only characters [A-Za-z].
unlock(string $namespace)
Unlocks mutex.
lock(string $namespace)
Creates a table {prefix}{$namespace}_lock that is used as a mutex.
isLocked(string $namespace)
Checks if mutex is locked.
__construct(protected Database $db)
Constructor.
Exception thrown if an argument is not of the expected type.
foreach($recommendedExtensions as $extension) if(empty(ini_get('session.gc_probability'))||empty(ini_get('session.gc_divisor'))) $db
if(parse_url(elgg_get_site_url(), PHP_URL_PATH) !=='/') if(file_exists(elgg_get_root_path() . 'robots.txt'))
Set robots.txt.