You are here

simplenews.install in Simplenews 6.2

Simplenews installation.

File

simplenews.install
View source
<?php

/**
 * @file
 * Simplenews installation.
 */

/**
 * Implementation of hook_requirements().
 */
function simplenews_requirements($phase) {
  $requirements = array();
  $t = get_t();

  // Report if token module got missing (e.g. after 6--1 to 6--2 upgrade)
  if ($phase == 'runtime') {
    if (!module_exists('token')) {
      $requirements['simplenews_token'] = array(
        'title' => $t('Simplenews'),
        'value' => l($t('token.module missing'), 'http://drupal.org/project/token'),
        'description' => $t("Simplenews is broken if token.module is missing. This could happen after 6.x-1.x upgrade to 6.x-2.x upgrade since token is a new dependency and Drupal 6 core doesn't check for presence. Please install token.module immediately since all sending processes are broken."),
        'severity' => REQUIREMENT_ERROR,
      );
    }
  }
  return $requirements;
}

/**
 * Implementation of hook_schema().
 */
function simplenews_schema() {
  $schema['simplenews_subscriptions'] = array(
    'description' => 'Subscribers to {simplenews_newsletters}.',
    'fields' => array(
      'snid' => array(
        'description' => 'Primary key: Unique subscription ID.',
        'type' => 'serial',
        'not null' => TRUE,
      ),
      'activated' => array(
        'description' => 'Boolean indicating the status of the subscription.',
        'type' => 'int',
        'size' => 'tiny',
        'not null' => TRUE,
        'default' => 0,
      ),
      'mail' => array(
        'description' => 'The subscription email address.',
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
        'default' => '',
      ),
      'uid' => array(
        'description' => 'The {users}.uid that has the same email address.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'language' => array(
        'type' => 'varchar',
        'length' => 12,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Anonymous subscriber preferred language. Empty for authenticated users.',
      ),
      'timestamp' => array(
        'description' => 'UNIX timestamp of when the user first subscribed to a newsletter.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'indexes' => array(
      'mail' => array(
        'mail',
      ),
      'uid' => array(
        'uid',
      ),
    ),
    'primary key' => array(
      'snid',
    ),
  );
  $schema['simplenews_newsletters'] = array(
    'description' => 'Simplenews newsletter data.',
    'fields' => array(
      'nid' => array(
        'description' => '{node} that is used as newsletter.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'vid' => array(
        'description' => 'The {node}.vid that identifies the version used as newsletter.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'tid' => array(
        'description' => 'The {term_data}.tid (= newsletter series) this issue belongs to.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      's_status' => array(
        'description' => 'Sent status of the newsletter issue (0 = not send; 1 = pending; 2 = send). ',
        'type' => 'int',
        'size' => 'tiny',
        'not null' => TRUE,
        'default' => 0,
      ),
      's_format' => array(
        'description' => 'Format of the newsletter (plain or html).',
        'type' => 'varchar',
        'length' => 8,
        'not null' => TRUE,
        'default' => '',
      ),
      'priority' => array(
        'description' => 'Email priority according to RFC 2156 and RFC 5231 (0 = none; 1 = highest; 2 = high; 3 = normal; 4 = low; 5 = lowest).',
        'type' => 'int',
        'size' => 'tiny',
        'not null' => TRUE,
        'default' => 0,
      ),
      'receipt' => array(
        'description' => 'Boolean indicating request for email receipt confirmation according to RFC 2822.',
        'type' => 'int',
        'size' => 'tiny',
        'not null' => TRUE,
        'default' => 0,
      ),
      'sent_subscriber_count' => array(
        'description' => 'The count of subscribers to the newsletter when it was sent.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'nid',
    ),
  );
  $schema['simplenews_snid_tid'] = array(
    'description' => 'Newsletter series subscription data.',
    'fields' => array(
      'snid' => array(
        'description' => 'The {simplenews_subscriptions}.snid who is subscribed.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'tid' => array(
        'description' => 'The newsletter series ({term_data}.tid) the subscriber is subscribed to.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'status' => array(
        'description' => 'A flag indicating whether the user is subscribed (1) or unsubscribed (0).',
        'type' => 'int',
        'size' => 'small',
        'not null' => TRUE,
        'default' => 1,
      ),
      'timestamp' => array(
        'description' => 'UNIX timestamp of when the user is (un)subscribed.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'source' => array(
        'description' => 'The source via which the user is (un)subscription.',
        'type' => 'varchar',
        'length' => 24,
        'not null' => TRUE,
        'default' => '',
      ),
    ),
    'primary key' => array(
      'snid',
      'tid',
    ),
  );
  $schema['simplenews_mail_spool'] = array(
    'description' => 'Spool for temporary storage of newsletter emails.',
    'fields' => array(
      'msid' => array(
        'description' => 'The primary identifier for a mail spool record.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'snid' => array(
        'description' => 'Foreign key for subscriber table ({simplenews_subscriptions}.snid)',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'mail' => array(
        'description' => 'The formatted email address of mail message recipient.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'nid' => array(
        'description' => 'The {node}.nid of this newsletter.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'vid' => array(
        'description' => 'The {node}.vid of this newsletter.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'tid' => array(
        'description' => 'The {term_data}.tid this newsletter issue belongs to.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'status' => array(
        'description' => 'The sent status of the email (0 = hold, 1 = pending, 2 = done).',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'size' => 'tiny',
      ),
      'error' => array(
        'description' => 'A boolean indicating whether an error occurred while sending the email.',
        'type' => 'int',
        'size' => 'tiny',
        'not null' => TRUE,
        'default' => 0,
      ),
      'timestamp' => array(
        'description' => 'The time status was set or changed.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'msid',
    ),
    'indexes' => array(
      'tid' => array(
        'tid',
      ),
      'status' => array(
        'status',
      ),
    ),
  );
  return $schema;
}

/**
 * Implementation of hook_install().
 */
function simplenews_install() {
  if (drupal_install_schema('simplenews')) {
    if (module_exists('help')) {
      drupal_set_message(t('Simplenews installation instructions are available on the <a href="!simplenews_help">Simplenews help page</a>.', array(
        '!simplenews_help' => url('admin/help/simplenews'),
      )));
    }
    else {
      drupal_set_message(t('Simplenews was successfully installed.'));
    }
  }
  else {
    drupal_set_message(t('The installation of Simplenews was not successful.'), 'error');
  }
  _simplenews_install_nodetype();
  variable_set('simplenews_content_types', array(
    'simplenews' => 'simplenews',
  ));
  _simplenews_install_vocabulary();
}

/**
 * Implementation of hook_uninstall().
 */
function simplenews_uninstall() {
  drupal_uninstall_schema('simplenews');
  db_query("\n    DELETE FROM {variable}\n    WHERE name LIKE 'simplenews_%%'");
}

/**
 * Create simplenews node type.
 */
function _simplenews_install_nodetype() {

  // Create a newsletter type. If exists, modify it.
  if ($type = node_get_types('type', 'simplenews')) {
    $type->module = 'node';
    $type->locked = FALSE;
    $type->custom = TRUE;
    node_type_save($type);
  }
  else {
    $info = array(
      'type' => 'simplenews',
      'name' => t('Newsletter issue'),
      'module' => 'node',
      'description' => t('A newsletter issue to be sent to subscribed email addresses.'),
      'locked' => FALSE,
      'custom' => TRUE,
    );
    $info = _node_type_set_defaults($info);
    node_type_save((object) $info);
  }
}

/**
 * Create simplenews vocabulary and initial term.
 */
function _simplenews_install_vocabulary() {

  // Create the simplenews vocabulary. If it exists, set it as the simplenews_vid.
  if ($vocabulary = db_fetch_array(db_query("\n    SELECT *\n    FROM {vocabulary}\n    WHERE name = '%s'", t('Newsletter')))) {
    $vocabulary['nodes'] = variable_get('simplenews_content_types', array(
      'simplenews' => 'simplenews',
    ));
  }
  else {
    $vocabulary = array(
      'name' => t('Newsletter'),
      'multiple' => '0',
      'required' => '1',
      'hierarchy' => '0',
      'relations' => '0',
      'module' => 'simplenews',
      'nodes' => variable_get('simplenews_content_types', array(
        'simplenews' => 'simplenews',
      )),
    );
  }
  taxonomy_save_vocabulary($vocabulary);
  variable_set('simplenews_vid', $vocabulary['vid']);

  // Check to see if at least 1 term exists, else create one
  $tid = db_result(db_query('
    SELECT tid
    FROM {term_data}
    WHERE vid = %d', $vocabulary['vid']));
  if (!$tid) {
    $form_values = array(
      'name' => t('@site_name newsletter', array(
        '@site_name' => variable_get('site_name', 'Drupal'),
      )),
      'vid' => $vocabulary['vid'],
      'weight' => 0,
    );
    switch (taxonomy_save_term($form_values)) {
      case SAVED_UPDATED:
        drupal_set_message(t('Updated term %name.', array(
          '%name' => $form_values['name'],
        )));
        break;
      case SAVED_DELETED:
        drupal_set_message(t('Deleted term %name.', array(
          '%name' => $form_values['name'],
        )));
        break;
    }
  }
}

/**
 * Rename sn_* tables to simplenews_* to avoid namespace conflicts.
 */
function simplenews_update_2() {
  $ret = array();
  db_rename_table($ret, 'sn_snid_tid', 'simplenews_snid_tid');
  db_rename_table($ret, 'sn_newsletters', 'simplenews_newsletters');
  db_rename_table($ret, 'sn_subscriptions', 'simplenews_subscriptions');
  return $ret;
}

/**
 * Add index to simplenews_subscriptions.
 */
function simplenews_update_5000() {
  $ret = array();
  db_add_index($ret, 'simplenews_subscriptions', 'mail', array(
    'mail',
  ));
  return $ret;
}

/**
 * Addition of node version to simplenews_newsletters in order to record the
 * node version which is being send.
 */
function simplenews_update_5001() {
  $ret = array();
  db_add_field($ret, 'simplenews_newsletters', 'vid', array(
    'type' => 'int',
    'type' => 'int',
    'not null' => TRUE,
    'default' => 0,
  ));
  return $ret;
}

/**
 * Data conversion of block delta.
 * Field type conversions: newsletter priority.
 * Field name change in simplenews_subscriptions table.
 */
function simplenews_update_6000() {
  $ret = array();

  // Convert the block delta: remove 'newsletter-' prefix from the delta.
  $result = db_query("\n    SELECT module, delta\n    FROM {blocks}\n    WHERE module = 'simplenews'\n      AND delta LIKE 'newsletter-%'");
  while ($data = db_fetch_object($result)) {
    $delta = strtr($data->delta, array(
      'newsletter-' => '',
    ));
    $ret[] = update_sql("\n      UPDATE {blocks}\n      SET delta = '%s'\n      WHERE module = 'simplenews'\n        AND delta = 'newsletter-%s'", $delta, $delta);
  }
  $result = db_query("\n    SELECT module, delta\n    FROM {blocks_roles}\n    WHERE module = 'simplenews'\n      AND delta LIKE 'newsletter-%'");
  while ($data = db_fetch_object($result)) {
    $delta = strtr($data->delta, array(
      'newsletter-' => '',
    ));
    $ret[] = update_sql("\n      UPDATE {blocks_roles}\n      SET delta = '%s'\n      WHERE module = 'simplenews'\n        AND delta = 'newsletter-%s'", $delta, $delta);
  }

  // Convert newsletter priority: change field type int to string
  db_change_field($ret, 'simplenews_newsletters', 'priority', 'priority', array(
    'type' => 'varchar',
    'length' => 8,
    'not null' => TRUE,
    'default' => '',
  ));

  // Convert subscription field name: change a_status to activated
  db_change_field($ret, 'simplenews_subscriptions', 'a_status', 'activated', array(
    'type' => 'int',
    'size' => 'tiny',
    'not null' => TRUE,
    'default' => 0,
  ));

  // Convert subscription field name: change s_status to is_send
  db_change_field($ret, 'simplenews_subscriptions', 's_status', 'is_send', array(
    'type' => 'int',
    'size' => 'tiny',
    'not null' => TRUE,
    'default' => 0,
  ));
  return $ret;
}

/**
 * Addition of simplenews_mail_cache table.
 * Related to this new table: the removal of simplenews_subscriptions is_send
 * status.
 * Correction of simplenews_newsletters priority field type.
 */
function simplenews_update_6001() {
  $schema['simplenews_mail_cache'] = array(
    'description' => '',
    'fields' => array(
      'mcid' => array(
        'description' => 'The primary identifier for a mail cache record.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'tid' => array(
        'description' => 'The {term_data}.tid this newsletter issue belongs to.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'subject' => array(
        'description' => 'The subject of this mail message.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'mail' => array(
        'description' => 'The formatted email address of mail message recipient.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'status' => array(
        'description' => 'The sent status of the email (0 = hold, 1 = pending, 2 = send).',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'size' => 'tiny',
      ),
      'timestamp' => array(
        'description' => 'The time status was set or changed.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'message' => array(
        'description' => 'The mail message array.',
        'type' => 'blob',
        'not null' => FALSE,
        'size' => 'big',
      ),
    ),
    'primary key' => array(
      'mcid',
    ),
    'indexes' => array(
      'tid' => array(
        'tid',
      ),
      'status' => array(
        'status',
      ),
    ),
  );
  $ret = array();

  // New table to buffer mail messages during sending
  db_create_table($ret, 'simplenews_mail_cache', $schema['simplenews_mail_cache']);

  // Remove is_send field. No longer required by the introduction of simplenews_mail_cache table
  db_drop_field($ret, 'simplenews_subscriptions', 'is_send');

  // Convert newsletter priority: change field type string back to int
  db_change_field($ret, 'simplenews_newsletters', 'priority', 'priority', array(
    'type' => 'int',
    'size' => 'tiny',
    'not null' => TRUE,
    'default' => 0,
  ));
  return $ret;
}

/**
 * Addition of node version to simplenews_newsletters in order to record the
 * node version which is being send.
 * Addition of nid to simplenews_mail_cache to be able to check the newsletter
 * sent status.
 */
function simplenews_update_6002() {
  $ret = array();
  db_add_field($ret, 'simplenews_mail_cache', 'nid', array(
    'type' => 'int',
    'not null' => TRUE,
    'default' => 0,
  ));
  variable_del('simplenews_time');
  return $ret;
}

/**
 * Addition of index to uid in simplenews_subscriptions.
 */
function simplenews_update_6003() {
  $ret = array();
  db_add_index($ret, 'simplenews_subscriptions', 'uid', array(
    'uid',
  ));
  return $ret;
}

/**
 * Add spool table and remove cache table.
 */
function simplenews_update_6004() {
  $schema['simplenews_mail_spool'] = array(
    'description' => 'Spool for temporary storage of newsletter emails.',
    'fields' => array(
      'msid' => array(
        'description' => 'The primary identifier for a mail spool record.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'mail' => array(
        'description' => 'The formatted email address of mail message recipient.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'nid' => array(
        'description' => 'The {node}.nid of this newsletter.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'vid' => array(
        'description' => 'The {node}.vid of this newsletter.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'tid' => array(
        'description' => 'The {term_data}.tid this newsletter issue belongs to.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'status' => array(
        'description' => 'The sent status of the email (0 = hold, 1 = pending, 2 = send).',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'size' => 'tiny',
      ),
      'timestamp' => array(
        'description' => 'The time status was set or changed.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'msid',
    ),
    'indexes' => array(
      'tid' => array(
        'tid',
      ),
      'status' => array(
        'status',
      ),
    ),
  );
  $ret = array();

  // New table to buffer mail messages during sending
  db_create_table($ret, 'simplenews_mail_spool', $schema['simplenews_mail_spool']);
  db_drop_table($ret, 'simplenews_mail_cache');
  return $ret;
}

/**
 * Add language field to subscription table and set language of existing subscribers.
 */
function simplenews_update_6005() {
  $ret = array();
  db_add_field($ret, 'simplenews_subscriptions', 'language', array(
    'type' => 'varchar',
    'length' => 12,
    'not null' => TRUE,
    'default' => '',
    'description' => 'Subscriber preferred language.',
  ));

  // Set preferred language for all current none anonymous subscribers.
  $result = db_query('
    SELECT s.snid, u.language
    FROM {simplenews_subscriptions} s
    INNER JOIN {users} u
      ON u.uid = s.uid
    WHERE s.uid > %d', 0);
  while ($subscriber = db_fetch_object($result)) {
    $ret[] = update_sql("\n      UPDATE {simplenews_subscriptions}\n      SET language = '%s'\n      WHERE snid = %d", $subscriber->language, $subscriber->snid);
  }
  return $ret;
}

/**
 * Make the simplenews content type a custom type.
 */
function simplenews_update_6006() {
  $ret = array();

  // Convert existing node type or re-create it.
  // If _node_types_build() if called before update, the simplenews
  // node type gets deleted because simplenews_node_info() no longer exists.
  // In that case we re-create the node type.
  if ($type = node_get_types('type', 'simplenews')) {
    $type->module = 'node';
    $type->locked = FALSE;
    $type->custom = TRUE;
    node_type_save($type);
  }
  else {
    _simplenews_install_nodetype();
  }
  return $ret;
}

/**
 * Rename old permissions.
 */
function simplenews_update_6007() {
  $ret = array();
  $result = db_query("\n    SELECT rid, perm\n    FROM {permission}\n    ORDER BY rid");
  while ($role = db_fetch_object($result)) {
    $patterns = array(
      '/create newsletter/',
      '/edit own newsletter/',
      '/edit any newsletter/',
      '/delete own newsletter/',
      '/delete any newsletter/',
    );
    $replacements = array(
      'create simplenews content',
      'edit own simplenews content',
      'edit any simplenews content',
      'delete own simplenews content',
      'delete any simplenews content',
    );
    $renamed_permission = preg_replace($patterns, $replacements, $role->perm);
    if ($renamed_permission != $role->perm) {
      $ret[] = update_sql("\n        UPDATE {permission}\n        SET perm = '{$renamed_permission}'\n        WHERE rid = {$role->rid}");
    }
  }
  return $ret;
}

/**
 * Make vocabulary required.
 */
function simplenews_update_6008() {
  $vocabulary = (array) taxonomy_vocabulary_load(variable_get('simplenews_vid', ''));
  $vocabulary['required'] = TRUE;
  taxonomy_save_vocabulary($vocabulary);
  return array();
}

/**
 * Add (un)subscription data to table simplenews_snid_tid.
 */
function simplenews_update_6100() {
  $ret = array();
  db_add_field($ret, 'simplenews_snid_tid', 'status', array(
    'description' => 'A flag indicating whether the user is subscribed (1) or unsubscribed (0).',
    'type' => 'int',
    'size' => 'small',
    'not null' => TRUE,
    'default' => 1,
  ));
  db_add_field($ret, 'simplenews_snid_tid', 'timestamp', array(
    'description' => 'UNIX timestamp of when the user is (un)subscribed.',
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 0,
  ));
  db_add_field($ret, 'simplenews_snid_tid', 'source', array(
    'description' => 'The source via which the user is (un)subscription.',
    'type' => 'varchar',
    'length' => 24,
    'not null' => TRUE,
    'default' => '',
  ));
  return $ret;
}

/**
 * Convert Simplenews custom tokens to Token tokens.
 */
function simplenews_update_6101() {
  $ret = array();
  $old = array(
    '!site',
    '!mailto',
    '!date',
    '!login_uri',
    '!uri',
    '!confirm_subscribe_url',
    '!confirm_unsubscribe_url',
    '!newsletter_url',
    '!newsletter_name',
  );
  $new = array(
    '[site-name]',
    '[user-mail]',
    '[site-date]',
    '[site-url]/user',
    '[site-url]',
    '[simplenews-subscribe-url]',
    '[simplenews-unsubscribe-url]',
    '[simplenews-newsletter-url]',
    '[simplenews-newsletters-name]',
  );
  $variables = array(
    'simplenews_confirm_subscribe_subject',
    'simplenews_confirm_subscribe_unsubscribed',
    'simplenews_confirm_subscribe_subscribed',
    'simplenews_confirm_unsubscribe_subscribed',
    'simplenews_confirm_unsubscribe_unsubscribed',
  );
  foreach ($variables as $variable) {
    if ($text = variable_get($variable, FALSE)) {
      $text = str_replace($old, $new, $text);
      variable_set($variable, $text);
    }
  }
  drupal_set_message(t('Simplenews custom tokens have been deprecated. An attempt was made to replace custom tokens in the confirmation messages. Check the messages at <a href="!url">Simplenews subscription settings</a>. Manually replace Simplenews tokens in (unsent) newsletter issues.', array(
    '!url' => url('admin/settings/simplenews/subscription'),
  )));
  return $ret;
}

/**
 * Dummy update for compatibility with HEAD
 *
 * Accidentally added in DRUPAL-6--1-1 branch already.
 * Continuing with 6200 numbers!
 */
function simplenews_update_6200() {
  return array();
}

/**
 * Correction of field size mismatch caused by simplenews_update_6009().
 */
function simplenews_update_6201() {
  $ret = array();
  db_change_field($ret, 'simplenews_mail_spool', 'error', 'error', array(
    'type' => 'int',
    'size' => 'tiny',
    'not null' => TRUE,
    'default' => 0,
  ));
  return $ret;
}

/**
 * Add fields 'status', 'timestamp', 'source' to 'simplenews_snid_tid' table.
 *
 * First update of DRUPAL-6--2 branch.
 */
function simplenews_update_6251() {
  $ret = array();
  db_add_field($ret, 'simplenews_snid_tid', 'status', array(
    'description' => 'A flag indicating whether the user is subscribed (1) or unsubscribed (0).',
    'type' => 'int',
    'size' => 'small',
    'not null' => TRUE,
    'default' => 1,
  ));
  db_add_field($ret, 'simplenews_snid_tid', 'timestamp', array(
    'description' => 'UNIX timestamp of when the user is (un)subscribed.',
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 0,
  ));
  db_add_field($ret, 'simplenews_snid_tid', 'source', array(
    'description' => 'The source via which the user is (un)subscription.',
    'type' => 'varchar',
    'length' => 24,
    'not null' => TRUE,
    'default' => '',
  ));
  return $ret;
}

/**
 * Add 'sent_subscriber_count' field to 'simplenews_newsletters' table.
 */
function simplenews_update_6252() {
  $ret = array();
  db_add_field($ret, 'simplenews_newsletters', 'sent_subscriber_count', array(
    'description' => 'The count of subscribers to the newsletter when it was sent.',
    'type' => 'int',
    'not null' => TRUE,
    'default' => 0,
  ));
  db_query("\n    UPDATE {simplenews_newsletters} sn\n    SET sent_subscriber_count = (\n      SELECT count(tid)\n      FROM {simplenews_snid_tid} AS sst\n      INNER JOIN {simplenews_subscriptions} AS ss\n        ON sst.snid = ss.snid\n      WHERE tid = sn.tid\n        AND ss.activated = %d\n    )", SIMPLENEWS_SUBSCRIPTION_STATUS_SUBSCRIBED);
  return $ret;
}

/**
 * Add timestamp field to simplenews subscriptions table.
 * Port timestamps from `simplenews_snid_tid` table to `simplenews_subscriptions`
 */
function simplenews_update_6253() {
  $ret = array();
  db_add_field($ret, 'simplenews_subscriptions', 'timestamp', array(
    'description' => 'UNIX timestamp of when the user first subscribed to a newsletter.',
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 0,
  ));

  // http://dev.mysql.com/doc/refman/5.1/en/correlated-subqueries.html
  // this subquery already works with mysql 4.
  db_query("\n    UPDATE {simplenews_subscriptions} s\n    SET s.timestamp = (\n      SELECT MIN(timestamp)\n      FROM {simplenews_snid_tid}\n      WHERE snid = s.snid\n    )");
  return $ret;
}

/**
 * Add snid field to simplenews spool table.
 */
function simplenews_update_6254() {
  $ret = array();
  db_add_field($ret, 'simplenews_mail_spool', 'snid', array(
    'description' => 'Foreign key for subscriber table ({simplenews_subscriptions}.snid)',
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 0,
  ));

  // populate snid for previous mail spool entries
  db_query("\n    UPDATE {simplenews_mail_spool} s\n    SET s.snid = (\n      SELECT snid\n      FROM {simplenews_subscriptions}\n      WHERE mail = s.mail\n      LIMIT 1\n    )");
  return $ret;
}

Functions

Namesort descending Description
simplenews_install Implementation of hook_install().
simplenews_requirements Implementation of hook_requirements().
simplenews_schema Implementation of hook_schema().
simplenews_uninstall Implementation of hook_uninstall().
simplenews_update_2 Rename sn_* tables to simplenews_* to avoid namespace conflicts.
simplenews_update_5000 Add index to simplenews_subscriptions.
simplenews_update_5001 Addition of node version to simplenews_newsletters in order to record the node version which is being send.
simplenews_update_6000 Data conversion of block delta. Field type conversions: newsletter priority. Field name change in simplenews_subscriptions table.
simplenews_update_6001 Addition of simplenews_mail_cache table. Related to this new table: the removal of simplenews_subscriptions is_send status. Correction of simplenews_newsletters priority field type.
simplenews_update_6002 Addition of node version to simplenews_newsletters in order to record the node version which is being send. Addition of nid to simplenews_mail_cache to be able to check the newsletter sent status.
simplenews_update_6003 Addition of index to uid in simplenews_subscriptions.
simplenews_update_6004 Add spool table and remove cache table.
simplenews_update_6005 Add language field to subscription table and set language of existing subscribers.
simplenews_update_6006 Make the simplenews content type a custom type.
simplenews_update_6007 Rename old permissions.
simplenews_update_6008 Make vocabulary required.
simplenews_update_6100 Add (un)subscription data to table simplenews_snid_tid.
simplenews_update_6101 Convert Simplenews custom tokens to Token tokens.
simplenews_update_6200 Dummy update for compatibility with HEAD
simplenews_update_6201 Correction of field size mismatch caused by simplenews_update_6009().
simplenews_update_6251 Add fields 'status', 'timestamp', 'source' to 'simplenews_snid_tid' table.
simplenews_update_6252 Add 'sent_subscriber_count' field to 'simplenews_newsletters' table.
simplenews_update_6253 Add timestamp field to simplenews subscriptions table. Port timestamps from `simplenews_snid_tid` table to `simplenews_subscriptions`
simplenews_update_6254 Add snid field to simplenews spool table.
_simplenews_install_nodetype Create simplenews node type.
_simplenews_install_vocabulary Create simplenews vocabulary and initial term.