You are here

node_expire.install in Node expire 8

Install, uninstall and update the module.

File

node_expire.install
View source
<?php

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

/**
 * Implements hook_install().
 */

/*
function node_expire_install() {
  // TODO The drupal_(un)install_schema
  // functions are called automatically in D7.
  // drupal_install_schema('node_expire')
}
*/

/**
 * Implements hook_schema().
 */
function node_expire_schema() {
  $schema['node_expire'] = array(
    'description' => 'Alerts administrators of possibly outdated materials, and optionally unpublishes them.',
    'fields' => array(
      'nid' => array(
        'description' => 'Node ID from {node}.nid.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'expire' => array(
        'type' => 'int',
        'default' => 0,
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'expired' => 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_expired_lastnotify' => array(
        'expire',
        'expired',
        'lastnotify',
      ),
    ),
  );
  return $schema;
}

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

  // TODO The drupal_(un)install_schema
  // functions are called automatically in D7.
  // drupal_uninstall_schema('node_expire').
  //
  // Delete global variable.
  \Drupal::config('node_expire.settings')
    ->clear('node_expire_ntypes')
    ->save();

  // Delete configuration variables.
  \Drupal::config('node_expire.settings')
    ->clear('node_expire_handle_content_expiry')
    ->save();
  \Drupal::config('node_expire.settings')
    ->clear('node_expire_date_entry_elements')
    ->save();
  \Drupal::config('node_expire.settings')
    ->clear('node_expire_past_date_allowed')
    ->save();

  // Delete node type related variables.
  $types = node_type_get_types();
  foreach ($types as $type) {

    // @FIXME
    // // @FIXME
    // // The correct configuration object could not be determined. You'll need to
    // // rewrite this call manually.
    // variable_del('node_expire_' . $type->type);
    // @FIXME
    // // @FIXME
    // // The correct configuration object could not be determined. You'll need to
    // // rewrite this call manually.
    // variable_del('node_expire_enabled_' . $type->type);
    // @FIXME
    // // @FIXME
    // // The correct configuration object could not be determined. You'll need to
    // // rewrite this call manually.
    // variable_del('node_expire_max_' . $type->type);
    // @FIXME
    // // @FIXME
    // // The correct configuration object could not be determined. You'll need to
    // // rewrite this call manually.
    // variable_del('node_expire_required_' . $type->type);
  }
}

/**
 * Implements hook_update_N().
 *
 * Include the max date allowed values. Only new nodes
 * (or edited ones) will be affected
 */
function node_expire_update_6200() {

  // @FIXME
  // Could not extract the default value because it is either indeterminate, or
  // not scalar. You'll need to provide a default value in
  // config/install/node_expire.settings.yml and config/schema/node_expire.schema.yml.
  if ($ntypes = \Drupal::config('node_expire.settings')
    ->get('node_expire_ntypes')) {
    foreach ($ntypes as $ntype => $default) {
      $ntypes[$ntype] = array(
        'default' => $default,
        'max' => '',
      );
    }
    \Drupal::config('node_expire.settings')
      ->set('node_expire_ntypes', $ntypes)
      ->save();
  }

  // $update[]
  // = 'Include the max date allowed values.
  // Only new nodes (or edited ones) will be affected';
  // hook_update_N() no longer returns a $ret array. Instead, return
  // nothing or a translated string indicating the update ran successfully.
  // See http://drupal.org/node/224333#update_sql. /* $update */
  return t('TODO Add a descriptive string here to show in the UI.');
}

/**
 * Implements hook_update_N().
 *
 * New field 'lastnotify'. Holds last notified timestamp.
 */
function node_expire_update_6201() {

  // $ret = array();
  if (!db_field_exists('node_expire', 'lastnotify')) {
    db_add_field('node_expire', 'lastnotify', array(
      'type' => 'int',
      'default' => 0,
      'unsigned' => TRUE,
      'not null' => TRUE,
    ));
  }
  db_drop_index('node_expire', 'expire_expired');
  db_add_index('node_expire', 'expire_expired_lastnotify', array(
    'expire',
    'expired',
    'lastnotify',
  ));

  // hook_update_N() no longer returns a $ret array. Instead, return
  // nothing or a translated string indicating the update ran successfully.
  // See http://drupal.org/node/224333#update_sql.  /* $ret */
  return t('TODO Add a descriptive string here to show in the UI.');
}