You are here

mail_logger.install in Mail Logger 6

Same filename and directory in other branches
  1. 5 mail_logger.install
  2. 7 mail_logger.install

Install and update functions for Mail Logger module.

File

mail_logger.install
View source
<?php

/**
 * @file
 * Install and update functions for Mail Logger module.
 */

/**
 * Implementation of hook_schema().
 */
function mail_logger_schema() {
  $schema = array();
  $schema['mail_logger'] = array(
    'description' => 'Mail Logger table stores outgoing mails',
    'fields' => array(
      'mlid' => array(
        'description' => 'Mail Logger entry ID',
        'type' => 'serial',
        'not null' => TRUE,
        'unsigned' => TRUE,
      ),
      'mailkey' => array(
        'description' => 'a key identifying the mail type',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'mail_to' => array(
        'description' => 'to whom this mail is going',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'subject' => array(
        'description' => 'Mail subject',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'body' => array(
        'description' => 'Body text of the mail',
        'type' => 'text',
        'not null' => TRUE,
        'size' => 'big',
      ),
      'mail_from' => array(
        'description' => 'the FROM email address',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'headers' => array(
        'description' => 'Headers of the outgoing mail',
        'type' => 'text',
        'not null' => TRUE,
        'size' => 'big',
      ),
      'date_sent' => array(
        'description' => 'Mail Logger entry ID',
        'type' => 'int',
        'not null' => TRUE,
        'unsigned' => TRUE,
      ),
      'language' => array(
        'description' => 'Language code',
        'type' => 'varchar',
        'length' => 20,
        'not null' => TRUE,
      ),
    ),
    'primary key' => array(
      'mlid',
    ),
    'indexes' => array(
      'mail_to' => array(
        'mail_to',
      ),
      'mail_from' => array(
        'mail_from',
      ),
      'subject' => array(
        array(
          'subject',
          20,
        ),
      ),
      'date_sent' => array(
        'date_sent',
      ),
      'language' => array(
        'language',
      ),
    ),
  );
  return $schema;
}

/**
 * Implementation of hook_install().
 */
function mail_logger_install() {
  drupal_install_schema('mail_logger');
}

/**
 * Implementation of hook_uninstall().
 */
function mail_logger_uninstall() {
  drupal_uninstall_schema('mail_logger');
}

/**
 * Implementation of hook_enable().
 */
function mail_logger_enable() {

  // Because modules can modify the outgoing mail, mail_logger must be executed last in order to capture
  // the final mail parameters by setting the weight of mail_logger to something large.
  $max_weight = db_result(db_query("SELECT max(weight) FROM {system} WHERE name <> 'mail_logger'"));
  db_query("UPDATE {system} SET weight = %d WHERE name = 'mail_logger'", $max_weight + 100);
}

/**
 * Add language field to the mail_logger table to support upgrading from Drupal 5.
 */
function mail_logger_update_6000() {
  $ret = array();
  if (!db_column_exists('mail_logger', 'language')) {
    db_add_field($ret, 'mail_logger', 'language', array(
      'description' => t('Language code'),
      'type' => 'varchar',
      'length' => 20,
      'not null' => TRUE,
    ));
    db_add_index($ret, 'mail_logger', 'language', array(
      'language',
    ));
  }
  return $ret;
}

/**
 * Rename the 'to' and 'from' columns to avoid using MySQL reserved keywords.
 */
function mail_logger_update_6001() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("ALTER TABLE {mail_logger} CHANGE COLUMN `to`   mail_to   varchar (255) NOT NULL");
      $ret[] = update_sql("ALTER TABLE {mail_logger} CHANGE COLUMN `from` mail_from varchar (255) NOT NULL");
      break;
    case 'pgsql':
      db_change_column($ret, 'mail_logger', 'to', 'mail_to', 'varchar', array(
        'not null' => TRUE,
      ));
      db_change_column($ret, 'mail_logger', 'from', 'mail_from', 'varchar', array(
        'not null' => TRUE,
      ));
      break;
  }

  // Remake the indexes on the two changed columns.
  // The backticks ` are needed to protect the MySQL reserved keywords.
  db_drop_index($ret, 'mail_logger', '`to`');
  db_drop_index($ret, 'mail_logger', '`from`');
  db_add_index($ret, 'mail_logger', 'mail_to', array(
    'mail_to',
  ));
  db_add_index($ret, 'mail_logger', 'mail_from', array(
    'mail_from',
  ));
  return $ret;
}

Functions

Namesort descending Description
mail_logger_enable Implementation of hook_enable().
mail_logger_install Implementation of hook_install().
mail_logger_schema Implementation of hook_schema().
mail_logger_uninstall Implementation of hook_uninstall().
mail_logger_update_6000 Add language field to the mail_logger table to support upgrading from Drupal 5.
mail_logger_update_6001 Rename the 'to' and 'from' columns to avoid using MySQL reserved keywords.