WordPress.org

Make WordPress Core

Ticket #11707: 11707_include_all_tables.diff

File 11707_include_all_tables.diff, 3.3 KB (added by neoxx, 4 years ago)
  • repair.php

     
    3131 
    3232        $okay = true; 
    3333 
    34         // Loop over the WP tables, checking and repairing as needed. 
    35         foreach ($wpdb->tables as $table) { 
    36                 if ( in_array($table, $wpdb->old_tables) ) 
    37                         continue; 
     34        //retrieve database tables with WP prefix 
     35        $tables = $wpdb->get_col( "SHOW TABLES" ); 
    3836 
    39                 $check = $wpdb->get_row("CHECK TABLE {$wpdb->prefix}$table"); 
     37        //use only current WP tables 
     38        $wp_tables = array_diff( $wpdb->tables, $wpdb->old_tables ); 
     39 
     40        //merge tables which we retrieved from the database with default WP tables 
     41        foreach( $wp_tables as $wp_table ) { 
     42                if ( in_array($wpdb->prefix.$wp_table, $tables) == false ) 
     43                        array_push ( $tables, $wpdb->prefix.$wp_table ); 
     44        } 
     45 
     46        //users can include or exclude tables with the filter 'repair_tables' 
     47        $tables = apply_filters( 'repair_tables', $tables ); 
     48 
     49        // Loop over the database tables, checking and repairing as needed. 
     50        foreach ($tables as $table) { 
     51                $check = $wpdb->get_row("CHECK TABLE $table"); 
    4052                if ( 'OK' == $check->Msg_text ) { 
    41                         echo "<p>The {$wpdb->prefix}$table table is okay."; 
     53                        echo "<p>The $table table is okay."; 
    4254                } else { 
    43                         echo "<p>The {$wpdb->prefix}$table table is not okay. It is reporting the following error: <code>$check->Msg_text</code>.  WordPress will attempt to repair this table&hellip;"; 
    44                         $repair = $wpdb->get_row("REPAIR TABLE {$wpdb->prefix}$table"); 
     55                        echo "<p>The $table table is not okay. It is reporting the following error: <code>$check->Msg_text</code>.  WordPress will attempt to repair this table&hellip;"; 
     56                        $repair = $wpdb->get_row("REPAIR TABLE $table"); 
    4557                        if ( 'OK' == $check->Msg_text ) { 
    46                                 echo "<br />&nbsp;&nbsp;&nbsp;&nbsp;Sucessfully repaired the {$wpdb->prefix}$table table."; 
     58                                echo "<br />&nbsp;&nbsp;&nbsp;&nbsp;Successfully repaired the $table table."; 
    4759                        } else { 
    48                                 echo "<br />&nbsp;&nbsp;&nbsp;&nbsp;Failed to repair the {$wpdb->prefix}$table table. Error: $check->Msg_text<br />"; 
    49                                 $problems["{$wpdb->prefix}$table"] = $check->Msg_text; 
     60                                echo "<br />&nbsp;&nbsp;&nbsp;&nbsp;Failed to repair the $table table. Error: $check->Msg_text<br />"; 
     61                                $problems["$table"] = $check->Msg_text; 
    5062                                $okay = false; 
    5163                        } 
    5264                } 
    5365                if ( $okay && $optimize ) { 
    54                         $check = $wpdb->get_row("ANALYZE TABLE {$wpdb->prefix}$table"); 
     66                        $check = $wpdb->get_row("ANALYZE TABLE $table"); 
    5567                        if ( 'Table is already up to date' == $check->Msg_text )  { 
    56                                 echo "<br />&nbsp;&nbsp;&nbsp;&nbsp;The {$wpdb->prefix}$table table is already optimized."; 
     68                                echo "<br />&nbsp;&nbsp;&nbsp;&nbsp;The $table table is already optimized."; 
    5769                        } else { 
    58                                 $check = $wpdb->get_row("OPTIMIZE TABLE {$wpdb->prefix}$table"); 
     70                                $check = $wpdb->get_row("OPTIMIZE TABLE $table"); 
    5971                                if ( 'OK' == $check->Msg_text || 'Table is already up to date' == $check->Msg_text ) 
    60                                         echo "<br />&nbsp;&nbsp;&nbsp;&nbsp;Sucessfully optimized the {$wpdb->prefix}$table table."; 
     72                                        echo "<br />&nbsp;&nbsp;&nbsp;&nbsp;Successfully optimized the $table table."; 
    6173                                else 
    62                                         echo "<br />&nbsp;&nbsp;&nbsp;&nbsp;Failed to optimize the {$wpdb->prefix}$table table. Error: $check->Msg_text"; 
     74                                        echo "<br />&nbsp;&nbsp;&nbsp;&nbsp;Failed to optimize the $table table. Error: $check->Msg_text"; 
    6375                        } 
    6476                } 
    6577                echo '</p>';