You are here

contact.install in Contact 6.2

Same filename and directory in other branches
  1. 7.2 contact.install

Install, update and uninstall functions for the contact module.

File

contact.install
View source
<?php

/**
 * @file
 * Install, update and uninstall functions for the contact module.
 */

/**
 * Implements hook_schema().
 */
function contact_schema() {
  $schema['contact'] = array(
    'description' => 'Contact form category settings.',
    'fields' => array(
      'cid' => array(
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => 'Primary Key: Unique category ID.',
      ),
      'category' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Category name.',
      ),
      'recipients' => array(
        'type' => 'text',
        'not null' => TRUE,
        'size' => 'big',
        'description' => 'Comma-separated list of recipient e-mail addresses.',
      ),
      'reply' => array(
        'type' => 'text',
        'not null' => TRUE,
        'size' => 'big',
        'description' => 'Text of the auto-reply message.',
      ),
      'weight' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'size' => 'tiny',
        'description' => "The category's weight.",
      ),
      'selected' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'size' => 'tiny',
        'description' => 'Flag to indicate whether or not category is selected by default. (1 = Yes, 0 = No)',
      ),
    ),
    'primary key' => array(
      'cid',
    ),
    'unique keys' => array(
      'category' => array(
        'category',
      ),
    ),
    'indexes' => array(
      'list' => array(
        'weight',
        'category',
      ),
    ),
  );
  return $schema;
}

/**
 * Implements hook_install().
 */
function contact_install() {

  // Create tables.
  drupal_install_schema('contact');

  // Insert a default contact category.
  db_query("INSERT INTO {contact} (category, recipients, selected, reply) VALUES ('%s', '%s', %d, '%s')", 'Website feedback', variable_get('site_mail', ini_get('sendmail_from')), 1, 0);
}

/**
 * Implements hook_uninstall().
 */
function contact_uninstall() {

  // Remove tables.
  drupal_uninstall_schema('contact');
  variable_del('contact_default_status');
  variable_del('contact_form_information');
  variable_del('contact_hourly_threshold');
}

/**
 * Migrate contact information to a block.
 */
function contact_update_6200() {
  $themes_with_blocks = array();
  $query = db_query("SELECT DISTINCT(s.name) FROM {system} s INNER JOIN {blocks} b ON s.name = b.theme WHERE s.type = 'theme' GROUP by s.name");
  while ($theme = db_result($query)) {
    $themes_with_blocks[] = $theme;
  }

  // Migrate contact form information.
  $default_format = variable_get('filter_default_format', 1);
  if ($contact_help = variable_get('contact_form_information', '')) {
    $block = array(
      'body' => $contact_help,
      'info' => 'Contact page help',
      'format' => $default_format,
    );
    drupal_write_record('boxes', $block);
    foreach ($themes_with_blocks as $theme) {

      // Add contact help block for themes, which had blocks.
      $theme_block = array(
        'module' => 'block',
        'delta' => $block['bid'],
        'theme' => $theme,
        'status' => 1,
        'weight' => 5,
        'region' => '',
        'visibility' => 1,
        'pages' => 'contact',
        'cache' => -1,
      );
      drupal_write_record('blocks', $theme_block);
    }
    drupal_set_message('The contact form information setting was migrated to <a href="' . url('admin/build/block/configure/block/' . $block['bid']) . '">a custom block</a> and set up to only show on the site-wide contact page. It has not yet been assigned a region. The block was set to use the default text format, which might differ from the HTML based format used before. Check the block and ensure that the output is right.');
  }
  variable_del('contact_form_information');
  return array();
}

/**
 * Rename the threshold limit variable.
 */
function contact_update_7000() {
  variable_set('contact_threshold_limit', variable_get('contact_hourly_threshold', 5));
  variable_del('contact_hourly_threshold');
  return array();
}

/**
 * Rename the administer contact forms permission.
 */
function contact_update_7001() {
  $ret = array();
  $ret[] = update_sql("UPDATE {permission} SET perm = REPLACE(perm, 'administer site-wide contact form', 'administer contact forms')");
  return $ret;
}

/**
 * Enable the 'access user contact forms' for registered users by default.
 */
function contact_update_7002() {
  $ret = array();
  $ret[] = update_sql("UPDATE {permission} SET perm = CONCAT(perm, ', access user contact forms') WHERE perm NOT LIKE '%access user contact forms%' AND rid = " . DRUPAL_AUTHENTICATED_RID);
  return $ret;
}

Functions

Namesort descending Description
contact_install Implements hook_install().
contact_schema Implements hook_schema().
contact_uninstall Implements hook_uninstall().
contact_update_6200 Migrate contact information to a block.
contact_update_7000 Rename the threshold limit variable.
contact_update_7001 Rename the administer contact forms permission.
contact_update_7002 Enable the 'access user contact forms' for registered users by default.