16require_once __DIR__ .
'/Maintenance.php';
26 parent::__construct();
27 $this->
addOption(
"old",
"Old db prefix [0 for none]",
true,
true );
28 $this->
addOption(
"new",
"New db prefix [0 for none]",
true,
true );
33 return Maintenance::DB_ADMIN;
37 $dbName = $this->
getConfig()->get( MainConfigNames::DBname );
40 if ( $this->
getOption(
'old',
'0' ) ===
'0' ) {
44 preg_match(
'/^[a-zA-Z]+_$/', $this->
getOption(
'old' ), $m );
45 $old = $m[0] ??
false;
48 if ( $this->
getOption(
'new',
'0' ) ===
'0' ) {
52 preg_match(
'/^[a-zA-Z]+_$/', $this->
getOption(
'new' ), $m );
53 $new = $m[0] ??
false;
56 if ( $old ===
false || $new ===
false ) {
59 if ( $old === $new ) {
60 $this->
output(
"Same prefix. Nothing to rename!\n" );
64 $this->
output(
"Renaming DB prefix for tables of $dbName from '$old' to '$new'\n" );
68 $res = $dbw->query(
"SHOW TABLES " . $dbw->buildLike( $old, $dbw->anyString() ), __METHOD__ );
69 foreach ( $res as $row ) {
72 $fields = get_object_vars( $row );
74 foreach ( $fields as $table ) {
76 $newTable = preg_replace(
'/^' . $old .
'/', $new, $table );
77 $this->
output(
"Renaming table $table to $newTable\n" );
78 $oldTableEnc = $dbw->addIdentifierQuotes( $table );
79 $newTableEnc = $dbw->addIdentifierQuotes( $newTable );
80 $dbw->query(
"RENAME TABLE $oldTableEnc TO $newTableEnc", __METHOD__ );
84 $this->
output(
"Done! [$count tables]\n" );
90require_once RUN_MAINTENANCE_IF_MAIN;
A class containing constants representing the names of configuration variables.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
getPrimaryDB(string|false $virtualDomain=false)
Maintenance script that changes the prefix of database tables.
getDbType()
Does the script need different DB access? By default, we give Maintenance scripts normal rights to th...
__construct()
Default constructor.
execute()
Do the actual work.