From 7a3fc7d36c1e54f1848d4bc93b51f6663c48b223 Mon Sep 17 00:00:00 2001 From: ryan Date: Fri, 21 Oct 2011 22:16:33 +0000 Subject: [PATCH] Don't use unbounded SHOW TABLES in is_blog_installed(). Do a more targeted DESCRIBE loop over the blog table list. fixes #19026 git-svn-id: http://svn.automattic.com/wordpress/trunk@19039 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/functions.php | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/wp-includes/functions.php b/wp-includes/functions.php index cf9c11ed9..2c315baa4 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -1899,32 +1899,35 @@ function is_blog_installed() { if ( $installed ) return true; - $suppress = $wpdb->suppress_errors(); - $tables = $wpdb->get_col('SHOW TABLES'); - $wpdb->suppress_errors( $suppress ); + // If visiting repair.php, return true and let it take over. + if ( defined( 'WP_REPAIRING' ) ) + return true; + + $suppress = $wpdb->suppress_errors(); - $wp_tables = $wpdb->tables(); // Loop over the WP tables. If none exist, then scratch install is allowed. // If one or more exist, suggest table repair since we got here because the options // table could not be accessed. + $wp_tables = $wpdb->tables(); foreach ( $wp_tables as $table ) { - // If one of the WP tables exist, then we are in an insane state. - if ( in_array( $table, $tables ) ) { - // The existence of custom user tables shouldn't suggest an insane state or prevent a clean install. - if ( defined( 'CUSTOM_USER_TABLE' ) && CUSTOM_USER_TABLE == $table ) - continue; - if ( defined( 'CUSTOM_USER_META_TABLE' ) && CUSTOM_USER_META_TABLE == $table ) - continue; + // The existence of custom user tables shouldn't suggest an insane state or prevent a clean install. + if ( defined( 'CUSTOM_USER_TABLE' ) && CUSTOM_USER_TABLE == $table ) + continue; + if ( defined( 'CUSTOM_USER_META_TABLE' ) && CUSTOM_USER_META_TABLE == $table ) + continue; - // If visiting repair.php, return true and let it take over. - if ( defined('WP_REPAIRING') ) - return true; - // Die with a DB error. - $wpdb->error = sprintf( /*WP_I18N_NO_TABLES*/'One or more database tables are unavailable. The database may need to be repaired.'/*/WP_I18N_NO_TABLES*/, 'maint/repair.php?referrer=is_blog_installed' ); - dead_db(); - } + if ( ! $wpdb->get_results( "DESCRIBE $table;" ) ) + continue; + + // One or more tables exist. We are insane. + + // Die with a DB error. + $wpdb->error = sprintf( /*WP_I18N_NO_TABLES*/'One or more database tables are unavailable. The database may need to be repaired.'/*/WP_I18N_NO_TABLES*/, 'maint/repair.php?referrer=is_blog_installed' ); + dead_db(); } + $wpdb->suppress_errors( $suppress ); + wp_cache_set( 'is_blog_installed', false ); return false;