function _taxonomy_edge_delete_subtree in Taxonomy Edge 8
Same name and namespace in other branches
- 6 taxonomy_edge.module \_taxonomy_edge_delete_subtree()
- 7 taxonomy_edge.module \_taxonomy_edge_delete_subtree()
Delete subtree
Parameters
$vid: Vocabulary ID
$tids: Array of term ids to delete subtree from
$type: Type of delete 0: Delete entire subtree 1: Delete ancestors (detach children from parents in $tids)
1 call to _taxonomy_edge_delete_subtree()
- _taxonomy_edge_detach_subtree in ./
taxonomy_edge.module - Detach children from parents in $tids (delete ancestors)
File
- ./
taxonomy_edge.module, line 447 - 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_delete_subtree($vid, $tids, $type = 0) {
// @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.
// With MySQL 5.6 we might be able to switch to a subquery method only.
$db_type = Database::getConnection()
->databaseType();
$type = $type == 0 ? '' : 'AND e2.distance > e.distance';
switch ($db_type) {
case 'mysql':
case 'mysqli':
db_query("DELETE e2.*\n FROM {taxonomy_term_edge} e\n INNER JOIN {taxonomy_term_edge} e2 ON e2.tid = e.tid\n WHERE e.parent IN (:tids)\n {$type}\n AND e.vid = :vid AND e2.vid = :vid\n ", array(
':tids' => $tids,
':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 INNER JOIN {taxonomy_term_edge} e2 ON e2.tid = e.tid AND e2.vid = e.vid\n WHERE e.parent IN (:tids)\n {$type}\n AND e.vid = :vid\n )", array(
':tids' => $tids,
':vid' => $vid,
));
break;
}
}