Changeset 5553 for trunk/wp-admin/import/wp-cat2tag.php
- Timestamp:
- 05/26/2007 06:54:16 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/wp-admin/import/wp-cat2tag.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/import/wp-cat2tag.php
r5390 r5553 17 17 global $wpdb; 18 18 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'); 20 20 } 21 21 … … 41 41 print '<ul style="list-style:none">'; 42 42 43 $hier = _get_ category_hierarchy();43 $hier = _get_term_hierarchy('category'); 44 44 45 45 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])) { 50 50 $this->_category_children($category, $hier); 51 51 } … … 64 64 print '<ul style="list-style:none">'; 65 65 66 foreach ($hier[$parent-> cat_ID] as $child_id) {66 foreach ($hier[$parent->term_id] as $child_id) { 67 67 $child =& get_category($child_id); 68 68 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])) { 72 72 $this->_category_children($child, $hier); 73 73 } … … 84 84 $cat_id = (int) $cat_id; 85 85 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 ) { 89 89 return true; 90 90 } else { … … 102 102 } 103 103 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'); 106 108 107 109 print '<ul>'; … … 117 119 $category =& get_category($cat_id); 118 120 119 if ($category->link_count > 0) {120 $type = $category->type | TAXONOMY_TAG;121 } else {122 $type = TAXONOMY_TAG;123 }124 125 121 // 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'"); 131 123 132 124 // 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'"); 134 126 135 127 // Clean the cache 136 clean_category_cache($category-> cat_ID);128 clean_category_cache($category->term_id); 137 129 138 130 _e('Converted successfully.'); … … 161 153 function convert_all() { 162 154 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); 173 158 } 174 159
Note: See TracChangeset
for help on using the changeset viewer.