You are here

forward.install in Forward 7.3

Install, update and uninstall functions for the forward module.

File

forward.install
View source
<?php

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

/**
 * Implements hook_install().
 */
function forward_install() {

  // Default to show Forward on full entity view mode
  variable_set('forward_view_full', TRUE);

  // Setup mail system for HTML emails
  $mail_systems = variable_get('mail_system', array(
    'default-system' => 'DefaultMailSystem',
  ));
  $mail_systems['forward'] = 'ForwardMailSystem';
  variable_set('mail_system', $mail_systems);

  // Warn administrator
  if (module_exists('mailsystem')) {
    $link = l(t('Review or change your mail setup.'), 'admin/config/system/mailsystem', array());
    drupal_set_message(t('The mail system for Forward has been set to enable HTML emails. ') . $link, 'warning');
  }

  // Initialize statistics table:
  // Nodes
  $query = db_select('node', 'n');
  $query
    ->addExpression("'node'", 'type');
  $query
    ->addField('n', 'type', 'bundle');
  $query
    ->addField('n', 'nid', 'id');
  db_insert('forward_statistics')
    ->from($query)
    ->execute();

  // Taxonomy terms
  if (module_exists('taxonomy')) {
    $query = db_select('taxonomy_term_data', 't');
    $query
      ->join('taxonomy_vocabulary', 'v', 't.vid = v.vid');
    $query
      ->addExpression("'taxonomy_term'", 'type');
    $query
      ->addField('v', 'machine_name', 'bundle');
    $query
      ->addField('t', 'tid', 'id');
    db_insert('forward_statistics')
      ->from($query)
      ->execute();
  }

  // Users
  $query = db_select('users', 'u');
  $query
    ->addExpression("'user'", 'type');
  $query
    ->addExpression("'user'", 'bundle');
  $query
    ->addField('u', 'uid', 'id');
  db_insert('forward_statistics')
    ->from($query)
    ->execute();

  // Other entity types with view modes
  $entity_types = entity_get_info();
  foreach ($entity_types as $type => $info) {
    if ($type != 'node' && $type != 'taxonomy_term' && $type != 'user') {
      if (!empty($info['view modes'])) {
        $entity_list = entity_load($type);
        foreach ($entity_list as $entity) {
          forward_entity_insert($entity, $type);
        }
      }
    }
  }
}

/**
 * Implements hook_uninstall().
 */
function forward_uninstall() {

  // Remove variables
  global $conf;
  foreach (array_keys($conf) as $key) {

    // Find variables that have the module prefix
    if (strpos($key, 'forward_') === 0) {
      variable_del($key);
    }
  }

  // Remove mail system
  $mail_systems = variable_get('mail_system', array(
    'default-system' => 'DefaultMailSystem',
  ));
  unset($mail_systems['forward']);
  variable_set('mail_system', $mail_systems);

  // Warn administrator
  if (module_exists('mailsystem')) {
    $link = l(t('Review or change your mail setup.'), 'admin/config/system/mailsystem', array());
    drupal_set_message(t('The mail system for Forward has been removed. ') . $link, 'warning');
  }
}

/**
 * Implements hook_schema().
 */
function forward_schema() {
  $schema['forward_log'] = array(
    'fields' => array(
      'path' => array(
        'type' => 'varchar',
        'not null' => TRUE,
        'default' => '<front>',
        'length' => 255,
      ),
      'type' => array(
        'type' => 'varchar',
        'not null' => TRUE,
        'length' => 8,
      ),
      'timestamp' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'uid' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'hostname' => array(
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Hostname of the user who triggered the event.',
      ),
    ),
    'indexes' => array(
      'forward_path' => array(
        'path',
      ),
      'forward_uid' => array(
        'uid',
      ),
      'forward_hostname' => array(
        'hostname',
      ),
    ),
  );
  $schema['forward_statistics'] = array(
    'fields' => array(
      'type' => array(
        'type' => 'varchar',
        'not null' => TRUE,
        'default' => '',
        'length' => 128,
      ),
      'bundle' => array(
        'type' => 'varchar',
        'not null' => TRUE,
        'default' => '',
        'length' => 128,
      ),
      'id' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'last_forward_timestamp' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'forward_count' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'clickthrough_count' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'indexes' => array(
      'forward_timestamp' => array(
        'last_forward_timestamp',
      ),
    ),
    'primary key' => array(
      'type',
      'bundle',
      'id',
    ),
  );
  return $schema;
}

Functions

Namesort descending Description
forward_install Implements hook_install().
forward_schema Implements hook_schema().
forward_uninstall Implements hook_uninstall().