You are here

function lineage_update_term_r in Taxonomy Lineage 5

Same name and namespace in other branches
  1. 6 lineage.module \lineage_update_term_r()
  2. 7 lineage.module \lineage_update_term_r()
2 calls to lineage_update_term_r()
lineage_update_all in ./lineage.module
lineage_update_term in ./lineage.module

File

./lineage.module, line 44

Code

function lineage_update_term_r($term, $base, $tids) {

  // Extend the base.
  $base['base'] .= lineage_string($term);

  // Update the hierarchy for the current tid.
  db_query("DELETE FROM {term_lineage} WHERE tid = '%d'", $term->tid);
  db_query("INSERT INTO {term_lineage} (tid, lineage, depth) VALUES ('%d', '%s', '%d')", $term->tid, $base['base'], $base['depth']);
  $base['depth']++;

  // Mark that we've done this one to prevent looping.
  $tids[$term->tid] = true;

  // Update all the children.
  $result = db_query("SELECT td.tid, td.name, td.weight FROM {term_hierarchy} th LEFT JOIN {term_data} td ON td.tid = th.tid WHERE th.parent = '%d'", $term->tid);
  while ($child = db_fetch_object($result)) {

    // loop protection, just in case.
    if (!isset($tids[$child->tid])) {
      $tids = lineage_update_term_r($child, $base, $tids);
    }
  }
  return $tids;
}