diff --git a/lib/classes/lock/postgres_lock_factory.php b/lib/classes/lock/postgres_lock_factory.php index 1d2ccf6159e..1d18967d59c 100644 --- a/lib/classes/lock/postgres_lock_factory.php +++ b/lib/classes/lock/postgres_lock_factory.php @@ -118,15 +118,15 @@ class postgres_lock_factory implements lock_factory { } /** - * Multiple locks for the same resource can be held by a single process. + * Multiple locks for the same resource can NOT be held by a single process. * * @deprecated since Moodle 4.0. - * @return boolean - Defer to the DB driver. + * @return boolean - false. */ public function supports_recursion() { debugging('The function supports_recursion() is deprecated, please do not use it anymore.', DEBUG_DEVELOPER); - return true; + return false; } /** @@ -149,6 +149,7 @@ class postgres_lock_factory implements lock_factory { /** * Create and get a lock + * * @param string $resource - The identifier for the lock. Should use frankenstyle prefix. * @param int $timeout - The number of seconds to wait for a lock before giving up. * @param int $maxlifetime - Unused by this lock type. @@ -159,8 +160,14 @@ class postgres_lock_factory implements lock_factory { $token = $this->get_index_from_key($this->type . '_' . $resource); - $params = array('locktype' => $this->dblockid, - 'token' => $token); + if (isset($this->openlocks[$token])) { + return false; + } + + $params = [ + 'locktype' => $this->dblockid, + 'token' => $token + ]; $locked = false;