Merge "Using ULS in Special:PageLanguage"
[lhc/web/wiklou.git] / includes / externalstore / ExternalStoreDB.php
index b7e5469..952bf63 100644 (file)
@@ -96,9 +96,6 @@ class ExternalStoreDB extends ExternalStoreMedium {
                if ( !$id ) {
                        throw new MWException( __METHOD__ . ': no insert ID' );
                }
-               if ( $dbw->getFlag( DBO_TRX ) ) {
-                       $dbw->commit( __METHOD__ );
-               }
 
                return "DB://$cluster/$id";
        }
@@ -106,8 +103,8 @@ class ExternalStoreDB extends ExternalStoreMedium {
        /**
         * Get a LoadBalancer for the specified cluster
         *
-        * @param string $cluster cluster name
-        * @return LoadBalancer object
+        * @param string $cluster Cluster name
+        * @return LoadBalancer
         */
        function getLoadBalancer( $cluster ) {
                $wiki = isset( $this->params['wiki'] ) ? $this->params['wiki'] : false;
@@ -118,8 +115,8 @@ class ExternalStoreDB extends ExternalStoreMedium {
        /**
         * Get a slave database connection for the specified cluster
         *
-        * @param string $cluster cluster name
-        * @return DatabaseBase object
+        * @param string $cluster Cluster name
+        * @return DatabaseBase
         */
        function getSlave( $cluster ) {
                global $wgDefaultExternalStore;
@@ -128,33 +125,39 @@ class ExternalStoreDB extends ExternalStoreMedium {
                $lb = $this->getLoadBalancer( $cluster );
 
                if ( !in_array( "DB://" . $cluster, (array)$wgDefaultExternalStore ) ) {
-                       wfDebug( "read only external store" );
+                       wfDebug( "read only external store\n" );
                        $lb->allowLagged( true );
                } else {
-                       wfDebug( "writable external store" );
+                       wfDebug( "writable external store\n" );
                }
 
-               return $lb->getConnection( DB_SLAVE, array(), $wiki );
+               $db = $lb->getConnection( DB_SLAVE, array(), $wiki );
+               $db->clearFlag( DBO_TRX ); // sanity
+
+               return $db;
        }
 
        /**
         * Get a master database connection for the specified cluster
         *
-        * @param string $cluster cluster name
-        * @return DatabaseBase object
+        * @param string $cluster Cluster name
+        * @return DatabaseBase
         */
        function getMaster( $cluster ) {
                $wiki = isset( $this->params['wiki'] ) ? $this->params['wiki'] : false;
                $lb = $this->getLoadBalancer( $cluster );
 
-               return $lb->getConnection( DB_MASTER, array(), $wiki );
+               $db = $lb->getConnection( DB_MASTER, array(), $wiki );
+               $db->clearFlag( DBO_TRX ); // sanity
+
+               return $db;
        }
 
        /**
         * Get the 'blobs' table name for this database
         *
-        * @param $db DatabaseBase
-        * @return String: table name ('blobs' by default)
+        * @param DatabaseBase $db
+        * @return string Table name ('blobs' by default)
         */
        function getTable( $db ) {
                $table = $db->getLBInfo( 'blobs table' );
@@ -169,9 +172,9 @@ class ExternalStoreDB extends ExternalStoreMedium {
         * Fetch a blob item out of the database; a cache of the last-loaded
         * blob will be kept so that multiple loads out of a multi-item blob
         * can avoid redundant database access and decompression.
-        * @param $cluster
-        * @param $id
-        * @param $itemID
+        * @param string $cluster
+        * @param string $id
+        * @param string $itemID
         * @return mixed
         * @private
         */
@@ -187,27 +190,27 @@ class ExternalStoreDB extends ExternalStoreMedium {
                $cacheID = ( $itemID === false ) ? "$cluster/$id" : "$cluster/$id/";
                if ( isset( $externalBlobCache[$cacheID] ) ) {
                        wfDebugLog( 'ExternalStoreDB-cache',
-                               "ExternalStoreDB::fetchBlob cache hit on $cacheID\n" );
+                               "ExternalStoreDB::fetchBlob cache hit on $cacheID" );
 
                        return $externalBlobCache[$cacheID];
                }
 
                wfDebugLog( 'ExternalStoreDB-cache',
-                       "ExternalStoreDB::fetchBlob cache miss on $cacheID\n" );
+                       "ExternalStoreDB::fetchBlob cache miss on $cacheID" );
 
                $dbr = $this->getSlave( $cluster );
                $ret = $dbr->selectField( $this->getTable( $dbr ),
                        'blob_text', array( 'blob_id' => $id ), __METHOD__ );
                if ( $ret === false ) {
                        wfDebugLog( 'ExternalStoreDB',
-                               "ExternalStoreDB::fetchBlob master fallback on $cacheID\n" );
+                               "ExternalStoreDB::fetchBlob master fallback on $cacheID" );
                        // Try the master
                        $dbw = $this->getMaster( $cluster );
                        $ret = $dbw->selectField( $this->getTable( $dbw ),
                                'blob_text', array( 'blob_id' => $id ), __METHOD__ );
                        if ( $ret === false ) {
                                wfDebugLog( 'ExternalStoreDB',
-                                       "ExternalStoreDB::fetchBlob master failed to find $cacheID\n" );
+                                       "ExternalStoreDB::fetchBlob master failed to find $cacheID" );
                        }
                }
                if ( $itemID !== false && $ret !== false ) {
@@ -239,7 +242,7 @@ class ExternalStoreDB extends ExternalStoreMedium {
                if ( $ids ) {
                        wfDebugLog( __CLASS__, __METHOD__ .
                                " master fallback on '$cluster' for: " .
-                               implode( ',', array_keys( $ids ) ) . "\n" );
+                               implode( ',', array_keys( $ids ) ) );
                        // Try the master
                        $dbw = $this->getMaster( $cluster );
                        $res = $dbw->select( $this->getTable( $dbr ),
@@ -247,7 +250,7 @@ class ExternalStoreDB extends ExternalStoreMedium {
                                array( 'blob_id' => array_keys( $ids ) ),
                                __METHOD__ );
                        if ( $res === false ) {
-                               wfDebugLog( __CLASS__, __METHOD__ . " master failed on '$cluster'\n" );
+                               wfDebugLog( __CLASS__, __METHOD__ . " master failed on '$cluster'" );
                        } else {
                                $this->mergeBatchResult( $ret, $ids, $res );
                        }
@@ -255,7 +258,7 @@ class ExternalStoreDB extends ExternalStoreMedium {
                if ( $ids ) {
                        wfDebugLog( __CLASS__, __METHOD__ .
                                " master on '$cluster' failed locating items: " .
-                               implode( ',', array_keys( $ids ) ) . "\n" );
+                               implode( ',', array_keys( $ids ) ) );
                }
 
                return $ret;
@@ -282,6 +285,10 @@ class ExternalStoreDB extends ExternalStoreMedium {
                }
        }
 
+       /**
+        * @param string $url
+        * @return array
+        */
        protected function parseURL( $url ) {
                $path = explode( '/', $url );