function bp_update_db_stuff()
{
    $bp_prefix = bp_core_get_table_prefix();
    // Rename the old user activity cached table if needed.
    if ($nxtdb->get_var("SHOW TABLES LIKE '%{$bp_prefix}bp_activity_user_activity_cached%'")) {
        $nxtdb->query("RENAME TABLE {$bp_prefix}bp_activity_user_activity_cached TO {$bp->activity->table_name}");
    }
    // Rename fields from pre BP 1.2
    if ($nxtdb->get_var("SHOW TABLES LIKE '%{$bp->activity->table_name}%'")) {
        if ($nxtdb->get_var("SHOW COLUMNS FROM {$bp->activity->table_name} LIKE 'component_action'")) {
            $nxtdb->query("ALTER TABLE {$bp->activity->table_name} CHANGE component_action type varchar(75) NOT NULL");
        }
        if ($nxtdb->get_var("SHOW COLUMNS FROM {$bp->activity->table_name} LIKE 'component_name'")) {
            $nxtdb->query("ALTER TABLE {$bp->activity->table_name} CHANGE component_name component varchar(75) NOT NULL");
        }
    }
    // On first installation - record all existing blogs in the system.
    if (!(int) $bp->site_options['bp-blogs-first-install']) {
        bp_blogs_record_existing_blogs();
        bp_update_option('bp-blogs-first-install', 1);
    }
    if (is_multisite()) {
        bp_core_add_illegal_names();
    }
    // Update and remove the message threads table if it exists
    if ($nxtdb->get_var("SHOW TABLES LIKE '%{$bp_prefix}bp_messages_threads%'")) {
        $update = BP_Messages_Thread::update_tables();
        if ($update) {
            $nxtdb->query("DROP TABLE {$bp_prefix}bp_messages_threads");
        }
    }
}
Example #2
0
function bp_core_install()
{
    global $wpdb, $bp;
    if (!empty($wpdb->charset)) {
        $charset_collate = "DEFAULT CHARACTER SET {$wpdb->charset}";
    }
    $sql[] = "CREATE TABLE {$bp->core->table_name_notifications} (\n\t\t  \t\tid bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,\n\t\t\t\tuser_id bigint(20) NOT NULL,\n\t\t\t\titem_id bigint(20) NOT NULL,\n\t\t\t\tsecondary_item_id bigint(20),\n\t\t  \t\tcomponent_name varchar(75) NOT NULL,\n\t\t\t\tcomponent_action varchar(75) NOT NULL,\n\t\t  \t\tdate_notified datetime NOT NULL,\n\t\t\t\tis_new bool NOT NULL DEFAULT 0,\n\t\t\t    KEY item_id (item_id),\n\t\t\t\tKEY secondary_item_id (secondary_item_id),\n\t\t\t\tKEY user_id (user_id),\n\t\t\t\tKEY is_new (is_new),\n\t\t\t\tKEY component_name (component_name),\n\t\t \t   \tKEY component_action (component_action),\n\t\t\t\tKEY useritem (user_id, is_new)\n\t\t\t   ) {$charset_collate};";
    require_once ABSPATH . 'wp-admin/upgrade-functions.php';
    dbDelta($sql);
    /* Add names of root components to the banned blog list to avoid conflicts */
    bp_core_add_illegal_names();
    // dbDelta won't change character sets, so we need to do this seperately.
    // This will only be in here pre v1.0
    $wpdb->query($wpdb->prepare("ALTER TABLE {$bp->core->table_name_notifications} DEFAULT CHARACTER SET %s", $wpdb->charset));
    update_site_option('bp-core-db-version', BP_CORE_DB_VERSION);
}