Merge "Don't fallback from uk to ru"
[lhc/web/wiklou.git] / includes / db / CloneDatabase.php
index bc703f3..f1ccd2a 100644 (file)
@@ -23,6 +23,7 @@
  * @file
  * @ingroup Database
  */
+use MediaWiki\MediaWikiServices;
 
 class CloneDatabase {
        /** @var string Table prefix for cloning */
@@ -32,7 +33,7 @@ class CloneDatabase {
        private $oldTablePrefix = '';
 
        /** @var array List of tables to be cloned */
-       private $tablesToClone = array();
+       private $tablesToClone = [];
 
        /** @var bool Should we DROP tables containing the new names? */
        private $dropCurrentTables = true;
@@ -40,16 +41,19 @@ class CloneDatabase {
        /** @var bool Whether to use temporary tables or not */
        private $useTemporaryTables = true;
 
+       /** @var Database */
+       private $db;
+
        /**
         * Constructor
         *
-        * @param DatabaseBase $db A database subclass
+        * @param Database $db A database subclass
         * @param array $tablesToClone An array of tables to clone, unprefixed
         * @param string $newTablePrefix Prefix to assign to the tables
         * @param string $oldTablePrefix Prefix on current tables, if not $wgDBprefix
         * @param bool $dropCurrentTables
         */
-       public function __construct( DatabaseBase $db, array $tablesToClone,
+       public function __construct( Database $db, array $tablesToClone,
                $newTablePrefix, $oldTablePrefix = '', $dropCurrentTables = true
        ) {
                $this->db = $db;
@@ -76,7 +80,7 @@ class CloneDatabase {
                        if ( $wgSharedDB && in_array( $tbl, $wgSharedTables, true ) ) {
                                // Shared tables don't work properly when cloning due to
                                // how prefixes are handled (bug 65654)
-                               throw new MWException( "Cannot clone shared table $tbl." );
+                               throw new RuntimeException( "Cannot clone shared table $tbl." );
                        }
                        # Clean up from previous aborted run.  So that table escaping
                        # works correctly across DB engines, we need to change the pre-
@@ -89,11 +93,11 @@ class CloneDatabase {
                        $newTableName = $this->db->tableName( $tbl, 'raw' );
 
                        if ( $this->dropCurrentTables
-                               && !in_array( $this->db->getType(), array( 'postgres', 'oracle' ) )
+                               && !in_array( $this->db->getType(), [ 'postgres', 'oracle' ] )
                        ) {
                                if ( $oldTableName === $newTableName ) {
                                        // Last ditch check to avoid data loss
-                                       throw new MWException( "Not dropping new table, as '$newTableName'"
+                                       throw new LogicException( "Not dropping new table, as '$newTableName'"
                                                . " is name of both the old and the new table." );
                                }
                                $this->db->dropTable( $tbl, __METHOD__ );
@@ -129,25 +133,9 @@ class CloneDatabase {
         */
        public static function changePrefix( $prefix ) {
                global $wgDBprefix;
-               wfGetLBFactory()->forEachLB( array( 'CloneDatabase', 'changeLBPrefix' ), array( $prefix ) );
-               $wgDBprefix = $prefix;
-       }
-
-       /**
-        * @param LoadBalancer $lb
-        * @param string $prefix
-        * @return void
-        */
-       public static function changeLBPrefix( $lb, $prefix ) {
-               $lb->forEachOpenConnection( array( 'CloneDatabase', 'changeDBPrefix' ), array( $prefix ) );
-       }
 
-       /**
-        * @param DatabaseBase $db
-        * @param string $prefix
-        * @return void
-        */
-       public static function changeDBPrefix( $db, $prefix ) {
-               $db->tablePrefix( $prefix );
+               $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
+               $lbFactory->setDomainPrefix( $prefix );
+               $wgDBprefix = $prefix;
        }
 }