Follow-up I0b781c11 (2a55449): use User::getAutomaticGroups().
[lhc/web/wiklou.git] / includes / filerepo / backend / lockmanager / DBLockManager.php
index ac9c079..c2a5085 100644 (file)
@@ -1,4 +1,25 @@
 <?php
+/**
+ * Version of LockManager based on using DB table locks.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup LockManager
+ */
 
 /**
  * Version of LockManager based on using DB table locks.
@@ -14,6 +35,7 @@
  * Caching is used to avoid hitting servers that are down.
  *
  * @ingroup LockManager
+ * @since 1.19
  */
 class DBLockManager extends LockManager {
        /** @var Array Map of DB names to server config */
@@ -54,7 +76,11 @@ class DBLockManager extends LockManager {
         * @param Array $config 
         */
        public function __construct( array $config ) {
-               $this->dbServers = $config['dbServers'];
+               parent::__construct( $config );
+
+               $this->dbServers = isset( $config['dbServers'] )
+                       ? $config['dbServers']
+                       : array(); // likely just using 'localDBMaster'
                // Sanitize dbsByBucket config to prevent PHP errors
                $this->dbsByBucket = array_filter( $config['dbsByBucket'], 'is_array' );
                $this->dbsByBucket = array_values( $this->dbsByBucket ); // consecutive
@@ -87,6 +113,9 @@ class DBLockManager extends LockManager {
 
        /**
         * @see LockManager::doLock()
+        * @param $paths array
+        * @param $type int
+        * @return Status
         */
        protected function doLock( array $paths, $type ) {
                $status = Status::newGood();
@@ -137,6 +166,9 @@ class DBLockManager extends LockManager {
 
        /**
         * @see LockManager::doUnlock()
+        * @param $paths array
+        * @param $type int
+        * @return Status
         */
        protected function doUnlock( array $paths, $type ) {
                $status = Status::newGood();
@@ -242,7 +274,7 @@ class DBLockManager extends LockManager {
         * Get (or reuse) a connection to a lock DB
         *
         * @param $lockDb string
-        * @return Database
+        * @return DatabaseBase
         * @throws DBError
         */
        protected function getConnection( $lockDb ) {
@@ -271,7 +303,7 @@ class DBLockManager extends LockManager {
                        $this->initConnection( $lockDb, $this->conns[$lockDb] );
                }
                if ( !$this->conns[$lockDb]->trxLevel() ) {
-                       $this->conns[$lockDb]->begin(); // start transaction
+                       $this->conns[$lockDb]->begin( __METHOD__ ); // start transaction
                }
                return $this->conns[$lockDb];
        }
@@ -297,7 +329,7 @@ class DBLockManager extends LockManager {
                foreach ( $this->conns as $lockDb => $db ) {
                        if ( $db->trxLevel() ) { // in transaction
                                try {
-                                       $db->rollback(); // finish transaction and kill any rows
+                                       $db->rollback( __METHOD__ ); // finish transaction and kill any rows
                                } catch ( DBError $e ) {
                                        $status->fatal( 'lockmanager-fail-db-release', $lockDb );
                                }
@@ -386,7 +418,7 @@ class DBLockManager extends LockManager {
                foreach ( $this->conns as $lockDb => $db ) {
                        if ( $db->trxLevel() ) { // in transaction
                                try {
-                                       $db->rollback(); // finish transaction and kill any rows
+                                       $db->rollback( __METHOD__ ); // finish transaction and kill any rows
                                } catch ( DBError $e ) {
                                        // oh well
                                }
@@ -410,11 +442,21 @@ class MySqlLockManager extends DBLockManager {
                self::LOCK_EX => self::LOCK_EX
        );
 
+       /**
+        * @param $lockDb string
+        * @param $db DatabaseBase
+        */
        protected function initConnection( $lockDb, DatabaseBase $db ) {
                # Let this transaction see lock rows from other transactions
                $db->query( "SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;" );
        }
 
+       /**
+        * @param $lockDb string
+        * @param $paths array
+        * @param $type int
+        * @return bool
+        */
        protected function doLockingQuery( $lockDb, array $paths, $type ) {
                $db = $this->getConnection( $lockDb );
                if ( !$db ) {