function taxonomy_edge_update_6101 in Taxonomy Edge 6
Update edge table with serial, vocabulary id and indexes, and add order table.
File
- ./
taxonomy_edge.install, line 134 - Installation file for Taxonomy Edge
Code
function taxonomy_edge_update_6101(&$sandbox) {
$ret = array();
if (!isset($sandbox['vocabularies'])) {
// We need to rebuild the data. Let's truncate before altering the table.
db_query("DELETE FROM {term_edge}");
// Change schema.
db_drop_index($ret, 'term_edge', 'idx_parent');
db_drop_primary_key($ret, 'term_edge');
db_add_field($ret, 'term_edge', 'eid', array(
'description' => 'Edge ID',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
), array(
'primary key' => array(
'eid',
),
));
db_add_field($ret, 'term_edge', 'vid', array(
'description' => 'Vocabulary ID',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
));
db_add_index($ret, 'term_edge', 'idx_update', array(
'vid',
'distance',
'parent',
));
db_add_index($ret, 'term_edge', 'idx_depth', array(
'parent',
'distance',
'vid',
));
db_add_index($ret, 'term_edge', 'idx_tree', array(
'parent',
'vid',
'distance',
));
// Add order table
$schema = array(
'description' => 'Sequencing table for sorting taxonomies.',
'fields' => array(
'oid' => array(
'description' => 'Order ID',
'type' => 'serial',
),
'vid' => array(
'description' => 'Vocabulary ID',
'type' => 'int',
'unsigned' => FALSE,
'not null' => TRUE,
'default' => 0,
),
'parent' => array(
'description' => 'Parent term ID',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'eid' => array(
'description' => 'Edge ID',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array(
'oid',
),
'indexes' => array(
'idx_order' => array(
'vid',
'parent',
),
'idx_edge' => array(
'eid',
),
),
);
db_create_table($ret, 'term_edge_order', $schema);
// Initialize vocabularies to rebuild.
$sandbox['vocabularies'] = array_values(taxonomy_get_vocabularies());
$sandbox['number_of_vocabularies'] = count($sandbox['vocabularies']);
$sandbox['current'] = 0;
$ret['#finished'] = 1 / ($sandbox['number_of_vocabularies'] + 1);
return $ret;
}
// Grab next vocabulary to be processed.
$vocabularies = $sandbox['vocabularies'];
$number_of_vocabularies = $sandbox['number_of_vocabularies'];
$current =& $sandbox['current'];
$vocabulary = $vocabularies[$current++];
// Process that vocabulary
module_load_include('rebuild.inc', 'taxonomy_edge');
$sub_context = array();
taxonomy_edge_rebuild_edges($vocabulary->vid, $sub_context);
foreach ($sub_context['results'] as $msg) {
drupal_set_message($msg);
}
$sub_context = array();
taxonomy_edge_rebuild_order($vocabulary->vid, $sub_context);
foreach ($sub_context['results'] as $msg) {
drupal_set_message($msg);
}
// Next step or finish.
$ret['#finished'] = (2 + $current) / ($number_of_vocabularies + 1);
return $ret;
}