You are here

function newsletter_install in Newsletter 7

Same name and namespace in other branches
  1. 7.2 newsletter.install \newsletter_install()

Implements hook_install().

File

./newsletter.install, line 10
Contains install,uninstall and update functions for Newsletter module.

Code

function newsletter_install() {
  $mail_modes = variable_get('mail_system', array(
    'default-system' => 'DefaultMailSystem',
  ));
  $mail_modes['newsletter'] = 'NewsletterMailSystem';
  variable_set('mail_system', $mail_modes);
  $personal_info_form_defaults = array(
    'firstname' => 'show',
    'lastname' => 'show',
    'gender' => 'show',
    'receive_format' => 'show',
  );
  variable_set('newsletter_personal_info_form', $personal_info_form_defaults);
  variable_set('newsletter_send_confirm', TRUE);
  variable_set('newsletter_send_welcome', TRUE);
  variable_set('newsletter_send_unsubscribe', TRUE);
  if (!db_query("SELECT vid FROM {taxonomy_vocabulary} WHERE machine_name = 'newsletter_categories'")
    ->fetchField()) {

    // Create vocabulary for newsletter lists categories.
    $vocabulary = new stdClass();
    $vocabulary->name = 'Newsletter categories';
    $vocabulary->machine_name = 'newsletter_categories';
    $vocabulary->description = 'Vocabulary used to store the categories of newsletter lists';
    $vocabulary->module = 'newsletter';
    $vocabulary->hierarchy = 0;
    taxonomy_vocabulary_save($vocabulary);
  }

  // Create fields and instances.
  $fields_instances = newsletter_fields_instances();
  foreach ($fields_instances as $op => $data) {
    foreach ($data as $specs) {
      switch ($op) {
        case 'field':
          if (!field_info_field($specs['field_name'])) {
            field_create_field($specs);
          }
          break;
        case 'instance':
          if (!field_info_instance($specs['entity_type'], $specs['field_name'], $specs['bundle'])) {
            field_create_instance($specs);
          }
          break;
      }
    }
  }

  // Add extra collumn to handle exposed newsletter lists tids.
  newsletter_schema_alter($schema);
  foreach ($schema['field_data_field_newsletter_list']['fields'] as $name => $spec) {
    db_add_field('field_data_field_newsletter_list', $name, $spec);
  }

  // Create dummy data
  newsletter_create_examples();
}