28 private $newTablePrefix;
31 private $oldTablePrefix;
34 private $tablesToClone;
37 private $dropCurrentTables;
40 private $useTemporaryTables =
true;
55 string $newTablePrefix,
56 string $oldTablePrefix =
null,
57 bool $dropCurrentTables =
true
59 if ( !$tablesToClone ) {
60 throw new InvalidArgumentException(
'Empty list of tables to clone' );
63 $this->tablesToClone = $tablesToClone;
64 $this->newTablePrefix = $newTablePrefix;
65 $this->oldTablePrefix = $oldTablePrefix ?? $this->db->tablePrefix();
66 $this->dropCurrentTables = $dropCurrentTables;
79 foreach ( $this->tablesToClone as $tbl ) {
83 throw new RuntimeException(
"Cannot clone shared table $tbl." );
85 # Clean up from previous aborted run. So that table escaping
86 # works correctly across DB engines, we need to change the pre-
87 # fix back and forth so tableName() works right.
89 $this->db->tablePrefix( $this->oldTablePrefix );
90 $oldTableName = $this->db->tableName( $tbl,
'raw' );
92 $this->db->tablePrefix( $this->newTablePrefix );
93 $newTableName = $this->db->tableName( $tbl,
'raw' );
97 if ( $this->dropCurrentTables ) {
98 if ( $oldTableName === $newTableName ) {
100 throw new LogicException(
"Not dropping new table, as '$newTableName'"
101 .
" is name of both the old and the new table." );
103 $this->db->dropTable( $tbl, __METHOD__ );
104 wfDebug( __METHOD__ .
" dropping {$newTableName}" );
109 wfDebug( __METHOD__ .
" duplicating $oldTableName to $newTableName" );
110 $this->db->duplicateTableStructure(
119 public function destroy( $dropTables =
false ) {
121 $this->db->tablePrefix( $this->newTablePrefix );
122 foreach ( $this->tablesToClone as $tbl ) {
123 $this->db->dropTable( $tbl, __METHOD__ );
126 $this->db->tablePrefix( $this->oldTablePrefix );
138 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
139 $lbFactory->setLocalDomainPrefix( $prefix );
142 $wgDBname => $lbFactory->getLocalDomainID()
144 $lbFactory->setDomainAliases( $aliases );
145 foreach ( $lbFactory->getAllLBs() as $lb ) {
146 $lb->setDomainAliases( $aliases );
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
__construct(IMaintainableDatabase $db, array $tablesToClone, string $newTablePrefix, string $oldTablePrefix=null, bool $dropCurrentTables=true)
static changePrefix( $prefix)
Change the table prefix on all open DB connections.
destroy( $dropTables=false)
Change the prefix back to the original.
useTemporaryTables( $u=true)
Set whether to use temporary tables or not.
$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.