function _taxonomy_edge_move_subtree in Taxonomy Edge 7.2
Same name and namespace in other branches
- 8 taxonomy_edge.module \_taxonomy_edge_move_subtree()
- 6 taxonomy_edge.module \_taxonomy_edge_move_subtree()
- 7 taxonomy_edge.module \_taxonomy_edge_move_subtree()
Detach path and children from current parent and attach to new parent
Parameters
$vid: Vocabulary ID
$pid: Path ID
$new_parent_pid: Path ID of new parent
1 call to _taxonomy_edge_move_subtree()
- _taxonomy_edge_taxonomy_term_update in ./
taxonomy_edge.module - Update a term in the edge tree.
File
- ./
taxonomy_edge.module, line 434 - Selecting all children of a given taxonomy term can be a pain. This module makes it easier to do this, by maintaining a complete list of edges for each term using the adjecency matrix graph theory.
Code
function _taxonomy_edge_move_subtree($vid, $pid, $new_parent_pid) {
// Remove old parents
// @fixme MySQL can not use EXISTS or IN without temp tables when deleting.
// SQLite cannot perform join delete.
// MySQL and Postgres differ in joined delete syntax.
// Use optimized joined delete for MySQL and subquery for others.
$db_type = Database::getConnection()
->databaseType();
switch ($db_type) {
case 'mysql':
case 'mysqli':
db_query("DELETE e2.*\n FROM {taxonomy_term_edge} e\n JOIN {taxonomy_term_edge} e2 ON e2.pid = e.pid\n WHERE e.parent = :parent\n AND e2.distance > e.distance\n AND e.vid = :vid AND e2.vid = :vid\n ", array(
':parent' => $pid,
':vid' => $vid,
));
break;
default:
db_query("DELETE FROM \n {taxonomy_term_edge} WHERE eid IN (\n SELECT e2.eid\n FROM {taxonomy_term_edge} e\n JOIN {taxonomy_term_edge} e2 ON e2.pid = e.pid\n WHERE e.parent = :parent\n AND e2.distance > e.distance\n AND e.vid = :vid AND e2.vid = :vid\n )", array(
':parent' => $pid,
':vid' => $vid,
));
break;
}
// Build new parents
db_query("INSERT INTO {taxonomy_term_edge} (vid, pid, parent, distance)\n SELECT :vid, e2.pid, e.parent, e.distance + e2.distance + 1 AS distance\n FROM {taxonomy_term_edge} e\n INNER JOIN {taxonomy_term_edge} e2 ON e.pid = :parent AND e2.parent = :pid\n WHERE e.vid = :vid AND e2.vid = :vid\n ", array(
':pid' => $pid,
':parent' => $new_parent_pid,
':vid' => $vid,
));
}