30require_once __DIR__ .
'/Maintenance.php';
40 parent::__construct();
41 $this->
addOption(
"old",
"Old db prefix [0 for none]",
true,
true );
42 $this->
addOption(
"new",
"New db prefix [0 for none]",
true,
true );
46 return Maintenance::DB_ADMIN;
50 $dbName = $this->
getConfig()->get( MainConfigNames::DBname );
53 if ( $this->
getOption(
'old', 0 ) ===
'0' ) {
57 preg_match(
'/^[a-zA-Z]+_$/', $this->
getOption(
'old' ), $m );
58 $old = $m[0] ??
false;
61 if ( $this->
getOption(
'new', 0 ) ===
'0' ) {
65 preg_match(
'/^[a-zA-Z]+_$/', $this->
getOption(
'new' ), $m );
66 $new = $m[0] ??
false;
69 if ( $old ===
false || $new ===
false ) {
72 if ( $old === $new ) {
73 $this->
output(
"Same prefix. Nothing to rename!\n",
true );
76 $this->
output(
"Renaming DB prefix for tables of $dbName from '$old' to '$new'\n" );
80 $res = $dbw->query(
"SHOW TABLES " . $dbw->buildLike( $old, $dbw->anyString() ), __METHOD__ );
81 foreach ( $res as $row ) {
84 $fields = get_object_vars( $row );
86 foreach ( $fields as $table ) {
88 $newTable = preg_replace(
'/^' . $old .
'/', $new, $table );
89 $this->
output(
"Renaming table $table to $newTable\n" );
90 $oldTableEnc = $dbw->addIdentifierQuotes( $table );
91 $newTableEnc = $dbw->addIdentifierQuotes( $newTable );
92 $dbw->query(
"RENAME TABLE $oldTableEnc TO $newTableEnc", __METHOD__ );
96 $this->
output(
"Done! [$count tables]\n" );
102require_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.
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.