Merge "Only need one check for is_dir"
[lhc/web/wiklou.git] / includes / objectcache / SqlBagOStuff.php
index 2a92bee..82eeb84 100644 (file)
@@ -145,6 +145,8 @@ class SqlBagOStuff extends BagOStuff {
                                $type = isset( $info['type'] ) ? $info['type'] : 'mysql';
                                $host = isset( $info['host'] ) ? $info['host'] : '[unknown]';
                                $this->logger->debug( __CLASS__ . ": connecting to $host" );
+                               // Use a blank trx profiler to ignore expections as this is a cache
+                               $info['trxProfiler'] = new TransactionProfiler();
                                $db = DatabaseBase::factory( $type, $info );
                                $db->clearFlag( DBO_TRX );
                        } else {
@@ -405,7 +407,7 @@ class SqlBagOStuff extends BagOStuff {
         * @param int $exptime
         * @return bool
         */
-       public function cas( $casToken, $key, $value, $exptime = 0 ) {
+       protected function cas( $casToken, $key, $value, $exptime = 0 ) {
                list( $serverIndex, $tableName ) = $this->getTableByKey( $key );
                try {
                        $db = $this->getDB( $serverIndex );
@@ -447,10 +449,9 @@ class SqlBagOStuff extends BagOStuff {
 
        /**
         * @param string $key
-        * @param int $time
         * @return bool
         */
-       public function delete( $key, $time = 0 ) {
+       public function delete( $key ) {
                list( $serverIndex, $tableName ) = $this->getTableByKey( $key );
                try {
                        $db = $this->getDB( $serverIndex );
@@ -515,6 +516,14 @@ class SqlBagOStuff extends BagOStuff {
                return $newValue;
        }
 
+       public function merge( $key, $callback, $exptime = 0, $attempts = 10 ) {
+               if ( !is_callable( $callback ) ) {
+                       throw new Exception( "Got invalid callback." );
+               }
+
+               return $this->mergeViaCas( $key, $callback, $exptime, $attempts );
+       }
+
        /**
         * @param DatabaseBase $db
         * @param string $exptime
@@ -724,9 +733,11 @@ class SqlBagOStuff extends BagOStuff {
                        $this->markServerDown( $exception, $serverIndex );
                }
                if ( $exception->db && $exception->db->wasReadOnlyError() ) {
-                       try {
-                               $exception->db->rollback( __METHOD__ );
-                       } catch ( DBError $e ) {
+                       if ( $exception->db->trxLevel() ) {
+                               try {
+                                       $exception->db->rollback( __METHOD__ );
+                               } catch ( DBError $e ) {
+                               }
                        }
                }
 
@@ -781,9 +792,3 @@ class SqlBagOStuff extends BagOStuff {
                }
        }
 }
-
-/**
- * Backwards compatibility alias
- */
-class MediaWikiBagOStuff extends SqlBagOStuff {
-}