Make WordPress Core

Changeset 5980


Ignore:
Timestamp:
08/29/2007 10:47:07 PM (17 years ago)
Author:
ryan
Message:

Don't convert category to tag if tag of the same name already exists. fixes #4864

File:
1 edited

Legend:

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

    r5941 r5980  
    9797        global $wpdb;
    9898
    99         if (!isset($_POST['cats_to_convert']) || !is_array($_POST['cats_to_convert'])) {
     99        if ( (!isset($_POST['cats_to_convert']) || !is_array($_POST['cats_to_convert'])) && empty($this->categories_to_convert)) {
    100100            print '<div class="narrow">';
    101101            print '<p>' . sprintf(__('Uh, oh. Something didn\'t work. Please <a href="%s">try again</a>.'), 'admin.php?import=wp-cat2tag') . '</p>';
    102102            print '</div>';
     103            return;
    103104        }
    104105
     
    110111        print '<ul>';
    111112
    112         foreach ($this->categories_to_convert as $cat_id) {
     113        foreach ( (array) $this->categories_to_convert as $cat_id) {
    113114            $cat_id = (int) $cat_id;
    114115
    115             print '<li>' . __('Converting category') . ' #' . $cat_id . '... ';
     116            print '<li>' . sprintf(__('Converting category #%s ... '),  $cat_id);
    116117
    117118            if (!$this->_category_exists($cat_id)) {
     
    120121                $category =& get_category($cat_id);
    121122
     123                if ( tag_exists($wpdb->escape($category->name)) ) {
     124                    _e('Category is already a tag.');
     125                    print '</li>';
     126                    continue;
     127                }
     128
    122129                // Set the category itself to $type from above
    123130                $wpdb->query("UPDATE $wpdb->term_taxonomy SET taxonomy = 'post_tag' WHERE term_id = '{$category->term_id}' AND taxonomy = 'category'");
     
    156163        global $wpdb;
    157164
    158         $wpdb->query("UPDATE $wpdb->term_taxonomy SET taxonomy = 'post_tag', parent = 0 WHERE taxonomy = 'category'");
    159         clean_category_cache($category->term_id);
     165        $this->categories_to_convert = get_categories('fields=ids&get=all');
     166        $this->convert_them();
    160167    }
    161168
Note: See TracChangeset for help on using the changeset viewer.