From 8fdfca30a335331b43d81532bf07a867f7be0171 Mon Sep 17 00:00:00 2001 From: Chad Horohoe Date: Wed, 11 Jun 2008 00:17:42 +0000 Subject: [PATCH] Implement Database::lock() and Database::unlock() based on the same methods in Filestore. Not implemented in Filestore just yet though. --- includes/Database.php | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/includes/Database.php b/includes/Database.php index 5a94942032..7e80c509fc 100644 --- a/includes/Database.php +++ b/includes/Database.php @@ -2234,7 +2234,42 @@ class Database { function buildConcat( $stringList ) { return 'CONCAT(' . implode( ',', $stringList ) . ')'; } + + /** + * Acquire a lock + * + * Abstracted from Filestore::lock() so child classes can implement for + * their own needs. + * + * @param string $lockName Name of lock to aquire + * @param string $method Name of method calling us + * @return bool + */ + public function lock( $lockName, $method ) { + $lockName = $this->addQuotes( $lockName ); + $result = $this->query( "SELECT GET_LOCK($lockName, 5) AS lockstatus", $method ); + $row = $this->fetchObject( $result ); + $this->freeResult( $result ); + if( $row->lockstatus == 1 ) { + return true; + } else { + wfDebug( __METHOD__." failed to acquire lock\n" ); + return false; + } + } + /** + * Release a lock. + * + * @param string $lockName Name of lock to release + * @param string $method Name of method calling us + */ + public function unlock( $lockName, $method ) { + $lockName = $this->addQuotes( $lockName ); + $result = $this->query( "SELECT RELEASE_LOCK($lockName)", $method ); + $this->fetchObject( $result ); + $this->freeResult( $result ); + } } /** -- 2.20.1