function _taxonomy_edge_delete_subtree in Taxonomy Edge 6
Same name and namespace in other branches
- 8 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 352 - 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.
global $db_type;
$type = $type == 0 ? '' : 'AND e2.distance > e.distance';
$args = $tids;
$args[] = $vid;
$args[] = $vid;
$placeholders = db_placeholders($tids);
switch ($db_type) {
case 'mysql':
case 'mysqli':
db_query("DELETE e2.*\n FROM {term_edge} e\n INNER JOIN {term_edge} e2 ON e2.tid = e.tid\n WHERE e.parent IN ({$placeholders})\n {$type}\n AND e.vid = %d AND e2.vid = %d\n ", $args);
break;
default:
db_query("DELETE FROM\n {term_edge} WHERE eid IN (\n SELECT e2.eid\n FROM {term_edge} e\n INNER JOIN {term_edge} e2 ON e2.tid = e.tid\n WHERE e.parent IN ({$placeholders})\n {$type}\n AND e.vid = %d AND e2.vid = %d\n )", $args);
break;
}
}