Merge "Add $wgRateLimits types ip-all and subnet-all"
[lhc/web/wiklou.git] / includes / db / DatabasePostgres.php
index c9d7b35..e84f264 100644 (file)
@@ -395,6 +395,10 @@ class DatabasePostgres extends Database {
                if ( function_exists( 'mb_convert_encoding' ) ) {
                        $sql = mb_convert_encoding( $sql, 'UTF-8' );
                }
+               // Clear previously left over PQresult
+               while ( $res = pg_get_result( $this->mConn ) ) {
+                       pg_free_result( $res );
+               }
                if ( pg_send_query( $this->mConn, $sql ) === false ) {
                        throw new DBUnexpectedError( $this, "Unable to post new query to PostgreSQL\n" );
                }
@@ -1577,11 +1581,13 @@ SQL;
                                "SELECT pg_try_advisory_lock($key) AS lockstatus", $method );
                        $row = $this->fetchObject( $result );
                        if ( $row->lockstatus === 't' ) {
+                               parent::lock( $lockName, $method, $timeout ); // record
                                return true;
                        } else {
                                sleep( 1 );
                        }
                }
+
                wfDebug( __METHOD__ . " failed to acquire lock\n" );
 
                return false;
@@ -1599,7 +1605,14 @@ SQL;
                $result = $this->query( "SELECT pg_advisory_unlock($key) as lockstatus", $method );
                $row = $this->fetchObject( $result );
 
-               return ( $row->lockstatus === 't' );
+               if ( $row->lockstatus === 't' ) {
+                       parent::unlock( $lockName, $method ); // record
+                       return true;
+               }
+
+               wfDebug( __METHOD__ . " failed to release lock\n" );
+
+               return false;
        }
 
        /**
@@ -1607,7 +1620,7 @@ SQL;
         * @return string Integer
         */
        private function bigintFromLockName( $lockName ) {
-               return wfBaseConvert( substr( sha1( $lockName ), 0, 15 ), 16, 10 );
+               return Wikimedia\base_convert( substr( sha1( $lockName ), 0, 15 ), 16, 10 );
        }
 } // end DatabasePostgres class