Ticket #12083: global_tables.diff
File global_tables.diff, 12.1 KB (added by , 15 years ago) |
---|
-
wp-admin/maint/repair.php
31 31 32 32 $okay = true; 33 33 34 $tables = array_merge( $wpdb->tables, is_multisite() ? $wpdb->global_tables : array( 'users', 'usermeta' ) ); 35 $prefix = $wpdb->prefix; 36 if ( is_multisite() && ! defined('MULTISITE') ) // _1 to get MU-era main blog 37 $prefix .= '_1'; 38 34 $tables = $wpdb->tables( 'all', true ); 39 35 // Loop over the WP tables, checking and repairing as needed. 40 36 foreach ( $tables as $table ) { 41 if ( in_array( $table, $wpdb->old_tables ) ) 42 continue; 43 44 $check = $wpdb->get_row("CHECK TABLE {$prefix}$table"); 37 $check = $wpdb->get_row("CHECK TABLE $table"); 45 38 if ( 'OK' == $check->Msg_text ) { 46 echo "<p>The {$prefix}$table table is okay.";39 echo "<p>The $table table is okay."; 47 40 } else { 48 echo "<p>The {$prefix}$table table is not okay. It is reporting the following error: <code>$check->Msg_text</code>. WordPress will attempt to repair this table…";49 $repair = $wpdb->get_row("REPAIR TABLE {$prefix}$table");41 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…"; 42 $repair = $wpdb->get_row("REPAIR TABLE $table"); 50 43 if ( 'OK' == $check->Msg_text ) { 51 echo "<br /> Successfully repaired the {$prefix}$table table.";44 echo "<br /> Successfully repaired the $table table."; 52 45 } else { 53 echo "<br /> Failed to repair the {prefix}$table table. Error: $check->Msg_text<br />";54 $problems[" {$prefix}$table"] = $check->Msg_text;46 echo "<br /> Failed to repair the $table table. Error: $check->Msg_text<br />"; 47 $problems["$table"] = $check->Msg_text; 55 48 $okay = false; 56 49 } 57 50 } 58 51 if ( $okay && $optimize ) { 59 $check = $wpdb->get_row("ANALYZE TABLE {$prefix}$table");52 $check = $wpdb->get_row("ANALYZE TABLE $table"); 60 53 if ( 'Table is already up to date' == $check->Msg_text ) { 61 echo "<br /> The {$prefix}$table table is already optimized.";54 echo "<br /> The $table table is already optimized."; 62 55 } else { 63 $check = $wpdb->get_row("OPTIMIZE TABLE {$prefix}$table");56 $check = $wpdb->get_row("OPTIMIZE TABLE $table"); 64 57 if ( 'OK' == $check->Msg_text || 'Table is already up to date' == $check->Msg_text ) 65 echo "<br /> Successfully optimized the {$prefix}$table table.";58 echo "<br /> Successfully optimized the $table table."; 66 59 else 67 echo "<br /> Failed to optimize the {$prefix}$table table. Error: $check->Msg_text";60 echo "<br /> Failed to optimize the $table table. Error: $check->Msg_text"; 68 61 } 69 62 } 70 63 echo '</p>'; -
wp-includes/deprecated.php
1 1 <?php 2 2 /** 3 3 * Deprecated functions from past WordPress versions. You shouldn't use these 4 * globals and functions and look for the alternatives instead. The functions5 * and globals will beremoved in a later version.4 * functions and look for the alternatives instead. The functions will be 5 * removed in a later version. 6 6 * 7 7 * @package WordPress 8 8 * @subpackage Deprecated 9 9 */ 10 10 11 11 /* 12 * Deprecated global variables.13 */14 15 /**16 * The name of the Posts table17 * @global string $tableposts18 * @deprecated Use $wpdb->posts19 */20 $tableposts = $wpdb->posts;21 22 /**23 * The name of the Users table24 * @global string $tableusers25 * @deprecated Use $wpdb->users26 */27 $tableusers = $wpdb->users;28 29 /**30 * The name of the Categories table31 * @global string $tablecategories32 * @deprecated Use $wpdb->categories33 */34 $tablecategories = $wpdb->categories;35 36 /**37 * The name of the post to category table38 * @global string $tablepost2cat39 * @deprecated Use $wpdb->post2cat;40 */41 $tablepost2cat = $wpdb->post2cat;42 43 /**44 * The name of the comments table45 * @global string $tablecomments46 * @deprecated Use $wpdb->comments;47 */48 $tablecomments = $wpdb->comments;49 50 /**51 * The name of the links table52 * @global string $tablelinks53 * @deprecated Use $wpdb->links;54 */55 $tablelinks = $wpdb->links;56 57 /**58 * @global string $tablelinkcategories59 * @deprecated Not used anymore;60 */61 $tablelinkcategories = 'linkcategories_is_gone';62 63 /**64 * The name of the options table65 * @global string $tableoptions66 * @deprecated Use $wpdb->options;67 */68 $tableoptions = $wpdb->options;69 70 /**71 * The name of the postmeta table72 * @global string $tablepostmeta73 * @deprecated Use $wpdb->postmeta;74 */75 $tablepostmeta = $wpdb->postmeta;76 77 /*78 12 * Deprecated functions come here to die. 79 13 */ 80 14 -
wp-includes/functions.php
1827 1827 $tables = $wpdb->get_col('SHOW TABLES'); 1828 1828 $wpdb->suppress_errors( $suppress ); 1829 1829 1830 $wp_tables = $wpdb->tables( 'all', true ); 1830 1831 // Loop over the WP tables. If none exist, then scratch install is allowed. 1831 1832 // If one or more exist, suggest table repair since we got here because the options 1832 1833 // table could not be accessed. 1833 foreach ( $wpdb->tables as $table) {1834 foreach ( $wp_tables as $table ) { 1834 1835 // If one of the WP tables exist, then we are in an insane state. 1835 if ( in_array( $wpdb->prefix . $table, $tables) ) {1836 if ( in_array( $table, $tables ) ) { 1836 1837 // If visiting repair.php, return true and let it take over. 1837 1838 if ( defined('WP_REPAIRING') ) 1838 1839 return true; -
wp-includes/wp-db.php
137 137 var $ready = false; 138 138 var $blogid = 0; 139 139 var $siteid = 0; 140 var $blogs;141 var $signups;142 var $site;143 var $sitemeta;144 var $sitecategories;145 var $global_tables = array('blogs', 'signups', 'site', 'sitemeta', 'users', 'usermeta', 'sitecategories', 'registration_log', 'blog_versions');146 140 147 141 /** 148 142 * WordPress Posts table … … 163 157 var $users; 164 158 165 159 /** 166 * WordPress Categories table167 *168 * @since 1.5.0169 * @access public170 * @var string171 */172 var $categories;173 174 /**175 * WordPress Post to Category table176 *177 * @since 1.5.0178 * @access public179 * @var string180 */181 var $post2cat;182 183 /**184 160 * WordPress Comments table 185 161 * 186 162 * @since 1.5.0 … … 262 238 var $term_relationships; 263 239 264 240 /** 265 * List of WordPress tables241 * List of WordPress per-blog tables 266 242 * 267 243 * @since {@internal Version Unknown}} 268 244 * @access private 245 * @see wpdb::tables() 269 246 * @var array 270 247 */ 271 var $tables = array( 'posts', 'categories', 'post2cat', 'comments', 'links', 'link2cat', 'options',272 'postmeta', 'terms', 'term_taxonomy', 'term_relationships', 'commentmeta');248 var $tables = array( 'posts', 'comments', 'links', 'options', 'postmeta', 249 'terms', 'term_taxonomy', 'term_relationships', 'commentmeta' ); 273 250 274 251 /** 275 252 * List of deprecated WordPress tables 276 253 * 277 254 * @since 2.9.0 278 255 * @access private 256 * @see wpdb::tables() 279 257 * @var array 280 258 */ 281 var $old_tables = array( 'categories', 'post2cat', 'link2cat');259 var $old_tables = array( 'categories', 'post2cat', 'link2cat' ); 282 260 261 /** 262 * Multisite Blogs table 263 * 264 * @since 3.0.0 265 * @access public 266 * @var string 267 */ 268 var $blogs; 283 269 284 270 /** 285 * Format specifiers for DB columns. Columns not listed here default to %s. Initialized in wp-settings.php.271 * Multisite Signups table 286 272 * 273 * @since 3.0.0 274 * @access public 275 * @var string 276 */ 277 var $signups; 278 279 /** 280 * Multisite Sites table 281 * 282 * @since 3.0.0 283 * @access public 284 * @var string 285 */ 286 var $site; 287 288 /** 289 * Multisite Site Metadata table 290 * 291 * @since 3.0.0 292 * @access public 293 * @var string 294 */ 295 var $sitemeta; 296 297 /** 298 * Multisite Sitewide Terms table 299 * 300 * @since 3.0.0 301 * @access public 302 * @var string 303 */ 304 var $sitecategories; 305 306 /** 307 * Multisite Registration Log table 308 * 309 * @since 3.0.0 310 * @access public 311 * @var string 312 */ 313 var $registration_log; 314 315 /** 316 * Multisite Blog Versions table 317 * 318 * @since 3.0.0 319 * @access public 320 * @var string 321 */ 322 var $blog_versions; 323 324 /** 325 * List of Multisite global tables 326 * 327 * @since 3.0.0 328 * @access private 329 * @see wpdb::tables() 330 * @var array 331 */ 332 var $ms_tables = array( 'blogs', 'signups', 'site', 'sitemeta', 333 'sitecategories', 'registration_log', 'blog_versions' ); 334 335 /** 336 * List of WordPress global tables 337 * 338 * @since 3.0.0 339 * @access private 340 * @see wpdb::tables() 341 * @var array 342 */ 343 var $global_tables = array( 'users', 'usermeta' ); 344 345 /** 346 * Format specifiers for DB columns. Columns not listed here default to %s. Initialized in wp-settings.php. 347 * 287 348 * Keys are colmn names, values are format types: 'ID' => '%d' 288 349 * 289 350 * @since 2.8.0 290 351 * @see wpdb:prepare() 291 352 * @see wpdb:insert() 292 353 * @see wpdb:update() 354 * @see wp_set_wpdb_vars() 293 355 * @access public 294 356 * @var array 295 357 */ … … 439 501 * @param string $prefix Alphanumeric name for the new prefix. 440 502 * @return string|WP_Error Old prefix or WP_Error on error 441 503 */ 442 function set_prefix( $prefix) {504 function set_prefix( $prefix ) { 443 505 444 506 if ( preg_match('|[^a-z0-9_]|i', $prefix) ) 445 507 return new WP_Error('invalid_db_prefix', /*WP_I18N_DB_BAD_PREFIX*/'Invalid database prefix'/*/WP_I18N_DB_BAD_PREFIX*/); … … 452 514 if ( isset( $this->base_prefix ) ) 453 515 $old_prefix = $this->base_prefix; 454 516 $this->base_prefix = $prefix; 455 foreach ( $this-> global_tablesas $table )517 foreach ( $this->tables( 'global' ) as $table ) 456 518 $this->$table = $prefix . $table; 457 519 458 if ( defined('VHOST') && empty( $this->blogid) )520 if ( defined('VHOST') && empty( $this->blogid ) ) 459 521 return $old_prefix; 460 522 461 523 $this->prefix = $this->get_blog_prefix( $this->blogid ); 462 524 463 foreach ( (array) $this->tables as $table )525 foreach ( (array) $this->tables( 'blog' ) as $table ) 464 526 $this->$table = $this->prefix . $table; 465 527 528 foreach ( (array) $this->tables( 'old' ) as $table ) 529 $this->$table = $this->prefix . $table; 530 466 531 if ( defined('CUSTOM_USER_TABLE') ) 467 532 $this->users = CUSTOM_USER_TABLE; 468 533 … … 481 546 482 547 $this->prefix = $this->get_blog_prefix( $this->blogid ); 483 548 484 foreach ( $this->tables as $table )549 foreach ( $this->tables( 'blog' ) as $table ) 485 550 $this->$table = $this->prefix . $table; 486 551 552 foreach ( $this->tables( 'old' ) as $table ) 553 $this->$table = $this->prefix . $table; 554 487 555 return $old_blog_id; 488 556 } 489 557 … … 499 567 } 500 568 501 569 /** 570 * Returns an array of WordPress tables. 571 * 572 * @since 3.0.0 573 * @uses wpdb::tables 574 * @uses wpdb::old_tables 575 * @uses wpdb::global_tables 576 * @uses is_multisite() 577 * 578 * @param string $scope Can be all, global, blog, or old tables. Default all. 579 * All returns all global tables and the blog tables for the queried blog. 580 * @param bool $prefix Whether to include the blog prefix. Default false. 581 * @param int $blog_id The blog_id to prefix. Defaults to main blog. 582 * @return array Table names. 583 */ 584 function tables( $scope = 'all', $prefix = false, $blog_id = 0 ) { 585 switch ( $scope ) { 586 case 'old' : 587 $tables = $this->old_tables; 588 break; 589 case 'blog' : 590 $tables = $this->tables; 591 break; 592 case 'global' : 593 $tables = array_merge( $this->global_tables, $this->ms_tables ); 594 break; 595 case 'all' : 596 $tables = array_merge( $this->global_tables, $this->tables ); 597 if ( is_multisite() ) 598 $tables = array_merge( $tables, $this->ms_tables ); 599 break; 600 } 601 602 if ( $prefix ) { 603 $prefix = $this->get_blog_prefix( $blog_id ); 604 foreach ( $tables as &$table ) { 605 $table = $prefix . $table; 606 } 607 } 608 609 return $tables; 610 } 611 612 /** 502 613 * Selects a database using the current database connection. 503 614 * 504 615 * The database name will be changed based on the current database