function taxonomy_manager_switch in Taxonomy Manager 6.2
Same name and namespace in other branches
- 7 taxonomy_manager.admin.inc \taxonomy_manager_switch()
Changes vocabulary of given terms and its children conflicts might be possible with multi-parent terms!
1 call to taxonomy_manager_switch()
File
- ./
taxonomy_manager.admin.inc, line 2001 - Taxonomy Manager Admin
Code
function taxonomy_manager_switch($tids, $from_voc, $to_voc, $parents = array()) {
foreach ($tids as $tid) {
//hook to inform modules about the changes
module_invoke_all('taxonomy_manager_term', 'switch', $tid, $from_voc, $to_voc);
$children = taxonomy_get_tree($from_voc, $tid);
$place_holder = array();
$terms_to_switch = array();
foreach ($children as $child) {
$placeholder[] = '%d';
$terms_to_switch[] = $child->tid;
}
$placeholder[] = '%d';
$terms_to_switch[] = $tid;
db_query("UPDATE {term_data} SET vid = %d WHERE tid IN (" . implode(', ', $placeholder) . ")", array_merge(array(
$to_voc,
), $terms_to_switch));
//delete references to parents from the old voc
foreach ($children as $child) {
$term_parents = taxonomy_get_parents($child->tid);
foreach ($term_parents as $term_parent) {
if ($term_parent->vid != $to_voc) {
db_query("DELETE FROM {term_hierarchy} WHERE tid = %d AND parent = %d", $child->tid, $term_parent->tid);
}
}
}
//set parent of the selected term
if (!count($parents)) {
$parents[0] = 0;
}
taxonomy_manager_move($parents, array(
$tid,
));
taxonomy_manager_update_voc($to_voc, $parents);
}
}