Followup r92081: SQL fix for cleanupUploadStash.php on PostgreSQL (bug 32822)
[lhc/web/wiklou.git] / maintenance / renameDbPrefix.php
index e0b6686..289e747 100644 (file)
@@ -20,7 +20,7 @@
  *
  * @ingroup Maintenance
  */
+
 require_once( dirname( __FILE__ ) . '/Maintenance.php' );
 
 class RenameDbPrefix extends Maintenance {
@@ -53,25 +53,25 @@ class RenameDbPrefix extends Maintenance {
                        preg_match( '/^[a-zA-Z]+_$/', $this->getOption( 'new' ), $m );
                        $new = isset( $m[0] ) ? $m[0] : false;
                }
-       
+
                if ( $old === false || $new === false ) {
                        $this->error( "Invalid prefix!", true );
                }
                if ( $old === $new ) {
                        $this->output( "Same prefix. Nothing to rename!\n", true );
                }
-       
+
                $this->output( "Renaming DB prefix for tables of $wgDBname from '$old' to '$new'\n" );
                $count = 0;
-       
+
                $dbw = wfGetDB( DB_MASTER );
-               $res = $dbw->query( "SHOW TABLES LIKE '" . $dbw->escapeLike( $old ) . "%'" );
+               $res = $dbw->query( "SHOW TABLES " . $dbw->buildLike( $old, $dbw->anyString() ) );
                foreach ( $res as $row ) {
                        // XXX: odd syntax. MySQL outputs an oddly cased "Tables of X"
                        // sort of message. Best not to try $row->x stuff...
                        $fields = get_object_vars( $row );
                        // Silly for loop over one field...
-                       foreach ( $fields as $resName => $table ) {
+                       foreach ( $fields as $table ) {
                                // $old should be regexp safe ([a-zA-Z_])
                                $newTable = preg_replace( '/^' . $old . '/', $new, $table );
                                $this->output( "Renaming table $table to $newTable\n" );
@@ -84,4 +84,4 @@ class RenameDbPrefix extends Maintenance {
 }
 
 $maintClass = "RenameDbPrefix";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );