You are here

taxonomy_edge.install in Taxonomy Edge 7.2

Same filename and directory in other branches
  1. 8 taxonomy_edge.install
  2. 6 taxonomy_edge.install
  3. 7 taxonomy_edge.install

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() {
  _taxonomy_edge_install();
  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 > Structure > Taxonomy'), 'admin/structure/taxonomy/edge'),
  )));
}

/**
 * Implements hook_uninstall().
 */
function taxonomy_edge_uninstall() {
  _taxonomy_edge_uninstall();
  drupal_set_message(st('Taxonomy Edge is now uninstalled. You may remove the provided patch to the core module Taxonomy module if applicable.'));
}

/**
 * Implements hook_enable().
 */
function taxonomy_edge_enable() {
  return;

  // Rebuild the edge list when module is enabled
  drupal_load('module', 'taxonomy');
  drupal_load('module', 'taxonomy_edge');
  module_load_include('rebuild.inc', 'taxonomy_edge');
  foreach (taxonomy_get_vocabularies() as $vocabulary) {
    taxonomy_edge_rebuild_edges_batch($vocabulary->vid);
    taxonomy_edge_rebuild_order_batch($vocabulary->vid);
  }
}

/**
 * Implements hook_schema().
 */
function taxonomy_edge_schema() {
  $schema['taxonomy_term_edge_path'] = array(
    'description' => 'Stores paths for taxonomies.',
    'fields' => array(
      'pid' => array(
        'description' => 'Path ID',
        'type' => 'serial',
      ),
      'tid' => array(
        'description' => 'Term ID',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'vid' => array(
        'description' => 'Vocabulary ID',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'temp_pid' => array(
        'description' => 'Temporary Path ID for updates',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'pid',
    ),
    'indexes' => array(
      'idx_update' => array(
        'vid',
        'temp_pid',
      ),
      'idx_order' => array(
        'pid',
        'tid',
      ),
      'idx_term' => array(
        'tid',
        'pid',
      ),
    ),
  );
  $schema['taxonomy_term_edge'] = array(
    'description' => 'Stores edge list for taxonomies.',
    'fields' => array(
      'eid' => array(
        'description' => 'Edge ID',
        'type' => 'serial',
      ),
      'vid' => array(
        'description' => 'Vocabulary ID',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'pid' => array(
        'description' => 'Path 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',
    ),
    'unique keys' => array(
      'idx_node' => array(
        'pid',
        'distance',
      ),
    ),
    'indexes' => array(
      'idx_update' => array(
        'parent',
        'pid',
      ),
      'idx_path' => array(
        'pid',
        'parent',
        'distance',
      ),
      'idx_build' => array(
        'distance',
        'pid',
      ),
      'idx_depth' => array(
        'vid',
        'distance',
      ),
    ),
  );
  $schema['taxonomy_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' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'pid' => array(
        'description' => 'Path ID',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'oid',
    ),
    'indexes' => array(
      'idx_vocab' => array(
        'vid',
        'oid',
        'pid',
      ),
    ),
  );
  return $schema;
}
function _taxonomy_edge_install() {
  db_add_index('node', 'idx_taxonomy_edge', array(
    'sticky',
    'created',
    'nid',
  ));
  db_add_index('taxonomy_index', 'idx_taxonomy_edge', array(
    'sticky',
    'created',
    'nid',
  ));
}
function _taxonomy_edge_uninstall() {
  db_drop_index('node', 'idx_taxonomy_edge');
  db_drop_index('taxonomy_index', 'idx_taxonomy_edge');
  variable_del('taxonomy_edge_static_caching');
  variable_del('taxonomy_edge_max_depth');
  variable_del('taxonomy_edge_build_realtime');
  variable_del('taxonomy_edge_optimized_get_tree');
}

/**
 * Add path id to support multiple parents properly
 */
function taxonomy_edge_update_7200() {
  $schema = drupal_get_schema('taxonomy_term_edge_path');
  db_create_table('taxonomy_term_edge_path', $schema);
  $schema = drupal_get_schema('taxonomy_term_edge_order');
  db_create_table('taxonomy_term_edge_order', $schema);
  db_truncate('taxonomy_term_edge')
    ->execute();
  db_drop_primary_key('taxonomy_term_edge');
  db_drop_index('taxonomy_term_edge', 'idx_term');
  db_drop_index('taxonomy_term_edge', 'idx_parent');
  db_drop_field('taxonomy_term_edge', 'tid');
  db_add_field('taxonomy_term_edge', 'pid', array(
    'description' => 'Path ID',
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 0,
  ));
  db_add_index('taxonomy_term_edge', 'idx_update', array(
    'parent',
    'pid',
  ));
  db_add_index('taxonomy_term_edge', 'idx_path', array(
    'pid',
    'parent',
    'distance',
  ));
  db_add_index('taxonomy_term_edge', 'idx_build', array(
    'distance',
    'pid',
  ));
  db_add_index('taxonomy_term_edge', 'idx_depth', array(
    'vid',
    'distance',
  ));
}

Functions