28 private string $newTablePrefix;
31 private string $oldTablePrefix;
34 private array $tablesToClone;
37 private bool $dropCurrentTables;
40 private bool $useTemporaryTables =
true;
54 string $newTablePrefix,
55 ?
string $oldTablePrefix =
null,
56 bool $dropCurrentTables =
true
58 if ( !$tablesToClone ) {
59 throw new InvalidArgumentException(
'Empty list of tables to clone' );
62 $this->tablesToClone = $tablesToClone;
63 $this->newTablePrefix = $newTablePrefix;
64 $this->oldTablePrefix = $oldTablePrefix ?? $this->db->
tablePrefix();
65 $this->dropCurrentTables = $dropCurrentTables;
78 foreach ( $this->tablesToClone as $tbl ) {
82 throw new RuntimeException(
"Cannot clone shared table $tbl." );
84 # Clean up from previous aborted run. So that table escaping
85 # works correctly across DB engines, we need to change the pre-
86 # fix back and forth so tableName() works right.
88 $this->db->tablePrefix( $this->oldTablePrefix );
89 $oldTableName = $this->db->tableName( $tbl,
'raw' );
91 $this->db->tablePrefix( $this->newTablePrefix );
92 $newTableName = $this->db->tableName( $tbl,
'raw' );
96 if ( $this->dropCurrentTables ) {
97 if ( $oldTableName === $newTableName ) {
99 throw new LogicException(
"Not dropping new table, as '$newTableName'"
100 .
" is name of both the old and the new table." );
102 $this->db->dropTable( $tbl, __METHOD__ );
107 $this->db->duplicateTableStructure(
108 $oldTableName, $newTableName, $this->useTemporaryTables, __METHOD__ );
116 public function destroy(
bool $dropTables =
false ): void {
118 $this->db->tablePrefix( $this->newTablePrefix );
119 foreach ( $this->tablesToClone as $tbl ) {
120 $this->db->dropTable( $tbl, __METHOD__ );
123 $this->db->tablePrefix( $this->oldTablePrefix );
135 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
136 $lbFactory->setLocalDomainPrefix( $prefix );
139 $wgDBname => $lbFactory->getLocalDomainID()
141 $lbFactory->setDomainAliases( $aliases );
142 foreach ( $lbFactory->getAllLBs() as $lb ) {
143 $lb->setDomainAliases( $aliases );
if(!defined('MW_SETUP_CALLBACK'))
useTemporaryTables(bool $u=true)
Set whether to use temporary tables or not.
static changePrefix(string $prefix)
Change the table prefix on all open DB connections.
destroy(bool $dropTables=false)
Change the prefix back to the original.
__construct(IMaintainableDatabase $db, array $tablesToClone, string $newTablePrefix, ?string $oldTablePrefix=null, bool $dropCurrentTables=true)
$wgDBprefix
Config variable stub for the DBprefix setting, for use by phpdoc and IDEs.
$wgSharedTables
Config variable stub for the SharedTables setting, for use by phpdoc and IDEs.
$wgDBname
Config variable stub for the DBname setting, for use by phpdoc and IDEs.
$wgSharedDB
Config variable stub for the SharedDB setting, for use by phpdoc and IDEs.
Advanced database interface for IDatabase handles that include maintenance methods.