Make WordPress Core

Ticket #22134: 22134.patch

File 22134.patch, 7.6 KB (added by faishal, 12 years ago)
  • schema.php

     
    4545        $is_multisite = is_multisite() || ( defined( 'WP_INSTALLING_NETWORK' ) && WP_INSTALLING_NETWORK );
    4646
    4747        // Blog specific tables.
    48         $blog_tables = "CREATE TABLE $wpdb->terms (
     48        $blog_tables = "CREATE TABLE IF NOT EXISTS $wpdb->terms (
    4949 term_id bigint(20) unsigned NOT NULL auto_increment,
    5050 name varchar(200) NOT NULL default '',
    5151 slug varchar(200) NOT NULL default '',
     
    5454 UNIQUE KEY slug (slug),
    5555 KEY name (name)
    5656) $charset_collate;
    57 CREATE TABLE $wpdb->term_taxonomy (
     57CREATE TABLE IF NOT EXISTS $wpdb->term_taxonomy (
    5858 term_taxonomy_id bigint(20) unsigned NOT NULL auto_increment,
    5959 term_id bigint(20) unsigned NOT NULL default 0,
    6060 taxonomy varchar(32) NOT NULL default '',
     
    6565 UNIQUE KEY term_id_taxonomy (term_id,taxonomy),
    6666 KEY taxonomy (taxonomy)
    6767) $charset_collate;
    68 CREATE TABLE $wpdb->term_relationships (
     68CREATE TABLE IF NOT EXISTS $wpdb->term_relationships (
    6969 object_id bigint(20) unsigned NOT NULL default 0,
    7070 term_taxonomy_id bigint(20) unsigned NOT NULL default 0,
    7171 term_order int(11) NOT NULL default 0,
    7272 PRIMARY KEY  (object_id,term_taxonomy_id),
    7373 KEY term_taxonomy_id (term_taxonomy_id)
    7474) $charset_collate;
    75 CREATE TABLE $wpdb->commentmeta (
     75CREATE TABLE IF NOT EXISTS $wpdb->commentmeta (
    7676  meta_id bigint(20) unsigned NOT NULL auto_increment,
    7777  comment_id bigint(20) unsigned NOT NULL default '0',
    7878  meta_key varchar(255) default NULL,
     
    8181  KEY comment_id (comment_id),
    8282  KEY meta_key (meta_key)
    8383) $charset_collate;
    84 CREATE TABLE $wpdb->comments (
     84CREATE TABLE IF NOT EXISTS $wpdb->comments (
    8585  comment_ID bigint(20) unsigned NOT NULL auto_increment,
    8686  comment_post_ID bigint(20) unsigned NOT NULL default '0',
    8787  comment_author tinytext NOT NULL,
     
    103103  KEY comment_date_gmt (comment_date_gmt),
    104104  KEY comment_parent (comment_parent)
    105105) $charset_collate;
    106 CREATE TABLE $wpdb->links (
     106CREATE TABLE IF NOT EXISTS $wpdb->links (
    107107  link_id bigint(20) unsigned NOT NULL auto_increment,
    108108  link_url varchar(255) NOT NULL default '',
    109109  link_name varchar(255) NOT NULL default '',
     
    120120  PRIMARY KEY  (link_id),
    121121  KEY link_visible (link_visible)
    122122) $charset_collate;
    123 CREATE TABLE $wpdb->options (
     123CREATE TABLE IF NOT EXISTS $wpdb->options (
    124124  option_id bigint(20) unsigned NOT NULL auto_increment,
    125125  option_name varchar(64) NOT NULL default '',
    126126  option_value longtext NOT NULL,
     
    128128  PRIMARY KEY  (option_id),
    129129  UNIQUE KEY option_name (option_name)
    130130) $charset_collate;
    131 CREATE TABLE $wpdb->postmeta (
     131CREATE TABLE IF NOT EXISTS $wpdb->postmeta (
    132132  meta_id bigint(20) unsigned NOT NULL auto_increment,
    133133  post_id bigint(20) unsigned NOT NULL default '0',
    134134  meta_key varchar(255) default NULL,
     
    137137  KEY post_id (post_id),
    138138  KEY meta_key (meta_key)
    139139) $charset_collate;
    140 CREATE TABLE $wpdb->posts (
     140CREATE TABLE IF NOT EXISTS $wpdb->posts (
    141141  ID bigint(20) unsigned NOT NULL auto_increment,
    142142  post_author bigint(20) unsigned NOT NULL default '0',
    143143  post_date datetime NOT NULL default '0000-00-00 00:00:00',
     
    169169) $charset_collate;\n";
    170170
    171171        // Single site users table. The multisite flavor of the users table is handled below.
    172         $users_single_table = "CREATE TABLE $wpdb->users (
     172        $users_single_table = "CREATE TABLE IF NOT EXISTS $wpdb->users (
    173173  ID bigint(20) unsigned NOT NULL auto_increment,
    174174  user_login varchar(60) NOT NULL default '',
    175175  user_pass varchar(64) NOT NULL default '',
     
    186186) $charset_collate;\n";
    187187
    188188        // Multisite users table
    189         $users_multi_table = "CREATE TABLE $wpdb->users (
     189        $users_multi_table = "CREATE TABLE IF NOT EXISTS $wpdb->users (
    190190  ID bigint(20) unsigned NOT NULL auto_increment,
    191191  user_login varchar(60) NOT NULL default '',
    192192  user_pass varchar(64) NOT NULL default '',
     
    205205) $charset_collate;\n";
    206206
    207207        // usermeta
    208         $usermeta_table = "CREATE TABLE $wpdb->usermeta (
     208        $usermeta_table = "CREATE TABLE IF NOT EXISTS $wpdb->usermeta (
    209209  umeta_id bigint(20) unsigned NOT NULL auto_increment,
    210210  user_id bigint(20) unsigned NOT NULL default '0',
    211211  meta_key varchar(255) default NULL,
     
    222222                $global_tables = $users_single_table . $usermeta_table;
    223223
    224224        // Multisite global tables.
    225         $ms_global_tables = "CREATE TABLE $wpdb->blogs (
     225        $ms_global_tables = "CREATE TABLE IF NOT EXISTS $wpdb->blogs (
    226226  blog_id bigint(20) NOT NULL auto_increment,
    227227  site_id bigint(20) NOT NULL default '0',
    228228  domain varchar(200) NOT NULL default '',
     
    239239  KEY domain (domain(50),path(5)),
    240240  KEY lang_id (lang_id)
    241241) $charset_collate;
    242 CREATE TABLE $wpdb->blog_versions (
     242CREATE TABLE IF NOT EXISTS $wpdb->blog_versions (
    243243  blog_id bigint(20) NOT NULL default '0',
    244244  db_version varchar(20) NOT NULL default '',
    245245  last_updated datetime NOT NULL default '0000-00-00 00:00:00',
    246246  PRIMARY KEY  (blog_id),
    247247  KEY db_version (db_version)
    248248) $charset_collate;
    249 CREATE TABLE $wpdb->registration_log (
     249CREATE TABLE IF NOT EXISTS $wpdb->registration_log (
    250250  ID bigint(20) NOT NULL auto_increment,
    251251  email varchar(255) NOT NULL default '',
    252252  IP varchar(30) NOT NULL default '',
     
    255255  PRIMARY KEY  (ID),
    256256  KEY IP (IP)
    257257) $charset_collate;
    258 CREATE TABLE $wpdb->site (
     258CREATE TABLE IF NOT EXISTS $wpdb->site (
    259259  id bigint(20) NOT NULL auto_increment,
    260260  domain varchar(200) NOT NULL default '',
    261261  path varchar(100) NOT NULL default '',
    262262  PRIMARY KEY  (id),
    263263  KEY domain (domain,path)
    264264) $charset_collate;
    265 CREATE TABLE $wpdb->sitemeta (
     265CREATE TABLE IF NOT EXISTS $wpdb->sitemeta (
    266266  meta_id bigint(20) NOT NULL auto_increment,
    267267  site_id bigint(20) NOT NULL default '0',
    268268  meta_key varchar(255) default NULL,
     
    271271  KEY meta_key (meta_key),
    272272  KEY site_id (site_id)
    273273) $charset_collate;
    274 CREATE TABLE $wpdb->signups (
     274CREATE TABLE IF NOT EXISTS $wpdb->signups (
    275275  domain varchar(200) NOT NULL default '',
    276276  path varchar(100) NOT NULL default '',
    277277  title longtext NOT NULL,
     
    308308
    309309        if ( isset( $old_blog_id ) )
    310310                $wpdb->set_blog_id( $old_blog_id );
    311 
    312         return $queries;
     311        return $queries;
    313312}
    314313
    315314// Populate for back compat.
  • upgrade.php

     
    14811481
    14821482        // Create a tablename index for an array ($cqueries) of queries
    14831483        foreach($queries as $qry) {
    1484                 if (preg_match("|CREATE TABLE ([^ ]*)|", $qry, $matches)) {
    1485                         $cqueries[ trim( $matches[1], '`' ) ] = $qry;
    1486                         $for_update[$matches[1]] = 'Created table '.$matches[1];
     1484                if(preg_match("|CREATE TABLE IF NOT EXISTS ([^ ]*)|", $qry, $matches)){
     1485                    $cqueries[ trim( $matches[1], '`' ) ] = $qry;
     1486                    $for_update[$matches[1]] = 'Created table '.$matches[1];
     1487                }elseif (preg_match("|CREATE TABLE ([^ ]*)|", $qry, $matches)) {
     1488                    $cqueries[ trim( $matches[1], '`' ) ] = $qry;
     1489                    $for_update[$matches[1]] = 'Created table '.$matches[1];
    14871490                } else if (preg_match("|CREATE DATABASE ([^ ]*)|", $qry, $matches)) {
    14881491                        array_unshift($cqueries, $qry);
    14891492                } else if (preg_match("|INSERT INTO ([^ ]*)|", $qry, $matches)) {
     
    14961499        }
    14971500        $cqueries = apply_filters( 'dbdelta_create_queries', $cqueries );
    14981501        $iqueries = apply_filters( 'dbdelta_insert_queries', $iqueries );
    1499 
     1502       
    15001503        $global_tables = $wpdb->tables( 'global' );
    15011504        foreach ( $cqueries as $table => $qry ) {
    15021505                // Upgrade global tables only for the main site. Don't upgrade at all if DO_NOT_UPGRADE_GLOBAL_TABLES is defined.