57 throw new InvalidArgumentException(
'Empty list of tables to clone' );
76 foreach ( $this->tablesToClone as $tbl ) {
80 throw new RuntimeException(
"Cannot clone shared table $tbl." );
82 # Clean up from previous aborted run. So that table escaping
83 # works correctly across DB engines, we need to change the pre-
84 # fix back and forth so tableName() works right.
86 $this->db->tablePrefix( $this->oldTablePrefix );
87 $oldTableName = $this->db->tableName( $tbl,
'raw' );
89 $this->db->tablePrefix( $this->newTablePrefix );
90 $newTableName = $this->db->tableName( $tbl,
'raw' );
94 if ( $this->dropCurrentTables ) {
95 if ( $oldTableName === $newTableName ) {
97 throw new LogicException(
"Not dropping new table, as '$newTableName'"
98 .
" is name of both the old and the new table." );
100 $this->db->dropTable( $tbl, __METHOD__ );
101 wfDebug( __METHOD__ .
" dropping {$newTableName}" );
106 wfDebug( __METHOD__ .
" duplicating $oldTableName to $newTableName" );
107 $this->db->duplicateTableStructure(
116 public function destroy( $dropTables =
false ) {
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 $lbFactory->forEachLB(
static function (
ILoadBalancer $lb ) use ( $aliases ) {
$wgDBprefix
Current wiki database table name prefix.
$wgDBname
Current wiki database name.
$wgSharedDB
Shared database for multiple wikis.
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
bool $useTemporaryTables
Whether to use temporary tables or not.
bool $dropCurrentTables
Should we DROP tables containing the new names?
IMaintainableDatabase $db
static changePrefix( $prefix)
Change the table prefix on all open DB connections.
string $newTablePrefix
Table prefix for cloning.
__construct(IMaintainableDatabase $db, array $tablesToClone, $newTablePrefix, $oldTablePrefix=null, $dropCurrentTables=true)
destroy( $dropTables=false)
Change the prefix back to the original.
array $tablesToClone
List of tables to be cloned.
useTemporaryTables( $u=true)
Set whether to use temporary tables or not.
string $oldTablePrefix
Current table prefix.
Advanced database interface for IDatabase handles that include maintenance methods.