WordPress.org

Make WordPress Core

Changeset 5553


Ignore:
Timestamp:
05/26/2007 06:54:16 PM (15 years ago)
Author:
ryan
Message:

Update cat2tag converter. Some term API tweaks. see #4189

Location:
trunk
Files:
5 edited

Legend:

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

    r5390 r5553  
    1717        global $wpdb;
    1818       
    19         $this->all_categories = $wpdb->get_results("SELECT * FROM $wpdb->categories WHERE (type & ~ " . TAXONOMY_TAG . ") != 0 AND category_count > 0 ORDER BY cat_name ASC");
     19        $this->all_categories = get_categories('get=all');
    2020    }
    2121   
     
    4141        print '<ul style="list-style:none">';
    4242       
    43         $hier = _get_category_hierarchy();
     43        $hier = _get_term_hierarchy('category');
    4444       
    4545        foreach ($this->all_categories as $category) {
    46             if ((int) $category->category_parent == 0) {
    47                 print '<li><label><input type="checkbox" name="cats_to_convert[]" value="' . intval($category->cat_ID) . '" /> ' . $category->cat_name . ' (' . $category->category_count . ')</label>';
    48                
    49                 if (isset($hier[$category->cat_ID])) {
     46            if ((int) $category->parent == 0) {
     47                print '<li><label><input type="checkbox" name="cats_to_convert[]" value="' . intval($category->term_id) . '" /> ' . $category->name . ' (' . $category->count . ')</label>';
     48               
     49                if (isset($hier[$category->term_id])) {
    5050                    $this->_category_children($category, $hier);
    5151                }
     
    6464        print '<ul style="list-style:none">';
    6565       
    66         foreach ($hier[$parent->cat_ID] as $child_id) {
     66        foreach ($hier[$parent->term_id] as $child_id) {
    6767            $child =& get_category($child_id);
    6868           
    69             print '<li><label><input type="checkbox" name="cats_to_convert[]" value="' . intval($child->cat_ID) . '" /> ' . $child->cat_name . ' (' . $child->category_count . ')</label>';
    70            
    71             if (isset($hier[$child->cat_ID])) {
     69            print '<li><label><input type="checkbox" name="cats_to_convert[]" value="' . intval($child->term_id) . '" /> ' . $child->name . ' (' . $child->count . ')</label>';
     70           
     71            if (isset($hier[$child->term_id])) {
    7272                $this->_category_children($child, $hier);
    7373            }
     
    8484        $cat_id = (int) $cat_id;
    8585       
    86         $maybe_exists = $wpdb->get_results("SELECT cat_ID from $wpdb->categories WHERE cat_ID = '$cat_id'");
    87        
    88         if (count($maybe_exists) > 0) {
     86        $maybe_exists = category_exists($cat_id);
     87       
     88        if ( $maybe_exists ) {
    8989            return true;
    9090        } else {
     
    102102        }
    103103       
    104         $this->categories_to_convert = $_POST['cats_to_convert'];
    105         $hier = _get_category_hierarchy();
     104       
     105        if ( empty($this->categories_to_convert) )
     106            $this->categories_to_convert = $_POST['cats_to_convert'];
     107        $hier = _get_term_hierarchy('category');
    106108       
    107109        print '<ul>';
     
    117119                $category =& get_category($cat_id);
    118120               
    119                 if ($category->link_count > 0) {
    120                     $type = $category->type | TAXONOMY_TAG;
    121                 } else {
    122                     $type = TAXONOMY_TAG;
    123                 }
    124                
    125121                // Set the category itself to $type from above
    126                 $wpdb->query("UPDATE $wpdb->categories SET type = '$type' WHERE cat_ID = '{$category->cat_ID}'");
    127                
    128                 // Set relationships in post2cat to 'tag', category_count becomes tag_count
    129                 $wpdb->query("UPDATE $wpdb->post2cat SET rel_type = 'tag' WHERE category_ID = '{$category->cat_ID}'");
    130                 $wpdb->query("UPDATE $wpdb->categories SET tag_count = '{$category->category_count}', category_count = '0' WHERE cat_ID = '{$category->cat_ID}'");
     122                $wpdb->query("UPDATE $wpdb->term_taxonomy SET taxonomy = '$type' WHERE term_id = '{$category->term_id}' AND taxonomy = 'category'");
    131123               
    132124                // Set all parents to 0 (root-level) if their parent was the converted tag
    133                 $wpdb->query("UPDATE $wpdb->categories SET category_parent = 0 WHERE category_parent = '{$category->cat_ID}'");
     125                $wpdb->query("UPDATE $wpdb->term_taxonomy SET parent = 0 WHERE parent = '{$category->term_id}' AND taxonomy = 'category'");
    134126               
    135127                // Clean the cache
    136                 clean_category_cache($category->cat_ID);
     128                clean_category_cache($category->term_id);
    137129               
    138130                _e('Converted successfully.');
     
    161153    function convert_all() {
    162154        global $wpdb;
    163        
    164         $cats = $wpdb->get_results("SELECT * FROM $wpdb->categories WHERE (type & ~ " . TAXONOMY_TAG . ") != 0 AND category_count > 0");
    165        
    166         $_POST['cats_to_convert'] = array();
    167        
    168         foreach ($cats as $cat) {
    169             $_POST['cats_to_convert'][] = $cat->cat_ID;
    170         }
    171        
    172         $this->convert_them();
     155
     156        $wpdb->query("UPDATE $wpdb->term_taxonomy SET taxonomy = '$type', parent = 0 WHERE taxonomy = 'category'");
     157        clean_category_cache($category->term_id);
    173158    }
    174159   
  • trunk/wp-admin/includes/template.php

    r5543 r5553  
    9999    }
    100100
    101     $cats = get_categories("child_of=$parent&hide_empty=0&get=ids");
     101    $cats = get_categories("child_of=$parent&hide_empty=0&fields=ids");
    102102    $result = array ();
    103103
  • trunk/wp-includes/category.php

    r5534 r5553  
    55
    66    if ( ! $cat_ids = wp_cache_get('all_category_ids', 'category') ) {
    7         $cat_ids = get_terms('category', 'get=ids&hierarchical=0&hide_empty=0');
     7        $cat_ids = get_terms('category', 'fields=ids&get=all');
    88        wp_cache_add('all_category_ids', $cat_ids, 'category');
    99    }
  • trunk/wp-includes/post.php

    r5529 r5553  
    448448    $post_id = (int) $post_id;
    449449
    450     $cats = get_object_terms($post_id, 'category', 'get=ids');
     450    $cats = get_object_terms($post_id, 'category', 'get=fields');
    451451    return $cats;
    452452}
  • trunk/wp-includes/taxonomy.php

    r5552 r5553  
    137137
    138138    foreach ( (array) $objects as $object ) {
    139         $terms = get_object_terms($object, $taxonomy, 'get=ids');
     139        $terms = get_object_terms($object, $taxonomy, 'fields=ids');
    140140        if ( 1 == count($terms) && isset($default) )
    141141            $terms = array($default);
     
    320320    $object_ids = ($single_object = !is_array($object_id)) ? array($object_id) : $object_id;
    321321
    322     $defaults = array('orderby' => 'name', 'order' => 'ASC', 'get' => 'everything');
     322    $defaults = array('orderby' => 'name', 'order' => 'ASC', 'fields' => 'all');
    323323    $args = wp_parse_args( $args, $defaults );
    324324    extract($args);
     
    332332    $object_ids = implode(', ', $object_ids);
    333333
    334     if ( 'everything' == $get )
     334    if ( 'all' == $fields )
    335335        $select_this = 't.*';
    336     else if ( 'ids' == $get )
     336    else if ( 'ids' == $fields )
    337337        $select_this = 't.term_id';
    338338
    339339    $query = "SELECT $select_this FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN $wpdb->term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ($taxonomies) AND tr.object_id IN ($object_ids) ORDER BY $orderby $order";
    340340
    341     if ( 'everything' == $get )
     341    if ( 'all' == $fields )
    342342        $taxonomy_data = $wpdb->get_results($query);
    343     else if ( 'ids' == $get )
     343    else if ( 'ids' == $fields )
    344344        $taxonomy_data = $wpdb->get_col($query);
    345345
     
    380380    $defaults = array('orderby' => 'name', 'order' => 'ASC',
    381381        'hide_empty' => true, 'exclude' => '', 'include' => '',
    382         'number' => '', 'get' => 'everything', 'slug' => '', 'parent' => '',
    383         'hierarchical' => true, 'child_of' => 0);
     382        'number' => '', 'fields' => 'all', 'slug' => '', 'parent' => '',
     383        'hierarchical' => true, 'child_of' => 0, 'get' => '');
    384384    $args = wp_parse_args( $args, $defaults );
    385385    $args['number'] = (int) $args['number'];
     
    387387        $args['child_of'] = 0;
    388388        $args['hierarchical'] = false;
    389     } else {
    390         $tax = get_taxonomy($taxonomy);
    391         if ( !$tax['hierarchical'] ) {
    392             $args['child_of'] = 0;
    393             $args['hierarchical'] = false; 
    394         }
     389    } else if ( !is_taxonomy_hierarchical($taxonomies[0]) ) {
     390        $args['child_of'] = 0;
     391        $args['hierarchical'] = false;
     392    }
     393    if ( 'all' == $args['get'] ) {
     394        $args['child_of'] = 0;
     395        $args['hide_empty'] = 0;
     396        $args['hierarchical'] = false;
    395397    }
    396398    extract($args);
     
    464466        $number = '';
    465467
    466     if ( 'everything' == $get )
     468    if ( 'all' == $fields )
    467469        $select_this = 't.*, tt.*';
    468     else if ( 'ids' == $get )
     470    else if ( 'ids' == $fields )
    469471        $select_this = 't.term_id';
    470472
    471473    $query = "SELECT $select_this FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy IN ($in_taxonomies) $where ORDER BY $orderby $order $number";
    472474
    473     if ( 'everything' == $get )
     475    if ( 'all' == $fields )
    474476        $terms = $wpdb->get_results($query);
    475     else if ( 'ids' == $get )
     477    else if ( 'ids' == $fields )
    476478        $terms = $wpdb->get_col($query);
    477479
Note: See TracChangeset for help on using the changeset viewer.