You are here

function taxonomy_edge_rebuild_order in Taxonomy Edge 7

Same name and namespace in other branches
  1. 8 taxonomy_edge.rebuild.inc \taxonomy_edge_rebuild_order()
  2. 6 taxonomy_edge.rebuild.inc \taxonomy_edge_rebuild_order()
  3. 7.2 taxonomy_edge.rebuild.inc \taxonomy_edge_rebuild_order()

Rebuild the sorted tree.

3 calls to taxonomy_edge_rebuild_order()
TaxonomyEdgeTreeTestCase::testOrder in tests/tree.test
taxonomy_edge_cron in ./taxonomy_edge.module
Implements hook_cron().
taxonomy_edge_update_7101 in ./taxonomy_edge.install
Fixup schema version and broken upgrade paths.
2 string references to 'taxonomy_edge_rebuild_order'
taxonomy_edge_rebuild_all_batch in ./taxonomy_edge.rebuild.inc
Start batch job for rebuild of edges and order.
taxonomy_edge_rebuild_order_batch in ./taxonomy_edge.rebuild.inc
Start batch job for rebuild of order.

File

./taxonomy_edge.rebuild.inc, line 163
This file contains the functions for reuilding various tables.

Code

function taxonomy_edge_rebuild_order($vid, &$context) {
  $vocabulary = taxonomy_vocabulary_load($vid);
  if (!$vocabulary) {
    $context['success'] = FALSE;
    $context['message'] = t('Invalid vocabulary ID: %vid', array(
      '%vid' => $vid,
    ));
    return;
  }

  // Acquire lock.
  if (!lock_acquire('taxonomy_edge_rebuild_edges_' . $vid)) {
    $context['success'] = FALSE;
    $context['message'] = t('Could not acquire lock!');
    return;
  }
  $tx = db_transaction();
  $time = microtime(TRUE);
  taxonomy_edge_invalidate_order($vid);
  db_query("DELETE FROM {taxonomy_term_edge_order} WHERE vid = :vid", array(
    ':vid' => $vid,
  ));
  $total_rows = db_query("INSERT INTO {taxonomy_term_edge_order} (vid, parent, eid)\n    SELECT op.vid, op.parent, op.eid\n    FROM {taxonomy_term_edge} op\n    WHERE op.vid = :vid\n    ORDER BY " . _taxonomy_edge_generate_term_path_query('op.tid'), array(
    ':vid' => $vid,
  ))
    ->rowCount();
  $context['success'] = TRUE;
  $context['finished'] = 1;
  $context['results'][] = t('%name sorted: %rows edges in %time seconds', array(
    '%rows' => $total_rows,
    '%time' => sprintf("%.03f", microtime(TRUE) - $time),
    '%name' => $vocabulary->name,
  ));
  db_insert('taxonomy_term_edge_order')
    ->fields(array(
    'vid' => -$vid,
  ))
    ->execute();
  lock_release('taxonomy_edge_rebuild_edges_' . $vid);
}