WordPress.org

Make WordPress Core

Ticket #10487: meta_upgrade.diff

File meta_upgrade.diff, 1.3 KB (added by scribu, 12 years ago)

code to migrate data to new table

  • wp-admin/includes/upgrade.php

     
    345345        if ( $wp_current_db_version < 10360 )
    346346                upgrade_280();
    347347
     348        if ( $wp_current_db_version < 11549 )
     349                upgrade_290();
     350
    348351        maybe_disable_automattic_widgets();
    349352
    350353        update_option( 'db_version', $wp_db_version );
     
    980983                populate_roles_280();
    981984}
    982985
     986/**
     987 * Execute changes made in WordPress 2.9.
     988 *
     989 * @since 2.9.0
     990 */
     991function upgrade_290() {
     992        migrate_old_meta('post');
     993}
    983994
     995
    984996// The functions we use to actually do stuff
    985997
    986998// General
    987999
    9881000/**
     1001 * Migrate data from wp_*meta to wp_meta
     1002 *
     1003 * @since 2.9.0
     1004 */
     1005function migrate_old_meta($type = 'post') {
     1006        register_meta_type($type);
     1007
     1008        global $wpdb;
     1009
     1010        $type = $wpdb->escape($type);
     1011        $id_column = $type . '_id';
     1012        $table_name = $wpdb->prefix . $type . 'meta';
     1013
     1014        $wpdb->query("
     1015                INSERT INTO $wpdb->meta (object_id, meta_type, meta_key, meta_value)
     1016                SELECT $id_column as object_id, '$type' as meta_type, meta_key, meta_value
     1017                FROM $table_name
     1018        ");
     1019
     1020        $wpdb->query('DROP TABLE ' . $table_name);
     1021}
     1022
     1023/**
    9891024 * {@internal Missing Short Description}}
    9901025 *
    9911026 * {@internal Missing Long Description}}