You are here

webform_report.install in Webform Report 5

File

webform_report.install
View source
<?php

function webform_report_install() {
  drupal_set_message('Installing webform');
  switch ($GLOBALS['db_type']) {
    case 'mysqli':
    case 'mysql':
      db_query("CREATE TABLE if not exists {webform_report} (\n        nid int(10) unsigned NOT NULL default '0',\n        wnid int(10) unsigned NOT NULL default '0',\n        kcid int(10) unsigned NOT NULL default '0',\n        description text NOT NULL,\n        sort int(2) unsigned NOT NULL default '4',\n        options text NOT NULL,\n        filter_type int(2) unsigned NOT NULL default '0',\n        filter_value varchar(128) NOT NULL default '',\n        results_per_page int(1) unsigned NOT NULL default '20',\n        PRIMARY KEY  (nid)\n        ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */");
      db_query("CREATE TABLE if not exists {webform_report_component} (\n        nid int(10) unsigned NOT NULL default '0',\n        cid int(10) unsigned NOT NULL default '0',\n        PRIMARY KEY  (nid, cid)\n        ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */");
      break;
    case 'pgsql':
      db_query("CREATE TABLE {webform_report} (\n        nid integer NOT NULL default '0',\n        wnid integer NOT NULL default '0',\n        kcid integer NOT NULL default '0',\n        description text NOT NULL,\n        sort smallint NOT NULL default '4',\n        options text NOT NULL,\n        filter_type smallint NOT NULL default '0',\n        filter_value varchar(128) NOT NULL default '',\n        results_per_page smallint NOT NULL default '20',\n        PRIMARY KEY  (nid)\n        )");
      db_query("CREATE TABLE {webform_report_component} (\n        nid integer NOT NULL default '0',\n        cid integer NOT NULL default '0',\n        PRIMARY KEY  (nid,cid)\n        )");
      break;
  }
  variable_set('webform_report_version', array(
    'text' => '5.1.5',
    'build' => '515',
  ));
  $success = TRUE;
  if ($success) {
    drupal_set_message(t('Webform report module installed module tables successfully.'));
  }
  else {
    drupal_set_message(t('The installation of webform report module was unsuccessful.'), 'error');
  }
}

/**
 * Implementation of hook_uninstall
 */
function webform_report_uninstall() {
  db_query('DROP TABLE {webform_report}');
  db_query('DROP TABLE {webform_report_component}');
  variable_del("webform_report");

  // delete all webform reports
  $result = db_query("SELECT nid FROM {node} WHERE type = 'webform_report'");
  while ($webform_report_node = db_fetch_object($result)) {
    node_delete($webform_report_node->nid);
  }
  node_type_delete('webform_report');
}

/**
 * Drupal 5 updates
 */

// New table structure to eliminate redundancy
function webform_report_update_1() {
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $items[] = update_sql("CREATE TABLE if not exists {webform_report_new} (\n        nid int(10) unsigned NOT NULL default '0',\n        wnid int(10) unsigned NOT NULL default '0',\n        kcid int(10) unsigned NOT NULL default '0',\n        description text NOT NULL,\n        sort int(2) unsigned NOT NULL default '4',\n        options text NOT NULL,\n        filter_type int(2) unsigned NOT NULL default '0',\n        filter_value varchar(128) NOT NULL default '',\n        results_per_page int(1) unsigned NOT NULL default '20',\n        PRIMARY KEY  (nid)\n        ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */");
      $items[] = update_sql("CREATE TABLE if not exists {webform_report_component} (\n        nid int(10) unsigned NOT NULL default '0',\n        cid int(10) unsigned NOT NULL default '0',\n        PRIMARY KEY  (nid, cid)\n        ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */");
      break;
    case 'pgsql':
      $items[] = update_sql("CREATE TABLE {webform_report_new} (\n        nid integer NOT NULL default '0',\n        wnid integer NOT NULL default '0',\n        kcid integer NOT NULL default '0',\n        description text NOT NULL,\n        sort smallint NOT NULL default '4',\n        options text NOT NULL,\n        filter_type smallint NOT NULL default '0',\n        filter_value varchar(128) NOT NULL default '',\n        results_per_page smallint NOT NULL default '20',\n        PRIMARY KEY  (nid)\n        )");
      $items[] = update_sql("CREATE TABLE {webform_report_component} (\n        nid integer NOT NULL default '0',\n        cid integer NOT NULL default '0',\n        PRIMARY KEY  (nid,cid)\n        )");
      break;
  }
  $items[] = update_sql("INSERT INTO {webform_report_new} (nid, wnid, kcid, description, sort) (SELECT DISTINCT nid, wnid, kcid, description, sort FROM {webform_report})");
  $items[] = update_sql("INSERT INTO {webform_report_component} (nid, cid) (SELECT nid, cid FROM {webform_report})");
  $items[] = update_sql("DROP TABLE {webform_report}");
  $items[] = update_sql("ALTER TABLE {webform_report_new} RENAME TO webform_report");
  return $items;
}

Functions

Namesort descending Description
webform_report_install
webform_report_uninstall Implementation of hook_uninstall
webform_report_update_1