Add option to optimize tables

git-svn-id: https://develop.svn.wordpress.org/trunk@12092 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2009-10-22 20:23:19 +00:00
parent df21977652
commit 9e97a77b19
1 changed files with 27 additions and 5 deletions

View File

@ -24,6 +24,13 @@ if ( !defined('WP_ALLOW_REPAIR') ) {
$problems = array(); $problems = array();
check_admin_referer('repair_db'); check_admin_referer('repair_db');
if ( 2 == $_GET['repair'] )
$optimize = true;
else
$optimize = false;
$okay = true;
// Loop over the WP tables, checking and repairing as needed. // Loop over the WP tables, checking and repairing as needed.
foreach ($wpdb->tables as $table) { foreach ($wpdb->tables as $table) {
if ( in_array($table, $wpdb->old_tables) ) if ( in_array($table, $wpdb->old_tables) )
@ -31,17 +38,31 @@ if ( !defined('WP_ALLOW_REPAIR') ) {
$check = $wpdb->get_row("CHECK TABLE {$wpdb->prefix}$table"); $check = $wpdb->get_row("CHECK TABLE {$wpdb->prefix}$table");
if ( 'OK' == $check->Msg_text ) { if ( 'OK' == $check->Msg_text ) {
echo "<p>The {$wpdb->prefix}$table table is okay.</p>"; echo "<p>The {$wpdb->prefix}$table table is okay.";
} else { } else {
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;<br/>"; 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;";
$repair = $wpdb->get_row("REPAIR TABLE {$wpb->prefix}$table"); $repair = $wpdb->get_row("REPAIR TABLE {$wpb->prefix}$table");
if ( 'OK' == $check->Msg_text ) { if ( 'OK' == $check->Msg_text ) {
echo "&nbsp;&nbsp;&nbsp;&nbsp;Sucessfully repaired the {$wpb->prefix}$table table.<br />"; echo "<br />&nbsp;&nbsp;&nbsp;&nbsp;Sucessfully repaired the {$wpb->prefix}$table table.";
} else { } else {
echo "&nbsp;&nbsp;&nbsp;&nbsp;Failed to repair the {$wpdb->prefix}$table table. Error: $check->Msg_text<br />"; echo "<br />&nbsp;&nbsp;&nbsp;&nbsp;Failed to repair the {$wpdb->prefix}$table table. Error: $check->Msg_text<br />";
$problems["{$wpdb->prefix}$table"] = $check->Msg_text; $problems["{$wpdb->prefix}$table"] = $check->Msg_text;
$okay = false;
} }
} }
if ( $okay && $optimize ) {
$check = $wpdb->get_row("ANALYZE TABLE {$wpdb->prefix}$table");
if ( 'Table is already up to date' == $check->Msg_text ) {
echo "<br />&nbsp;&nbsp;&nbsp;&nbsp;The {$wpb->prefix}$table table is already optimized.";
} else {
$check = $wpdb->get_row("OPTIMIZE TABLE {$wpdb->prefix}$table");
if ( 'OK' == $check->Msg_text || 'Table is already up to date' == $check->Msg_text )
echo "<br />&nbsp;&nbsp;&nbsp;&nbsp;Sucessfully optimized the {$wpb->prefix}$table table.";
else
echo "<br />&nbsp;&nbsp;&nbsp;&nbsp;Failed to optimize the {$wpdb->prefix}$table table. Error: $check->Msg_text";
}
}
echo '</p>';
} }
if ( !empty($problems) ) { if ( !empty($problems) ) {
@ -60,9 +81,10 @@ if ( !defined('WP_ALLOW_REPAIR') ) {
_e('WordPress can automatically look for some common database problems and repair them. Repairing can take awhile, so please be patient.') _e('WordPress can automatically look for some common database problems and repair them. Repairing can take awhile, so please be patient.')
?> ?>
<p class="step"><a class="button" href="<?php echo wp_nonce_url('repair.php?repair=1', 'repair_db') ?>"><?php _e( 'Repair Database' ); ?></a></p> <p class="step"><a class="button" href="<?php echo wp_nonce_url('repair.php?repair=1', 'repair_db') ?>"><?php _e( 'Repair Database' ); ?></a></p>
<?php _e('WordPress can also attempt to optimize the database. This improves performance in some situations. Repairing and optimizing the database can take a long time and the database will be locked while optimizing.'); ?>
<p class="step"><a class="button" href="<?php echo wp_nonce_url('repair.php?repair=2', 'repair_db') ?>"><?php _e( 'Repair and Optimize Database' ); ?></a></p>
<?php <?php
} }
?> ?>
</body> </body>
</html> </html>