* @file
* @ingroup Database
*/
+use MediaWiki\MediaWikiServices;
class CloneDatabase {
/** @var string Table prefix for cloning */
/** @var bool Whether to use temporary tables or not */
private $useTemporaryTables = true;
+ /** @var IMaintainableDatabase */
+ private $db;
+
/**
* Constructor
*
- * @param DatabaseBase $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( DatabaseBase $db, array $tablesToClone,
+ public function __construct( IMaintainableDatabase $db, array $tablesToClone,
$newTablePrefix, $oldTablePrefix = '', $dropCurrentTables = true
) {
$this->db = $db;
# Create new table
wfDebug( __METHOD__ . " duplicating $oldTableName to $newTableName\n" );
- $this->db->duplicateTableStructure( $oldTableName, $newTableName, $this->useTemporaryTables );
+ $this->db->duplicateTableStructure(
+ $oldTableName, $newTableName, $this->useTemporaryTables );
}
}
*/
public static function changePrefix( $prefix ) {
global $wgDBprefix;
- wfGetLBFactory()->forEachLB( function( LoadBalancer $lb ) use ( $prefix ) {
- $lb->setDomainPrefix( $prefix );
- $lb->forEachOpenConnection( function ( DatabaseBase $db ) use ( $prefix ) {
- $db->tablePrefix( $prefix );
- } );
- } );
+
+ $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
+ $lbFactory->setDomainPrefix( $prefix );
$wgDBprefix = $prefix;
}
}