Changeset 3570 for trunk/wp-admin/upgrade-functions.php
- Timestamp:
- 02/27/2006 04:57:30 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/upgrade-functions.php
r3548 r3570 2 2 3 3 require_once(ABSPATH . '/wp-admin/admin-functions.php'); 4 require_once(ABSPATH . '/wp-admin/admin-db.php'); 4 5 require_once(ABSPATH . '/wp-admin/upgrade-schema.php'); 5 6 // Functions to be called in install and upgrade scripts … … 34 35 upgrade_160(); 35 36 36 if ( $wp_current_db_version < 35 48)37 if ( $wp_current_db_version < 3570 ) 37 38 upgrade_210(); 38 39 … … 366 367 foreach ( $posts as $post ) 367 368 wp_schedule_event(mysql2date('U', $post->post_date), 'once', 'publish_future_post', $post->ID); 369 } 370 if ( $wp_current_db_version < 3570 ) { 371 // Create categories for link categories if a category with the same 372 // name doesn't exist. Create a map of link cat IDs to cat IDs. 373 $link_cats = $wpdb->get_results("SELECT cat_id, cat_name FROM $wpdb->linkcategories"); 374 foreach ( $link_cats as $link_cat) { 375 if ( $cat_id = category_exists($link_cat->cat_name) ) { 376 $link_cat_id_map[$link_cat->cat_id] = $cat_id; 377 $default_link_cat = $cat_id; 378 } else { 379 $link_cat_id_map[$link_cat->cat_id] = wp_create_category($link_cat->cat_name); 380 $default_link_cat = $link_cat_id_map[$link_cat->cat_id]; 381 } 382 } 383 384 // Associate links to cats. 385 $links = $wpdb->get_results("SELECT link_id, link_category FROM $wpdb->links"); 386 foreach ( $links as $link ) { 387 $link_cat = $link_cat_id_map[$link->link_category]; 388 $cat = $wpdb->get_row("SELECT * FROM $wpdb->link2cat WHERE link_id = '$link->link_id' AND category_id = '$link_cat'"); 389 if (!$cat && 0 != $link->link_category) { 390 $wpdb->query("INSERT INTO $wpdb->link2cat (link_id, category_id) 391 VALUES ('$link->link_id', '$link_cat')"); 392 } 393 } 394 395 // Set default to the last category we grabbed during the upgrade loop. 396 update_option('default_link_category', $default_link_cat); 397 398 // Count links per category. 399 if ( 0 == $wpdb->get_var("SELECT SUM(link_count) FROM $wpdb->categories") ) { 400 $categories = $wpdb->get_col("SELECT cat_ID FROM $wpdb->categories"); 401 foreach ( $categories as $cat_id ) { 402 $count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->link2cat, $wpdb->links WHERE $wpdb->links.link_id = $wpdb->link2cat.link_id AND category_id = '$cat_id'"); 403 $wpdb->query("UPDATE $wpdb->categories SET link_count = '$count' WHERE cat_ID = '$cat_id'"); 404 } 405 } 368 406 } 369 407 }
Note: See TracChangeset
for help on using the changeset viewer.