49 $dbName = $this->getConfig()->get( MainConfigNames::DBname );
52 if ( $this->getOption(
'old', 0 ) ===
'0' ) {
56 preg_match(
'/^[a-zA-Z]+_$/', $this->getOption(
'old' ), $m );
57 $old = $m[0] ??
false;
60 if ( $this->getOption(
'new', 0 ) ===
'0' ) {
64 preg_match(
'/^[a-zA-Z]+_$/', $this->getOption(
'new' ), $m );
65 $new = $m[0] ??
false;
68 if ( $old ===
false || $new ===
false ) {
69 $this->fatalError(
"Invalid prefix!" );
71 if ( $old === $new ) {
72 $this->output(
"Same prefix. Nothing to rename!\n",
true );
75 $this->output(
"Renaming DB prefix for tables of $dbName from '$old' to '$new'\n" );
78 $dbw = $this->getPrimaryDB();
79 $res = $dbw->query(
"SHOW TABLES " . $dbw->buildLike( $old, $dbw->anyString() ), __METHOD__ );
80 foreach ( $res as $row ) {
83 $fields = get_object_vars( $row );
85 foreach ( $fields as $table ) {
87 $newTable = preg_replace(
'/^' . $old .
'/', $new, $table );
88 $this->output(
"Renaming table $table to $newTable\n" );
89 $oldTableEnc = $dbw->addIdentifierQuotes( $table );
90 $newTableEnc = $dbw->addIdentifierQuotes( $newTable );
91 $dbw->query(
"RENAME TABLE $oldTableEnc TO $newTableEnc", __METHOD__ );
95 $this->output(
"Done! [$count tables]\n" );