You are here

function _taxonomy_edge_delete_subtree in Taxonomy Edge 7

Same name and namespace in other branches
  1. 8 taxonomy_edge.module \_taxonomy_edge_delete_subtree()
  2. 6 taxonomy_edge.module \_taxonomy_edge_delete_subtree()

Delete subtree.

Parameters

integer $vid: Vocabulary ID.

array $tids: Array of term ids to delete subtree from.

integer $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 470
Optimization of taxonomy data model for SQL performance.

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;
  }
}