You are here

maillog.install in Maillog / Mail Developer 7

Same filename and directory in other branches
  1. 8 maillog.install
  2. 6 maillog.install

Provides the installation routines for the maillog module.

File

maillog.install
View source
<?php

/**
 * @file
 * Provides the installation routines for the maillog module.
 */

/**
 * Implements hook_enable().
 */
function maillog_enable() {

  // The system default class.
  $default_class = 'DefaultMailSystem';

  // Load the current mail configuration.
  $mail_system = variable_get('mail_system', array(
    'default-system' => $default_class,
  ));
  $mail_system['maillog'] = 'MaillogMailSystem';

  // If maillog is enabled, don't take over the default.
  if ($mail_system['default-system'] == $default_class) {
    $mail_system['default-system'] = $mail_system['maillog'];
  }
  else {
    drupal_set_message(t('The Maillog module was not set as the default email system because another module is already handling email.'));
  }

  // Update the settings.
  variable_set('mail_system', $mail_system);

  // The maillog reports page is provided by a view, but it needs a menu cache
  // clear after the default views are loaded in order for the menu item to
  // become active.
  global $language;
  cache_clear_all('ctools_plugin_files:ctools:export_ui', 'cache');
  cache_clear_all('ctools_plugin_type_info', 'cache');
  cache_clear_all('views:plugin_data:' . $language->language, 'cache');
  variable_set('menu_rebuild_needed', TRUE);
}

/**
 * Implements hook_disable().
 */
function maillog_disable() {

  // Get the current mail system config.
  $mail_system = variable_get('mail_system', array(
    'default-system' => 'DefaultMailSystem',
  ));

  // Delete any overrides that might be set for Maillog.
  unset($mail_system['maillog']);

  // Revert the default config mail config if it is currently set to use
  // Maillog, and any others that are set to Maillog can be just deleted so they
  // revert to the default.
  $default_class = 'DefaultMailSystem';
  $maillog_class = 'MaillogMailSystem';
  foreach ($mail_system as $system => $class) {

    // Look for the default mail handler.
    if ($system == 'default-system') {

      // If this is currently using Maillog, revert it to the default class.
      if ($class == $maillog_class) {
        $mail_system[$system] = $default_class;
      }
    }
    elseif ($class == $maillog_class) {
      unset($mail_system[$system]);
    }
  }

  // Update the mail config.
  variable_set('mail_system', $mail_system);
}

/**
 * Implements hook_schema().
 */
function maillog_schema() {
  $schema['maillog'] = array(
    'description' => "Stores outgoing emails that are captured using the Maillog module.",
    'fields' => array(
      'id' => array(
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => "The primary key of this table.",
      ),
      'header_message_id' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => "The 'message-id' field of the e-mail.",
      ),
      'header_from' => array(
        'type' => 'text',
        'not null' => TRUE,
        'description' => "The 'From' field of the e-mail.",
      ),
      'header_to' => array(
        'type' => 'text',
        'not null' => TRUE,
        'description' => "The 'To' field of the e-mail.",
      ),
      'header_reply_to' => array(
        'type' => 'text',
        'not null' => TRUE,
        'description' => "The 'Reply-To' field of the e-mail.",
      ),
      'header_all' => array(
        'type' => 'text',
        'not null' => TRUE,
        'description' => "The 'Header' field of the e-mail.",
      ),
      'subject' => array(
        'description' => "The 'Subject' field of the e-mail.",
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'body' => array(
        'description' => 'The body of this message.',
        'type' => 'text',
        'not null' => TRUE,
        'size' => 'big',
      ),
      'sent_date' => array(
        'description' => 'The Unix timestamp when the mail was sent.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'id',
    ),
  );
  return $schema;
}

/**
 * Implements hook_uninstall().
 */
function maillog_uninstall() {
  variable_del('maillog_devel');
  variable_del('maillog_log');
  variable_del('maillog_send');
  variable_del('maillog_engine');
}

/**
 * Implementations of hook_update_N().
 */

/**
 * Rename the 'idmaillog' field to just 'id'.
 */
function maillog_update_7100() {
  if (!db_field_exists('maillog', 'id')) {

    // Add the new 'id' field.
    $spec = array(
      'type' => 'int',
      'not null' => TRUE,
      'unsigned' => TRUE,
      'default' => 0,
      'description' => "The primary key of this table.",
    );
    db_add_field('maillog', 'id', $spec);

    // Fill in all of the 'id' fields.
    db_query("UPDATE {maillog} SET id=idmaillog");

    // Drop the 'idmaillog' field
    db_drop_field('maillog', 'idmaillog');

    // Change the 'id' field to a serial.
    $spec = array(
      'type' => 'serial',
      'unsigned' => TRUE,
      'not null' => TRUE,
      'description' => "The primary key of this table.",
    );
    $keys = array(
      'primary key' => array(
        'id',
      ),
    );
    db_change_field('maillog', 'id', 'id', $spec, $keys);
  }
}

/**
 * Clear the menu cache so the new paths will be picked up.
 */
function maillog_update_7101() {
  variable_set('menu_rebuild_needed', TRUE);
}

/**
 * Clear the Views cache so the updated admin page will get the new paths.
 */
function maillog_update_7102() {
  cache_clear_all('*', 'cache_views', TRUE);
  cache_clear_all('*', 'cache_views_data', TRUE);
}

Functions

Namesort descending Description
maillog_disable Implements hook_disable().
maillog_enable Implements hook_enable().
maillog_schema Implements hook_schema().
maillog_uninstall Implements hook_uninstall().
maillog_update_7100 Rename the 'idmaillog' field to just 'id'.
maillog_update_7101 Clear the menu cache so the new paths will be picked up.
maillog_update_7102 Clear the Views cache so the updated admin page will get the new paths.