You are here

mail_edit.install in Mail Editor 6

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

Install, update and uninstall functions for the Mail Editor module.

File

mail_edit.install
View source
<?php

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

/**
 * Implementation of hook_install().
 */
function mail_edit_install() {
  if (db_table_exists('mail_edit') && !db_table_exists('mail_edit_registry')) {

    // This must be a left-over from the (incompatible!) D5 version, see #318324.
    // Move the old table out of the way.
    $ret = array();
    db_rename_table($ret, 'mail_edit', 'mail_edit_d5');
    if ($ret[0]['success']) {
      watchdog('mail_edit', 'The %mail_edit table has been renamed to %mail_edit_d5.', array(
        '%mail_edit' => '{mail_edit}',
        '%mail_edit_d5' => '{mail_edit_d5}',
      ), WATCHDOG_NOTICE);
    }
  }
  drupal_install_schema('mail_edit');
}

/**
 * Implementation of hook_uninstall().
 */
function mail_edit_uninstall() {
  drupal_uninstall_schema('mail_edit');
}

/**
 * Implementation of hook_schema().
 */
function mail_edit_schema() {
  $schema['mail_edit'] = array(
    'description' => '',
    'fields' => array(
      'description' => array(
        'type' => 'varchar',
        'length' => '255',
        'not null' => TRUE,
        'description' => '',
      ),
      'subject' => array(
        'type' => 'varchar',
        'length' => '255',
        'not null' => TRUE,
        'description' => '',
      ),
      'id' => array(
        'type' => 'varchar',
        'length' => '255',
        'not null' => TRUE,
        'description' => '',
      ),
      'language' => array(
        'type' => 'varchar',
        'length' => '10',
        'not null' => TRUE,
        'description' => '',
      ),
      'body' => array(
        'type' => 'text',
        'size' => 'normal',
        'description' => '',
      ),
    ),
    'primary key' => array(
      'id',
      'language',
    ),
    'indexes' => array(
      'language' => array(
        'language',
      ),
    ),
  );
  $schema['mail_edit_registry'] = array(
    'description' => '',
    'fields' => array(
      'id' => array(
        'type' => 'varchar',
        'length' => '255',
        'not null' => TRUE,
        'description' => '',
      ),
      'module' => array(
        'type' => 'varchar',
        'length' => '255',
        'not null' => TRUE,
        'description' => '',
      ),
      'mailkey' => array(
        'type' => 'varchar',
        'length' => '255',
        'not null' => TRUE,
        'description' => '',
      ),
      'description' => array(
        'type' => 'varchar',
        'length' => '255',
        'not null' => TRUE,
        'description' => '',
      ),
    ),
    'primary key' => array(
      'id',
    ),
  );
  return $schema;
}

/**
 * Do one of two things to install on D6:
 *  -- If this is an upgrade from a 5.x-1.x installation:
 *     The D5 {mail_edit} table cannot be migrated to D6, so we move it away and do a full install.
 *     Modules that have used Mail Editor under D5 can pick up their old records from {mail_edit_D5}.
 *  -- If we already have an early 6.x-1.x installation, then fix the schema.
 */
function mail_edit_update_6000() {
  $ret = array();
  if (db_table_exists('mail_edit') && !db_table_exists('mail_edit_registry')) {

    // We have a D5 installation and need to move the old table out of the way.
    db_rename_table($ret, 'mail_edit', 'mail_edit_d5');
    if ($ret[0]['success']) {
      watchdog('mail_edit', 'The %mail_edit table has been renamed to %mail_edit_d5.', array(
        '%mail_edit' => '{mail_edit}',
        '%mail_edit_d5' => '{mail_edit_d5}',
      ), WATCHDOG_NOTICE);
    }

    // Now install the D6 schema as of update_6000.
    $schema['mail_edit'] = array(
      'description' => '',
      'fields' => array(
        'description' => array(
          'type' => 'varchar',
          'length' => '255',
          'not null' => TRUE,
          'description' => '',
        ),
        'subject' => array(
          'type' => 'varchar',
          'length' => '255',
          'not null' => TRUE,
          'description' => '',
        ),
        'id' => array(
          'type' => 'varchar',
          'length' => '255',
          'not null' => TRUE,
          'description' => '',
        ),
        'language' => array(
          'type' => 'varchar',
          'length' => '10',
          'not null' => TRUE,
          'description' => '',
        ),
        'body' => array(
          'type' => 'text',
          'size' => 'normal',
          'description' => '',
        ),
      ),
      'primary key' => array(
        'id',
        'language',
      ),
      'indexes' => array(
        'language' => array(
          'language',
        ),
      ),
    );
    $schema['mail_edit_registry'] = array(
      'description' => '',
      'fields' => array(
        'id' => array(
          'type' => 'varchar',
          'length' => '255',
          'not null' => TRUE,
          'description' => '',
        ),
        'module' => array(
          'type' => 'varchar',
          'length' => '255',
          'not null' => TRUE,
          'description' => '',
        ),
        'mailkey' => array(
          'type' => 'varchar',
          'length' => '255',
          'not null' => TRUE,
          'description' => '',
        ),
        'description' => array(
          'type' => 'varchar',
          'length' => '255',
          'not null' => TRUE,
          'description' => '',
        ),
      ),
      'primary key' => array(
        'id',
      ),
    );
    db_create_table($ret, 'mail_edit', $schema['mail_edit']);
    db_create_table($ret, 'mail_edit_registry', $schema['mail_edit_registry']);
  }
  else {

    // Fix the schema of the 2008-Oct-08 snapshot release.
    db_drop_index($ret, 'mail_edit', '`unique entry`');
    db_drop_index($ret, 'mail_edit', '`id`');
    db_add_primary_key($ret, 'mail_edit', array(
      'id',
      'language',
    ));
    db_add_primary_key($ret, 'mail_edit_registry', array(
      'id',
    ));
  }
  return $ret;
}

Functions

Namesort descending Description
mail_edit_install Implementation of hook_install().
mail_edit_schema Implementation of hook_schema().
mail_edit_uninstall Implementation of hook_uninstall().
mail_edit_update_6000 Do one of two things to install on D6: -- If this is an upgrade from a 5.x-1.x installation: The D5 {mail_edit} table cannot be migrated to D6, so we move it away and do a full install. Modules that have used Mail Editor under D5 can pick up their old…