Changeset 5229

Show
Ignore:
Timestamp:
04/10/07 16:57:21 (2 years ago)
Author:
rob1n
Message:

Use own category_exists() function, and only list categories to convert. fixes #4107

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/wp-admin/import/wp-cat2tag.php

    r5218 r5229  
    1515     
    1616    function populate_all_categories() { 
    17         $this->all_categories =& get_categories('hide_empty=0&hierarchal=0'); 
     17        global $wpdb; 
     18         
     19        $this->all_categories = $wpdb->get_results("SELECT * FROM $wpdb->categories WHERE (type & ~ " . TAXONOMY_TAG . ") != 0 ORDER BY cat_name ASC"); 
    1820    } 
    1921     
     
    7173    } 
    7274     
     75    function _category_exists($cat_id) { 
     76        global $wpdb; 
     77         
     78        $cat_id = (int) $cat_id; 
     79         
     80        $maybe_exists = $wpdb->get_results("SELECT cat_ID from $wpdb->categories WHERE cat_ID = '$cat_id'"); 
     81         
     82        if (count($maybe_exists) > 0) { 
     83            return true; 
     84        } else { 
     85            return false; 
     86        } 
     87    } 
     88     
    7389    function convert_them() { 
    7490        global $wpdb; 
     
    90106            print '<li>' . __('Converting category') . ' #' . $cat_id . '... '; 
    91107             
    92             if (!category_exists($cat_id)) { 
     108            if (!$this->_category_exists($cat_id)) { 
    93109                _e('Category doesn\'t exist!'); 
    94110            } else { 
     
    101117                } 
    102118                 
     119                // Set the category itself to $type from above 
    103120                $wpdb->query("UPDATE $wpdb->categories SET type = '$type' WHERE cat_ID = '{$category->cat_ID}'"); 
    104121                 
    105                 $wpdb->query("UPDATE $wpdb->post2cat SET rel_type = 'tag' WHERE cat_ID = '{$category->cat_ID}'"); 
     122                // Set relationships in post2cat to 'tag', category_count becomes tag_count 
     123                $wpdb->query("UPDATE $wpdb->post2cat SET rel_type = 'tag' WHERE category_ID = '{$category->cat_ID}'"); 
    106124                $wpdb->query("UPDATE $wpdb->categories SET tag_count = '{$category->category_count}', category_count = '0' WHERE cat_ID = '{$category->cat_ID}'"); 
     125                 
     126                // Set all parents to 0 (root-level) if their parent was the converted tag 
     127                $wpdb->query("UPDATE $wpdb->categories SET category_parent = 0 WHERE category_parent = '{$category->cat_ID}'"); 
     128                 
     129                // Clean the cache 
     130                clean_category_cache($category->cat_ID); 
    107131                 
    108132                _e('Converted successfully.'); 
     
    113137         
    114138        print '</ul>'; 
    115          
    116         clean_category_cache(); 
    117139    } 
    118140