You are here

function lineage_update_term in Taxonomy Lineage 6

Same name and namespace in other branches
  1. 5 lineage.module \lineage_update_term()
  2. 7 lineage.module \lineage_update_term()
2 calls to lineage_update_term()
lineage_taxonomy in ./lineage.module
Implementation of hook_taxonomy().
lineage_update_all in ./lineage.module
Updates all lineage records.

File

./lineage.module, line 163

Code

function lineage_update_term($term, $all = FALSE) {
  if (is_array($term)) {
    $term = (object) $term;
  }

  // If we are in the middle of updating all lineages, skip this.
  if (!$all) {

    // Select lineage for a different term in this vocab arbitrarily.
    $r = db_query("\n      SELECT tl.lineage, td.tid, td.name, td.weight, td.vid, th.parent\n        FROM {term_data} td\n          LEFT JOIN {term_lineage} tl ON tl.tid = td.tid\n          LEFT JOIN {term_hierarchy} th ON td.tid = th.tid\n        WHERE td.vid = %d\n          AND td.tid <> %d\n        LIMIT 1;", $term->vid, $term->tid);
    $other_term = db_fetch_object($r);

    // If the lineage string doesn't match what we think it should be,
    // an update is required.
    if ($other_term->lineage != lineage_string($other_term)) {
      $count = lineage_update_all($term->vid);
      return $count;
    }
  }

  // Else, just update this term.
  $base = _lineage_get_parent_lineage($term->parent);
  return count(lineage_update_term_r($term, $base));
}