You are here

nat.install in Node Auto Term [NAT] 5

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

File

nat.install
View source
<?php

/**
 * Implementation of hook_install().
 */
function nat_install() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysqli':
    case 'mysql':
      db_query("CREATE TABLE {nat} (\n        nid int NOT NULL default 0,\n        tid int NOT NULL default 0,\n        vid int NOT NULL default 0,\n        KEY nid (nid))\n        COMMENT = 'NAT module: establish relationship between nids and tids.'\n        /*!40100 default CHARACTER SET utf8 */");
      break;
    case 'pgsql':
      db_query("CREATE TABLE {nat} (\n        nid integer NOT NULL default 0,\n        tid integer NOT NULL default 0,\n        vid integer NOT NULL default 0)");
      db_query("CREATE INDEX {nat}_nid_idx ON {nat}(nid)");
  }
  return $ret;
}

/**
 * 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;
}

/**
 * Implementation of hook_uninstall().
 */
function nat_uninstall() {
  db_query('DROP TABLE {nat}');
  variable_del('nat_config');
}

Functions

Namesort descending Description
nat_install Implementation of hook_install().
nat_uninstall Implementation of hook_uninstall().
nat_update_2 Add a vid column to the NAT table.