You are here

nat.install in Node Auto Term [NAT] 7.2

Same filename and directory in other branches
  1. 5 nat.install
  2. 6.2 nat.install
  3. 6 nat.install
  4. 7 nat.install

File

nat.install
View source
<?php

/*
 * @file
 * NAT - node auto term - install file.
 */

/**
 * Implements hook_install().
 */
function nat_install() {
  $t = get_t();
  drupal_set_message($t('NAT module: Installation script complete.'));
}

/**
 * Implements hook_install().
 */
function nat_schema() {
  $schema['nat'] = array(
    'description' => 'NAT module: establish relationship between nids and tids.',
    'fields' => array(
      'nid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => 'Index: Node ID.',
      ),
      'tid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => 'Term ID.',
      ),
      'vid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => 'Vocabulary ID.',
      ),
    ),
    'indexes' => array(
      'nid' => array(
        'nid',
      ),
    ),
  );
  return $schema;
}

/**
 * Add a vid column to the NAT table.
 */
function nat_update_2() {
  switch ($GLOBALS['db_type']) {
    case 'mysqli':
    case 'mysql':
      $ret[] = update_sql("ALTER TABLE {nat} ADD vid int NOT NULL DEFAULT 0");
      break;
    case 'pgsql':
      db_add_column($ret, 'nat', 'vid', 'int', array(
        'not null' => TRUE,
        'default' => 0,
      ));
      break;
  }
  $result = db_query('SELECT n.nid, n.tid, td.vid FROM {nat} n INNER JOIN {term_data} td USING (tid)');
  while ($node = db_fetch_array($result)) {
    db_query('UPDATE {nat} SET vid = %d WHERE nid = %d AND tid = %d', $node['vid'], $node['nid'], $node['tid']);
  }
  return $ret;
}

/**
 * Implements hook_uninstall().
 */
function nat_uninstall() {
  variable_del('nat_config');
  $t = get_t();
  drupal_set_message($t('NAT module: Uninstallation script complete.'));
}

/**
 * Convert configuration settings from vocab vid to vocab machine_name
 */
function nat_update_7002() {

  // Convert stored configuration from vocab vid to machine_name
  $nat_config = variable_get('nat_config', array());
  if (isset($nat_config['types'])) {
    foreach ($nat_config['types'] as $type => $vids) {
      unset($vocab_names);
      if (is_array($vids)) {
        foreach ($vids as $vid) {
          if (is_numeric($vid)) {
            $vocab = taxonomy_vocabulary_load($vid);
            $types[$vocab->machine_name] = $vocab->machine_name;
          }
          if (isset($types)) {
            $nat_config['types'][$type] = $types;
          }
        }
      }
    }
  }
  if (isset($nat_config['associations'])) {
    foreach ($nat_config['associations'] as $type => $vids) {
      unset($vocab_names);
      if (is_array($vids)) {
        foreach ($vids as $vid => $fields) {
          if (is_numeric($vid)) {
            $vocab = taxonomy_vocabulary_load($vid);
            $associations[$vocab->machine_name] = $fields;
          }
          if (isset($associations)) {
            $nat_config['associations'][$type] = $associations;
          }
        }
      }
    }
  }
  serialize($nat_config);
  variable_set('nat_config', $nat_config);
}

Functions

Namesort descending Description
nat_install Implements hook_install().
nat_schema Implements hook_install().
nat_uninstall Implements hook_uninstall().
nat_update_2 Add a vid column to the NAT table.
nat_update_7002 Convert configuration settings from vocab vid to vocab machine_name