You are here

node_expire.install in Node expire 6

Install, uninstall and update the module.

File

node_expire.install
View source
<?php

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

/**
 * Implementation of hook_install().
 */
function node_expire_install() {
  drupal_install_schema('node_expire');
}

/**
 * Implementation of hook_schema().
 */
function node_expire_schema() {
  $schema['node_expire'] = array(
    'description' => t('Alerts administrators of possibly outdated materials, and optionally unpublishes them.'),
    'fields' => array(
      'nid' => array(
        'description' => t('Node ID from {node}.nid.'),
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'expire' => array(
        'type' => 'int',
        'default' => 0,
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'expire_timefrom' => array(
        'type' => 'int',
        'size' => 'small',
        'default' => 0,
        'not null' => TRUE,
      ),
      'expiremode' => array(
        'type' => 'varchar',
        'length' => 10,
        'not null' => TRUE,
      ),
      'isroot' => array(
        'type' => 'int',
        'size' => 'tiny',
        'default' => 0,
        'not null' => TRUE,
      ),
      'lastnotify' => array(
        'type' => 'int',
        'default' => 0,
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
    ),
    'primary key' => array(
      'nid',
    ),
    'indexes' => array(
      'expire' => array(
        'expire',
      ),
      'expiremode' => array(
        'expiremode',
      ),
      'lastnotify' => array(
        'lastnotify',
      ),
    ),
  );
  return $schema;
}

/**
 * Implementation of hook_uninstall().
 */
function node_expire_uninstall() {
  drupal_uninstall_schema('node_expire');

  // Delete some global variables
  variable_del('node-expire-body');
  variable_del('node-expire-book-props');
  variable_del('node-expire-cc');
  variable_del('node-expire-enable-email');
  variable_del('node-expire-node-visibility');
  variable_del('node-expire-renotify');
  variable_del('node-expire-subject');
  variable_del('node-expire-unpublishtime');
}

/**
 * Update the database table in order to support more DBMS.
 */
function node_expire_update_6001() {
  $update = array();
  $expire_timefrom = array(
    'none' => 0,
    'onupdate' => 1,
    'date' => 2,
  );
  $nodes = db_query('SELECT expire, expiresec, nid FROM {node_expire}');
  while ($node = db_fetch_array($nodes)) {

    // Convert 'expire' dates to timestamps format, since date features
    // is not standard thru DBMS
    $node['expire'] = $node['expire'];

    // Convert the data from 'expiresec' to a small numbers
    $node['expire_timefrom'] = $expire_timefrom($node['expiresec']);
    $nodes_data[] = $node;
  }

  // Remove the old columns and rename the new ones
  db_drop_field($update, 'node_expire', 'expire');
  db_drop_field($update, 'node_expire', 'expiresec');
  db_add_column($update, 'node_expire', 'expire', 'int', array(
    'unsigned' => TRUE,
    'default' => 0,
    'not null' => TRUE,
  ));
  db_add_column($update, 'node_expire', 'expire_timefrom', 'int', array(
    'size' => 'small',
    'unsigned' => TRUE,
    'default' => 0,
    'not null' => TRUE,
  ));
  db_add_index($update, 'node_expire', 'expire', array(
    'expire',
  ));
  foreach ($nodes_data as $node) {
    $update[] = update_sql('UPDATE {node_expire} SET
      expire = ' . $node['expire'] . ',
      expire_timefrom = ' . $node['expire_timefrom'] . '
      WHERE nid = ' . $node['nid']);
  }

  // Convert all 'expiration_type' variables to 'expiremode'
  if ($defaults = variable_get('node-expire-node-visibility', array())) {
    foreach (array_keys($defaults) as $node) {
      $defaults[$node]['expiremode'] = $defaults[$node]['expiration_type'];
      unset($defaults[$node]['expiration_type']);
    }
    variable_set('node-expire-node-visibility', $defaults);
  }
  return $update;
}

Functions

Namesort descending Description
node_expire_install Implementation of hook_install().
node_expire_schema Implementation of hook_schema().
node_expire_uninstall Implementation of hook_uninstall().
node_expire_update_6001 Update the database table in order to support more DBMS.