Merge "Remove "@author Bryan Davis" and "Brad Jorsch" annotations"
[lhc/web/wiklou.git] / includes / db / CloneDatabase.php
index caca7e2..809b660 100644 (file)
@@ -23,6 +23,8 @@
  * @file
  * @ingroup Database
  */
+use MediaWiki\MediaWikiServices;
+use Wikimedia\Rdbms\IMaintainableDatabase;
 
 class CloneDatabase {
        /** @var string Table prefix for cloning */
@@ -40,16 +42,19 @@ class CloneDatabase {
        /** @var bool Whether to use temporary tables or not */
        private $useTemporaryTables = true;
 
+       /** @var IMaintainableDatabase */
+       private $db;
+
        /**
         * Constructor
         *
-        * @param IDatabase $db A database subclass
+        * @param IMaintainableDatabase $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( IDatabase $db, array $tablesToClone,
+       public function __construct( IMaintainableDatabase $db, array $tablesToClone,
                $newTablePrefix, $oldTablePrefix = '', $dropCurrentTables = true
        ) {
                $this->db = $db;
@@ -75,7 +80,7 @@ class CloneDatabase {
                foreach ( $this->tablesToClone as $tbl ) {
                        if ( $wgSharedDB && in_array( $tbl, $wgSharedTables, true ) ) {
                                // Shared tables don't work properly when cloning due to
-                               // how prefixes are handled (bug 65654)
+                               // how prefixes are handled (T67654)
                                throw new RuntimeException( "Cannot clone shared table $tbl." );
                        }
                        # Clean up from previous aborted run.  So that table escaping
@@ -103,7 +108,8 @@ class CloneDatabase {
 
                        # Create new table
                        wfDebug( __METHOD__ . " duplicating $oldTableName to $newTableName\n" );
-                       $this->db->duplicateTableStructure( $oldTableName, $newTableName, $this->useTemporaryTables );
+                       $this->db->duplicateTableStructure(
+                               $oldTableName, $newTableName, $this->useTemporaryTables );
                }
        }
 
@@ -129,12 +135,9 @@ class CloneDatabase {
         */
        public static function changePrefix( $prefix ) {
                global $wgDBprefix;
-               wfGetLBFactory()->forEachLB( function( LoadBalancer $lb ) use ( $prefix ) {
-                       $lb->setDomainPrefix( $prefix );
-                       $lb->forEachOpenConnection( function ( IDatabase $db ) use ( $prefix ) {
-                               $db->tablePrefix( $prefix );
-                       } );
-               } );
+
+               $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
+               $lbFactory->setDomainPrefix( $prefix );
                $wgDBprefix = $prefix;
        }
 }