You are here

mailing_list.install in Mailing List 6

Same filename and directory in other branches
  1. 7 mailing_list.install

Install and update functions for mailing_list.

File

mailing_list.install
View source
<?php

/**
 * @file
 * Install and update functions for mailing_list.
 */

/**
 * Implementation of hook_install().
 */
function mailing_list_install() {
  drupal_install_schema('mailing_list');
}

/**
 * Implementation of hook_uninstall().
 */
function mailing_list_uninstall() {
  drupal_uninstall_schema('mailing_list');
  db_query("DELETE FROM {blocks} WHERE module = 'mailing_list'");
}

/**
 * Implementation of hook_schema().
 */
function mailing_list_schema() {
  $schema = array();
  $schema['mailing_list'] = array(
    'description' => t('A mailing list consisting of names and e-mails.'),
    'fields' => array(
      'mlid' => array(
        'description' => 'The primary identifier for a mailing list.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'name' => array(
        'description' => t('The title of this mailing list.'),
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
    ),
    'primary key' => array(
      'mlid',
    ),
    'indexes' => array(
      'name' => array(
        'name',
      ),
    ),
  );
  $schema['mailing_list_emails'] = array(
    'description' => t('An e-mail in a mailing list.'),
    'fields' => array(
      'eid' => array(
        'description' => 'The primary identifier for a mailing list e-mail.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'mlid' => array(
        'description' => t('The {mailing_list} this e-mail belongs to.'),
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'mail' => array(
        'description' => t('The e-mail of this subscriber.'),
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'name' => array(
        'description' => t('The name of this subscriber.'),
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
    ),
    'primary key' => array(
      'eid',
    ),
    'indexes' => array(
      'mlid' => array(
        'mlid',
      ),
      'name' => array(
        'name',
      ),
      'mail' => array(
        'mail',
      ),
    ),
    'unique keys' => array(
      'mlid_mail' => array(
        'mlid',
        'mail',
      ),
    ),
  );
  return $schema;
}

/**
 * Update mailing lists to allow subscriber names (not just e-mails), and clean
 * up field names.
 */
function mailing_list_update_6000() {
  $ret = array();
  db_change_field($ret, 'mailing_list', 'id', 'mlid', array(
    'type' => 'serial',
    'unsigned' => TRUE,
    'not null' => TRUE,
  ));
  db_change_field($ret, 'mailing_list', 'list', 'name', array(
    'type' => 'varchar',
    'length' => 255,
    'not null' => TRUE,
  ), array(
    'indexes' => array(
      'name' => array(
        'name',
      ),
    ),
  ));
  db_change_field($ret, 'mailing_list_emails', 'id', 'eid', array(
    'type' => 'serial',
    'unsigned' => TRUE,
    'not null' => TRUE,
  ));
  db_change_field($ret, 'mailing_list_emails', 'mailing_list_id', 'mlid', array(
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 0,
  ), array(
    'indexes' => array(
      'mlid' => array(
        'mlid',
      ),
    ),
  ));
  db_change_field($ret, 'mailing_list_emails', 'email', 'mail', array(
    'type' => 'varchar',
    'length' => 255,
    'not null' => TRUE,
  ), array(
    'indexes' => array(
      'mail' => array(
        'mail',
      ),
    ),
    'unique keys' => array(
      'mlid_mail' => array(
        'mlid',
        'mail',
      ),
    ),
  ));
  db_add_field($ret, 'mailing_list_emails', 'name', array(
    'type' => 'varchar',
    'not null' => TRUE,
    'length' => 255,
  ), array(
    'indexes' => array(
      'name' => array(
        'name',
      ),
    ),
  ));
  $ret[] = update_sql("DELETE FROM {permission} WHERE perm = 'export mailing list'");
  $result = db_query("SELECT rid, perm FROM {permission} WHERE perm = 'administer mailing list' ORDER BY rid");
  while ($role = db_fetch_object($result)) {
    $ret[] = update_sql("UPDATE {permission} SET perm = 'administer mailing lists' WHERE rid = {$role->rid}");
  }
  return $ret;
}

Functions

Namesort descending Description
mailing_list_install Implementation of hook_install().
mailing_list_schema Implementation of hook_schema().
mailing_list_uninstall Implementation of hook_uninstall().
mailing_list_update_6000 Update mailing lists to allow subscriber names (not just e-mails), and clean up field names.