You are here

feedback.install in Feedback 5.2

Same filename and directory in other branches
  1. 5 feedback.install
  2. 6.2 feedback.install
  3. 7.2 feedback.install

File

feedback.install
View source
<?php

/**
 * Implementation of hook_install().
 */
function feedback_install() {
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_query("CREATE TABLE {feedback} (\n        fid int unsigned NOT NULL default '0',\n        uid int unsigned NOT NULL default '0',\n        status tinyint unsigned NOT NULL default '0',\n        message longtext NOT NULL,\n        location text NOT NULL,\n        location_masked text NOT NULL,\n        url text NOT NULL,\n        timestamp int NOT NULL,\n        useragent varchar(255) NOT NULL,\n        PRIMARY KEY (fid),\n        KEY location (location(32)),\n        KEY location_masked (location_masked(32))\n      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
      break;
    case 'pgsql':
      db_query("CREATE TABLE {feedback} (\n        fid int_unsigned NOT NULL default '0',\n        uid int_unsigned NOT NULL default '0',\n        status smallint NOT NULL default '0',\n        message text NOT NULL,\n        location text NOT NULL,\n        location_masked text NOT NULL,\n        url text NOT NULL,\n        timestamp int NOT NULL,\n        useragent varchar(255) NOT NULL,\n        PRIMARY KEY (fid)\n      )");
      db_query("CREATE INDEX {feedback}_fid_idx ON {feedback} (fid)");
      db_query("CREATE INDEX {feedback}_location_idx ON {feedback} (location)");
      db_query("CREATE INDEX {feedback}_location_masked_idx ON {feedback} (location_masked)");
      break;
  }
}

/**
 * Implementation of hook_uninstall().
 */
function feedback_uninstall() {
  db_query("DROP TABLE {feedback}");
  db_query("DELETE FROM {variable} WHERE name LIKE 'feedback_%%'");
}

/**
 * Add location_masked column to {feedback} table.
 */
function feedback_update_5200() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("ALTER TABLE {feedback} ADD location_masked text NOT NULL AFTER location");
      $ret[] = update_sql("ALTER TABLE {feedback} ADD KEY location_masked (location_masked(32))");
      break;
    case 'pgsql':
      db_add_column($ret, 'feedback', 'location_masked', 'text', array(
        'not null' => TRUE,
      ));
      $ret[] = update_sql("CREATE INDEX {feedback}_location_masked_idx ON {feedback} (location_masked)");
      break;
  }
  return $ret;
}

/**
 * Add user agent column.
 */
function feedback_update_5201() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("ALTER TABLE {feedback} ADD useragent varchar(255) NOT NULL");
      break;
    case 'pgsql':
      db_add_column($ret, 'feedback', 'useragent', 'varchar(255)', array(
        'not null' => TRUE,
      ));
      break;
  }
  return $ret;
}

/**
 * Add column for absolute URL.
 */
function feedback_update_5202() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("ALTER TABLE {feedback} ADD url text NOT NULL AFTER location_masked");
      $ret[] = update_sql("UPDATE {feedback} SET url = location");
      break;
    case 'pgsql':
      db_add_column($ret, 'feedback', 'url', 'text', array(
        'not null' => TRUE,
      ));
      $ret[] = update_sql("UPDATE {feedback} SET url = location");
      break;
  }
  return $ret;
}

Functions

Namesort descending Description
feedback_install Implementation of hook_install().
feedback_uninstall Implementation of hook_uninstall().
feedback_update_5200 Add location_masked column to {feedback} table.
feedback_update_5201 Add user agent column.
feedback_update_5202 Add column for absolute URL.