--- taxonomy_switch.module.bak +++ taxonomy_switch.module @@ -173,52 +173,65 @@ function taxonomy_switch_execute($edit) { $from_vid = module_invoke('taxonomy', 'get_vocabulary', $edit['taxonomy_switch_from_vid']); $to_vid = module_invoke('taxonomy', 'get_vocabulary', $edit['taxonomy_switch_to_vid']); - $from_term = module_invoke('taxonomy', 'get_term', $edit['taxonomy_switch_from_term']); - $output = t('The term ').''.$from_term->name.''.t(' has been moved from the source vocabulary ').''.$from_vid->name.''.t(' to the target vocabulary ').''.$to_vid->name.''.'
'; - $output .= t('The term has been moved '); -// Here we could lock the tables -// db_query("LOCK TABLES {term_data} WRITE {term_hierarchy} WRITE {term_relation} WRITE {term_synonym}"); - $children = module_invoke('taxonomy', 'get_tree', $from_term->vid, $from_term->tid); - db_query('DELETE FROM {term_relation} WHERE tid1 = %d OR tid2 = %d', $from_term->tid, $from_term->tid); - db_query('DELETE FROM {term_hierarchy} WHERE tid = %d', $from_term->tid); - $ins = "vid = '". str_replace('%', '%%', db_escape_string($to_vid->vid)) ."'"; - foreach ($children as $c => $from_term_child) { - db_query('UPDATE {term_data} SET '. $ins .' WHERE tid = %d', $from_term_child->tid); - } - db_query('UPDATE {term_data} SET '. $ins .' WHERE tid = %d', $from_term->tid); -/* taxonomy_get_tree($vid, $parent = 0, $depth = -1, $max_depth = NULL) -$vid Which vocabulary to generate the tree for. -$parent The term ID under which to generate the tree. If 0, generate the tree for the entire vocabulary. -$depth Internal use only. -$max_depth The number of levels of the tree to return. Leave NULL to return all levels.*/ - switch ($edit['taxonomy_switch_to_hierarchy']) { - case 0: - $output .= t('to root level in the target vocabulary'); - db_query('INSERT INTO {term_hierarchy} (tid, parent) VALUES (%d, %d)', $from_term->tid, 0); - break; - case 1: - $to_term = module_invoke('taxonomy', 'get_term', $edit['taxonomy_switch_to_term']); - $to_term->name ? $output .= t('below the term '). '' . $to_term->name. '' : $output .= t('below the root'); - $output .= t(' in the target vocabulary'); - db_query('INSERT INTO {term_hierarchy} (tid, parent) VALUES (%d, %d)', $from_term->tid, $edit['taxonomy_switch_to_term']); - break; - case 2: - $output .= t('below the following terms in the multiple-hierarchy target vocabulary : ').'
'; - foreach ($edit['taxonomy_switch_to_term'] as $i => $to_tid) { - $to_term = module_invoke('taxonomy', 'get_term', $to_tid); - $to_term->name ? $output .= '- '.$to_term->name.'
' : $output .= '- '.t('Root').'
'; - db_query('INSERT INTO {term_hierarchy} (tid, parent) VALUES (%d, %d)', $from_term->tid, $to_term->tid); + // begin modifications - L0rne + $from_terms = array(); + if (is_array($edit['taxonomy_switch_from_term'])) { + $from_terms = $edit['taxonomy_switch_from_term']; + } else { + $from_terms[] = $edit['taxonomy_switch_from_term']; + } + foreach ($from_terms as $term) { + + $from_term = module_invoke('taxonomy', 'get_term', $term); + $output .= "

"; + $output .= t('The term ').''.$from_term->name.''.t(' has been moved from the source vocabulary ').''.$from_vid->name.''.t(' to the target vocabulary ').''.$to_vid->name.''.'
'; + $output .= t('The term has been moved '); + // Here we could lock the tables + // db_query("LOCK TABLES {term_data} WRITE {term_hierarchy} WRITE {term_relation} WRITE {term_synonym}"); + $children = module_invoke('taxonomy', 'get_tree', $from_term->vid, $from_term->tid); + db_query('DELETE FROM {term_relation} WHERE tid1 = %d OR tid2 = %d', $from_term->tid, $from_term->tid); + db_query('DELETE FROM {term_hierarchy} WHERE tid = %d', $from_term->tid); + $ins = "vid = '". str_replace('%', '%%', db_escape_string($to_vid->vid)) ."'"; + foreach ($children as $c => $from_term_child) { + db_query('UPDATE {term_data} SET '. $ins .' WHERE tid = %d', $from_term_child->tid); + } + db_query('UPDATE {term_data} SET '. $ins .' WHERE tid = %d', $from_term->tid); + /* taxonomy_get_tree($vid, $parent = 0, $depth = -1, $max_depth = NULL) + $vid Which vocabulary to generate the tree for. + $parent The term ID under which to generate the tree. If 0, generate the tree for the entire vocabulary. + $depth Internal use only. + $max_depth The number of levels of the tree to return. Leave NULL to return all levels.*/ + switch ($edit['taxonomy_switch_to_hierarchy']) { + case 0: + $output .= t('to root level in the target vocabulary'); + $output .= "

"; + db_query('INSERT INTO {term_hierarchy} (tid, parent) VALUES (%d, %d)', $from_term->tid, 0); + break; + case 1: + $to_term = module_invoke('taxonomy', 'get_term', $edit['taxonomy_switch_to_term']); + $to_term->name ? $output .= t('below the term '). '' . $to_term->name. '' : $output .= t('below the root'); + $output .= t(' in the target vocabulary'); + db_query('INSERT INTO {term_hierarchy} (tid, parent) VALUES (%d, %d)', $from_term->tid, $edit['taxonomy_switch_to_term']); + break; + case 2: + $output .= t('below the following terms in the multiple-hierarchy target vocabulary : ').'
'; + foreach ($edit['taxonomy_switch_to_term'] as $i => $to_tid) { + $to_term = module_invoke('taxonomy', 'get_term', $to_tid); + $to_term->name ? $output .= '- '.$to_term->name.'
' : $output .= '- '.t('Root').'
'; + db_query('INSERT INTO {term_hierarchy} (tid, parent) VALUES (%d, %d)', $from_term->tid, $to_term->tid); + } + break; + } + // Update the content types in the target vocabulary if necessary + if ($edit['taxonomy_switch_target_new_types']) { + foreach (explode(',', $edit['taxonomy_switch_target_new_types']) as $type) { + db_query("INSERT INTO {vocabulary_node_types} (vid, type) VALUES (%d, '%s')", $to_vid->vid, $type); + } + } + + // db_query("UNLOCK TABLES"); } - break; - } -// Update the content types in the target vocabulary if necessary - if ($edit['taxonomy_switch_target_new_types']) { - foreach (explode(',', $edit['taxonomy_switch_target_new_types']) as $type) { - db_query("INSERT INTO {vocabulary_node_types} (vid, type) VALUES (%d, '%s')", $to_vid->vid, $type); - } - } -// db_query("UNLOCK TABLES"); return $output; } @@ -323,7 +336,7 @@ '#options' => $terms_from, '#description' => t('You must choose one from the list'), '#extra' => $extra = 0, - '#multiple' => FALSE, + '#multiple' => TRUE, //chaned to TRUE from FALSE - L0rne '#required' => TRUE, ); // Target terms