Update more docs and type hints to use IDatabase
[lhc/web/wiklou.git] / includes / objectcache / SqlBagOStuff.php
index 1ed8ef5..f634df1 100644 (file)
@@ -127,12 +127,10 @@ class SqlBagOStuff extends BagOStuff {
         * Get a connection to the specified database
         *
         * @param int $serverIndex
-        * @return DatabaseBase
+        * @return IDatabase
         * @throws MWException
         */
        protected function getDB( $serverIndex ) {
-               global $wgDebugDBTransactions;
-
                if ( !isset( $this->conns[$serverIndex] ) ) {
                        if ( $serverIndex >= $this->numServers ) {
                                throw new MWException( __METHOD__ . ": Invalid server index \"$serverIndex\"" );
@@ -147,9 +145,6 @@ class SqlBagOStuff extends BagOStuff {
 
                        # If server connection info was given, use that
                        if ( $this->serverInfos ) {
-                               if ( $wgDebugDBTransactions ) {
-                                       $this->logger->debug( "Using provided serverInfo for SqlBagOStuff" );
-                               }
                                $info = $this->serverInfos[$serverIndex];
                                $type = isset( $info['type'] ) ? $info['type'] : 'mysql';
                                $host = isset( $info['host'] ) ? $info['host'] : '[unknown]';
@@ -173,9 +168,7 @@ class SqlBagOStuff extends BagOStuff {
                                        $db = wfGetDB( $index );
                                }
                        }
-                       if ( $wgDebugDBTransactions ) {
-                               $this->logger->debug( sprintf( "Connection %s will be used for SqlBagOStuff", $db ) );
-                       }
+                       $this->logger->debug( sprintf( "Connection %s will be used for SqlBagOStuff", $db ) );
                        $this->conns[$serverIndex] = $db;
                }
 
@@ -220,12 +213,7 @@ class SqlBagOStuff extends BagOStuff {
                }
        }
 
-       /**
-        * @param string $key
-        * @param mixed $casToken [optional]
-        * @return mixed
-        */
-       public function get( $key, &$casToken = null ) {
+       public function get( $key, &$casToken = null, $flags = 0 ) {
                $values = $this->getMulti( array( $key ) );
                if ( array_key_exists( $key, $values ) ) {
                        $casToken = $values[$key];
@@ -234,11 +222,7 @@ class SqlBagOStuff extends BagOStuff {
                return false;
        }
 
-       /**
-        * @param array $keys
-        * @return array
-        */
-       public function getMulti( array $keys ) {
+       public function getMulti( array $keys, $flags = 0 ) {
                $values = array(); // array of (key => value)
 
                $keysByTable = array();
@@ -370,37 +354,7 @@ class SqlBagOStuff extends BagOStuff {
         * @return bool
         */
        public function set( $key, $value, $exptime = 0 ) {
-               list( $serverIndex, $tableName ) = $this->getTableByKey( $key );
-               try {
-                       $db = $this->getDB( $serverIndex );
-                       $exptime = intval( $exptime );
-
-                       if ( $exptime < 0 ) {
-                               $exptime = 0;
-                       }
-
-                       if ( $exptime == 0 ) {
-                               $encExpiry = $this->getMaxDateTime( $db );
-                       } else {
-                               $exptime = $this->convertExpiry( $exptime );
-                               $encExpiry = $db->timestamp( $exptime );
-                       }
-                       // (bug 24425) use a replace if the db supports it instead of
-                       // delete/insert to avoid clashes with conflicting keynames
-                       $db->replace(
-                               $tableName,
-                               array( 'keyname' ),
-                               array(
-                                       'keyname' => $key,
-                                       'value' => $db->encodeBlob( $this->serialize( $value ) ),
-                                       'exptime' => $encExpiry
-                               ), __METHOD__ );
-               } catch ( DBError $e ) {
-                       $this->handleWriteError( $e, $serverIndex );
-                       return false;
-               }
-
-               return true;
+               return $this->setMulti( array( $key => $value ), $exptime );
        }
 
        /**
@@ -528,7 +482,7 @@ class SqlBagOStuff extends BagOStuff {
        }
 
        /**
-        * @param DatabaseBase $db
+        * @param IDatabase $db
         * @param string $exptime
         * @return bool
         */
@@ -537,7 +491,7 @@ class SqlBagOStuff extends BagOStuff {
        }
 
        /**
-        * @param DatabaseBase $db
+        * @param IDatabase $db
         * @return string
         */
        protected function getMaxDateTime( $db ) {