You are here

taxonomy_edge.install in Taxonomy Edge 6

Installation file for Taxonomy Edge

File

taxonomy_edge.install
View source
<?php

/**
 * @file
 *
 * Installation file for Taxonomy Edge
 */

/**
 * Implements hook_install().
 */
function taxonomy_edge_install() {
  $ret = array();
  $ret[] = drupal_install_schema('taxonomy_edge');
  db_add_index($ret, 'node', 'idx_taxonomy_edge', array(
    'sticky',
    'created',
    'nid',
  ));
  db_add_index($ret, 'term_node', 'idx_taxonomy_edge', array(
    'vid',
    'tid',
  ));
  drupal_set_message(st('Taxonomy Edge is now installed. Add the provided patch to the core module Taxonomy module for better performance.'));
  drupal_set_message(st('Taxonomy Edge settings are available under !link', array(
    '!link' => l(st('Administer > Content > Taxonomy Edge'), 'admin/content/taxonomy/edge'),
  )));
  drupal_set_message(st('Remember to build trees: !link', array(
    '!link' => l(st('Administer > Content > Taxonomy'), 'admin/content/taxonomy'),
  )));
  return $ret;
}

/**
 * Implements hook_uninstall().
 */
function taxonomy_edge_uninstall() {
  $ret = array();
  $ret[] = drupal_uninstall_schema('taxonomy_edge');
  db_drop_index($ret, 'node', 'idx_taxonomy_edge');
  db_drop_index($ret, 'term_node', 'idx_taxonomy_edge');
  drupal_set_message(st('Taxonomy Edge is now uninstalled. You may remove the provided patch to the core module Taxonomy module if applicable.'));
  return $ret;
}

/**
 * Implements hook_schema().
 */
function taxonomy_edge_schema() {
  $schema['term_edge'] = array(
    'description' => 'Stores edge list for taxonomies.',
    'fields' => array(
      'eid' => array(
        'description' => 'Edge ID',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'vid' => array(
        'description' => 'Vocabulary ID',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'tid' => array(
        'description' => 'Term ID',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'parent' => array(
        'description' => 'Parent Term ID',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'distance' => array(
        'description' => 'Distance to parent (depth)',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'eid',
    ),
    'indexes' => array(
      'idx_update' => array(
        'vid',
        'distance',
        'parent',
      ),
      'idx_depth' => array(
        'parent',
        'distance',
        'vid',
      ),
      'idx_term' => array(
        'tid',
        'distance',
      ),
      'idx_tree' => array(
        'parent',
        'vid',
        'distance',
      ),
    ),
  );
  $schema['term_edge_order'] = 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',
      ),
    ),
  );
  return $schema;
}

/**
 * Update edge table with serial, vocabulary id and indexes, and add order table.
 */
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;
}

/**
 * Implements hook_enable().
 */
function taxonomy_edge_enable() {
  if (function_exists('drush_verify_cli') && drush_verify_cli()) {
    db_query("DELETE FROM {term_edge}");
    db_query("DELETE FROM {term_edge_order}");
    module_load_include('rebuild.inc', 'taxonomy_edge');
    $vids = array_keys(taxonomy_get_vocabularies());
    taxonomy_edge_rebuild_all_batch($vids);
    $batch =& batch_get();
    $batch['progressive'] = FALSE;
    batch_process();
  }
  else {
    $_SESSION['taxonomy_edge_rebuild_module_enabled'] = TRUE;
  }
}

Functions

Namesort descending Description
taxonomy_edge_enable Implements hook_enable().
taxonomy_edge_install Implements hook_install().
taxonomy_edge_schema Implements hook_schema().
taxonomy_edge_uninstall Implements hook_uninstall().
taxonomy_edge_update_6101 Update edge table with serial, vocabulary id and indexes, and add order table.