You are here

feedback.install in Feedback 5

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

File

feedback.install
View source
<?php

function feedback_install() {
  switch ($GLOBALS['db_type']) {
    case 'mysqli':
    case 'mysql':
      $result = db_query("\n        CREATE TABLE IF NOT EXISTS {feedback_pages} (\n        name VARCHAR(32) NOT NULL PRIMARY KEY,\n        data LONGTEXT\n        ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
      break;
    case 'pgsql':
      $result = db_query("\n      CREATE TABLE {feedback_pages} (\n        name VARCHAR(32) NOT NULL PRIMARY KEY,\n        data TEXT\n        )");
    default:
      break;
  }

  //insert default feedback page
  require_once drupal_get_path('module', 'feedback') . '/feedback.module';
  _feedback_add_page('default');
}

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

// Table creation called in update_1 to allow for the case
// where a user is upgrading from a previous version of
// the feedback module that did not use tables.
function feedback_update_1() {
  feedback_install();
}

/*
 * convert data from old feedback storage
 */
function feedback_update_2() {
  global $conf;
  $defaults = array();
  $defaults['email'] = variable_get('feedback_email', variable_get('site_mail', ini_get('sendmail_from')));
  $defaults['title'] = variable_get('feedback_nav_link', t('feedback'));
  $defaults['instructions'] = variable_get('feedback_instructions', '');
  $defaults['subject_prefix'] = variable_get('feedback_subject_prefix', '');
  $defaults["field_subject"] = variable_get('feedback_field_subject', '1');
  $defaults["field_name"] = variable_get('feedback_field_name', '1');
  $defaults["field_postal"] = variable_get('feedback_field_postal', '0');
  $defaults["field_phone"] = variable_get('feedback_field_phone', '0');
  $defaults["field_body"] = variable_get('feedback_field_body', '1');
  $defaults["logging"] = variable_get('feedback_logging', '1');
  $defaults['hourly_threshold'] = 3;
  $result = db_query("UPDATE {feedback_pages} SET data = '%s' WHERE name = '%s'", serialize($defaults), 'default');
  if ($result) {

    //clear old unused variables
    foreach ($conf as $key => $variable) {
      if (strpos($key, 'feedback') === 0) {
        variable_del($key);
      }
    }
  }
  else {
    drupal_set_message('Failed to transfer old feedback configuration to new feedback configuration table', 'error');
  }
  return array();
}