= self::MAX_LEN_LOCK_NAME) { //convert ot prefix and md5 full length $id = mb_substr($id, 0, 32) . md5($id); } $this->id = $id; } public function setLock() { Db::fetchOne('SELECT GET_LOCK(?,?)', array($this->id, self::MAX_LOCK_TIME)); } public function unLock() { Db::query('SELECT RELEASE_LOCK(?)', array($this->id)); } public function getId() { return $this->id; } /** * Checks if the lock is available to use. * * @param string $key * @return bool */ public static function isLockAvailable($key) { return (bool)Db::fetchOne('SELECT IS_FREE_LOCK(?)', [$key]); } }