Make WordPress Core


Ignore:
Timestamp:
05/05/2004 08:00:13 AM (23 years ago)
Author:
saxmatt
Message:

Upgrades should run faster now.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/upgrade-functions.php

    r1227 r1229  
    554554        }
    555555        // Get the title and ID of every post, post_name to check if it already has a value
    556         $posts = $wpdb->get_results("SELECT ID, post_title, post_name FROM $tableposts");
    557         foreach($posts as $post) {
    558                 if ('' == $post->post_name) {
    559                         $newtitle = sanitize_title($post->post_title);
    560                         $wpdb->query("UPDATE $tableposts SET post_name = '$newtitle' WHERE ID = '$post->ID'");
     556        $posts = $wpdb->get_results("SELECT ID, post_title, post_name FROM $tableposts WHERE post_name = ''");
     557        if ($posts) {
     558                foreach($posts as $post) {
     559                        if ('' == $post->post_name) {
     560                                $newtitle = sanitize_title($post->post_title);
     561                                $wpdb->query("UPDATE $tableposts SET post_name = '$newtitle' WHERE ID = '$post->ID'");
     562                        }
    561563                }
    562564        }
    … …  
    624626                )
    625627                ");
    626         $allposts = $wpdb->get_results("SELECT ID, post_category FROM $tableposts");
    627         foreach ($allposts as $post) {
    628                 // Check to see if it's already been imported
    629                 $cat = $wpdb->get_row("SELECT * FROM $tablepost2cat WHERE post_id = $post->ID AND category_id = $post->post_category");
    630                 if (!$cat && 0 != $post->post_category) { // If there's no result
    631                         $wpdb->query("
    632                                 INSERT INTO $tablepost2cat
    633                                 (post_id, category_id)
    634                                 VALUES
    635                                 ('$post->ID', '$post->post_category')
    636                                 ");
    637                 }
    638         }
     628
     629        $done_ids = $wpdb->get_results("SELECT DISTINCT post_id FROM $tablepost2cat");
     630        if ($done_ids) :
     631                foreach ($done_ids as $done_id) :
     632                        $done_posts[] = $done_id->post_id;
     633                endforeach;
     634                $catwhere = ' AND ID NOT IN (' . implode(',', $done_posts) . ')';
     635        else:
     636                $catwhere = '';
     637        endif;
     638       
     639        $allposts = $wpdb->get_results("SELECT ID, post_category FROM $tableposts WHERE post_category != '0' $catwhere");
     640        if ($allposts) :
     641                foreach ($allposts as $post) {
     642                        // Check to see if it's already been imported
     643                        $cat = $wpdb->get_row("SELECT * FROM $tablepost2cat WHERE post_id = $post->ID AND category_id = $post->post_category");
     644                        if (!$cat && 0 != $post->post_category) { // If there's no result
     645                                $wpdb->query("
     646                                        INSERT INTO $tablepost2cat
     647                                        (post_id, category_id)
     648                                        VALUES
     649                                        ('$post->ID', '$post->post_category')
     650                                        ");
     651                        }
     652                }
     653        endif;
    639654}
    640655
Note: See TracChangeset for help on using the changeset viewer.