Implement Database::lock() and Database::unlock() based on the same methods in Filest...
authorChad Horohoe <demon@users.mediawiki.org>
Wed, 11 Jun 2008 00:17:42 +0000 (00:17 +0000)
committerChad Horohoe <demon@users.mediawiki.org>
Wed, 11 Jun 2008 00:17:42 +0000 (00:17 +0000)
includes/Database.php

index 5a94942..7e80c50 100644 (file)
@@ -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 );
+       }
 }
 
 /**