You are here

node_authlink.install in Node authorize link 7

Same filename and directory in other branches
  1. 8 node_authlink.install

Installation and update of the node_authlink module.

File

node_authlink.install
View source
<?php

/**
 * @file
 * Installation and update of the node_authlink module.
 */

/**
 * Implements hook_schema().
 */
function node_authlink_schema() {
  $schema['node_authlink_nodes'] = array(
    'description' => 'Table for store authorization keys.',
    'fields' => array(
      'nid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'authkey' => array(
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
      ),
      'created' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'nid',
    ),
  );
  return $schema;
}

/**
 * Implements hook_install().
 */
function node_authlink_install() {
  drupal_set_message(t('To setup Node authorize link module go to Structure → Content types → edit → Node authorize link.'));
}

/**
 * Implements hook_uninstall().
 */
function node_authlink_uninstall() {
  $node_types = node_type_get_types();
  foreach ($node_types as $node_type) {
    variable_del('node_authlink_enable_' . $node_type->type);
    variable_del('node_authlink_grants_' . $node_type->type);
    variable_del('node_authlink_expire_' . $node_type->type);
  }
}

/**
 * Implements hook_update_N().
 */
function node_authlink_update_7100(&$sandbox) {

  // Migrate data.
  drupal_install_schema('node_authlink');
  $keys = db_query('SELECT f.field_node_authlink_authkey_value, f.entity_id, n.created
    FROM {field_data_field_node_authlink_authkey} AS f INNER JOIN {node} AS n ON f.entity_id = n.nid
    WHERE f.language = \'und\'');
  foreach ($keys as $key) {
    db_insert('node_authlink_nodes')
      ->fields(array(
      'nid' => $key->entity_id,
      'authkey' => $key->field_node_authlink_authkey_value,
      'created' => $key->created,
    ))
      ->execute();
  }
  unset($keys);

  // Migrate settings.
  $field = field_info_field('field_node_authlink_authkey');
  $instances = field_read_instances(array(
    'field_id' => $field['id'],
    'entity_type' => 'node',
  ));
  $node_types = array();
  foreach ($instances as $instance) {
    $node_types[$instance['bundle']] = $instance['bundle'];
    variable_set('node_authlink_enable_' . $instance['bundle'], TRUE);
    variable_set('node_authlink_grants_' . $instance['bundle'], $instance['node_authlink_grants']);
  }
  variable_set('node_authlink_types', $node_types);

  // Cleanup.
  field_delete_field('field_node_authlink_authkey');
}

/**
 * Remove node_authlink_types variable.
 */
function node_authlink_update_7101(&$sandbox) {
  variable_del('node_authlink_types');
}

Functions

Namesort descending Description
node_authlink_install Implements hook_install().
node_authlink_schema Implements hook_schema().
node_authlink_uninstall Implements hook_uninstall().
node_authlink_update_7100 Implements hook_update_N().
node_authlink_update_7101 Remove node_authlink_types variable.