34 $this->logger = $logger;
43 public function lock($namespace) {
44 $this->assertNamespace($namespace);
48 $this->db->insertData(
"CREATE TABLE {$this->db->prefix}{$namespace}_lock (id INT)");
49 $this->logger->info(
"Locked mutex for $namespace");
53 $this->logger->warn(
"Cannot lock mutex for {$namespace}: already locked.");
64 $this->assertNamespace($namespace);
66 $this->db->deleteData(
"DROP TABLE {$this->db->prefix}{$namespace}_lock");
67 $this->logger->notice(
"Mutex unlocked for $namespace.");
77 $this->assertNamespace($namespace);
79 return (
bool) count($this->db->getData(
"SHOW TABLES LIKE '{$this->db->prefix}{$namespace}_lock'"));
89 private function assertNamespace($namespace) {
90 if (!ctype_alpha($namespace)) {
isLocked($namespace)
Checks if mutex is locked.
lock($namespace)
Creates a table {prefix}{$namespace}_lock that is used as a mutex.
__construct(\Elgg\Database $db,\Elgg\Logger $logger)
Constructor.
unlock($namespace)
Unlocks mutex.