function _taxonomy_edge_taxonomy_term_insert in Taxonomy Edge 7
Same name and namespace in other branches
- 8 taxonomy_edge.module \_taxonomy_edge_taxonomy_term_insert()
- 6 taxonomy_edge.module \_taxonomy_edge_taxonomy_term_insert()
- 7.2 taxonomy_edge.module \_taxonomy_edge_taxonomy_term_insert()
Insert a term into the edge tree.
Parameters
object $term: Term object.
2 calls to _taxonomy_edge_taxonomy_term_insert()
- taxonomy_edge_process_queue_item in ./
taxonomy_edge.module - Cron queue worker.
- taxonomy_edge_taxonomy_term_insert in ./
taxonomy_edge.module - Implements hook_taxonomy_term_insert().
File
- ./
taxonomy_edge.module, line 553 - Optimization of taxonomy data model for SQL performance.
Code
function _taxonomy_edge_taxonomy_term_insert($term) {
// Derive proper parents.
$parents = _taxonomy_edge_unify_parents($term->parent);
if ($term->tid > 0) {
$tx = db_transaction();
db_insert('taxonomy_term_edge')
->fields(array(
'vid' => $term->vid,
'tid' => $term->tid,
'parent' => $term->tid,
))
->execute();
db_query("INSERT INTO {taxonomy_term_edge} (vid, tid, parent, distance)\n SELECT e.vid, :tid AS tid, e.parent, e.distance + 1 AS distance\n FROM {taxonomy_term_edge} e\n WHERE e.tid IN (:parents)\n AND e.vid = :vid\n ", array(
':vid' => $term->vid,
':tid' => $term->tid,
':parents' => $parents,
));
taxonomy_edge_invalidate_order($term->vid);
}
else {
watchdog('taxonomy_edge', 'Invalid term-id (%tid) received', array(
'%tid' => $term->tid,
), WATCHDOG_ERROR);
}
}