function taxonomy_manager_switch in Taxonomy Manager 7
Same name and namespace in other branches
- 6.2 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 2368
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);
$terms_to_switch = array();
foreach ($children as $child) {
$terms_to_switch[] = $child->tid;
}
$terms_to_switch[] = $tid;
db_update('taxonomy_term_data')
->fields(array(
'vid' => $to_voc,
))
->condition('tid', $terms_to_switch, 'IN')
->execute();
taxonomy_terms_static_reset();
//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_delete('taxonomy_term_hierarchy')
->condition('tid', $child->tid)
->condition('parent', $term_parent->tid)
->execute();
}
}
}
//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);
}
//TODO invoke update hook!!
taxonomy_terms_static_reset();
}