You are here

function lineage_update_term in Taxonomy Lineage 7

Same name and namespace in other branches
  1. 5 lineage.module \lineage_update_term()
  2. 6 lineage.module \lineage_update_term()
3 calls to lineage_update_term()
lineage_taxonomy_term_insert in ./lineage.module
Implements hook_taxonomy_term_insert().
lineage_taxonomy_term_update in ./lineage.module
Implements hook_taxonomy_term_update().
lineage_update_all in ./lineage.module
Updates all lineage records.

File

./lineage.module, line 192
lineage.module Module code for taxonomy term hierarchy lineage.

Code

function lineage_update_term($term, $all = FALSE) {

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

    // Select lineage for a different term in this vocab arbitrarily.
    $query = db_select('taxonomy_term_data', 'td');
    $query
      ->join('taxonomy_term_lineage', 'tl', 'tl.tid = td.tid');
    $query
      ->join('taxonomy_term_hierarchy', 'th', 'td.tid = th.tid');
    $query
      ->fields('tl', array(
      'lineage',
    ));
    $query
      ->fields('td', array(
      'tid',
      'name',
      'weight',
      'vid',
    ));
    $query
      ->fields('th', array(
      'parent',
    ));
    $query
      ->condition('td.vid', $term->vid, '=');
    $query
      ->condition('td.tid', $term->tid, '<>');
    $query
      ->range(0, 1);
    $other_term = $query
      ->execute()
      ->fetchObject();

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