You are here

function taxonomy_manager_delete_terms in Taxonomy Manager 6.2

Same name and namespace in other branches
  1. 5 taxonomy_manager.module \taxonomy_manager_delete_terms()
  2. 6 taxonomy_manager.admin.inc \taxonomy_manager_delete_terms()
  3. 7 taxonomy_manager.admin.inc \taxonomy_manager_delete_terms()

deletes terms from the database optional orphans (terms where parent get deleted) can be deleted as well

(difference to taxonomy_del_term: deletion of orphans optional)

Parameters

$tids array of term id to delete:

$options associative array with options: if $options['delete_orphans'] is true, orphans get deleted

2 calls to taxonomy_manager_delete_terms()
taxonomy_manager_merge in ./taxonomy_manager.admin.inc
merges terms into another term (main term), all merged term get added to the main term as synonyms. term_node relations are updated automatically (node with one of merging terms gets main term assigned) after all opterions are done (adding of…
taxonomy_manager_term_confirm_delete_submit in ./taxonomy_manager.admin.inc
Submit handler to delete a term after confirmation.

File

./taxonomy_manager.admin.inc, line 2060
Taxonomy Manager Admin

Code

function taxonomy_manager_delete_terms($tids, $options = array()) {
  if (!is_array($tids)) {
    array(
      $tids,
    );
  }
  while (count($tids) > 0) {
    $orphans = array();
    foreach ($tids as $tid) {
      if ($children = taxonomy_get_children($tid)) {
        foreach ($children as $child) {
          $parents = taxonomy_get_parents($child->tid);
          if ($options['delete_orphans']) {
            if (count($parents) == 1) {
              $orphans[] = $child->tid;
            }
          }
          else {
            db_query("DELETE FROM {term_hierarchy} WHERE tid = %d AND parent = %d", $child->tid, $tid);
            if (count($parents) == 1) {
              if (!db_result(db_query("SELECT COUNT(*) FROM {term_hierarchy} WHERE tid = %d AND parent = 0", $child->tid))) {
                db_query("INSERT INTO {term_hierarchy} (parent, tid) VALUES(0, %d)", $child->tid);
              }
            }
          }
        }
      }
      $term = (array) taxonomy_get_term($tid);
      db_query('DELETE FROM {term_data} WHERE tid = %d', $tid);
      db_query('DELETE FROM {term_hierarchy} WHERE tid = %d', $tid);
      db_query('DELETE FROM {term_relation} WHERE tid1 = %d OR tid2 = %d', $tid, $tid);
      db_query('DELETE FROM {term_synonym} WHERE tid = %d', $tid);
      db_query('DELETE FROM {term_node} WHERE tid = %d', $tid);
      module_invoke_all('taxonomy', 'delete', 'term', $term);
      $tids = $orphans;
    }
  }
}