You are here

node_accessibility.install in Node Accessibility 7

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

Install file for node accessibility.

File

node_accessibility.install
View source
<?php

/**
 * @file
 * Install file for node accessibility.
 */

/**
 * Implementation of hook_schema().
 */
function node_accessibility_schema() {
  $schema = array();
  $schema['node_accessibility_problems'] = array(
    'description' => st("Node validation problem statistics."),
    'fields' => array(
      'id' => array(
        'description' => st("The primary key used to represent this problem."),
        'type' => 'serial',
        'size' => 'big',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'nid' => array(
        'description' => st("The node's ID from {node}.nid."),
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'vid' => array(
        'description' => st("The node's version ID from {node}.vid."),
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'test_id' => array(
        'description' => st("The numeric ID from {quail_api_tests}.id, representing a specific error."),
        'type' => 'int',
        'size' => 'big',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'line' => array(
        'description' => st("The line number in which the error happened."),
        'type' => 'int',
        'size' => 'normal',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'element' => array(
        'description' => st("A snippet of the code that failed validation."),
        'type' => 'text',
        'not null' => TRUE,
        'default' => '',
      ),
    ),
    'primary key' => array(
      'id',
    ),
    'foreign keys' => array(
      'nid' => array(
        'table' => 'node',
        'columns' => array(
          'nid' => 'nid',
        ),
      ),
      'error_id' => array(
        'table' => 'quail_api_errors',
        'columns' => array(
          'id' => 'id',
        ),
      ),
    ),
  );

  // workaround mysql's violation of the SQL standard in a way that does not break standards-compliant databases.
  // @see https://dev.mysql.com/doc/refman/5.6/en/data-type-defaults.html
  // @see https://bugs.mysql.com/bug.php?id=25520
  // @see https://drupal.org/node/1401782
  // @see https://drupal.org/node/143881
  if (db_driver() == 'mysql') {
    unset($schema['node_accessibility_problems']['fields']['element']['default']);
  }
  return $schema;
}

/**
 * Implementation of hook_install().
 */
function node_accessibility_install() {
  if (function_exists('cf_settings_register')) {
    cf_settings_register('node_accessibility_node_type_settings', 'drupal_variables', 'node_accessibility', array());
    cf_settings_register('node_accessibility_alter_revision_menu', 'drupal_variables', 'node_accessibility', TRUE);
  }
  else {
    variable_set('node_accessibility_node_type_settings', array());
    variable_set('node_accessibility_alter_revision_menu', TRUE);
  }
}

/**
 * Implementation of hook_uninstall().
 */
function node_accessibility_uninstall() {
  if (function_exists('cf_settings_unregister')) {
    $registered = cf_settings_get_registered(array(
      'module_name' => 'node_accessibility',
    ), 'id');
    foreach ($registered as &$r) {
      cf_settings_unregister($r->variable_name, $r->variable_type, $r->module);
    }
  }
  else {
    variable_del('node_accessibility_node_type_settings');
    variable_del('node_accessibility_alter_revision_menu');
  }
}

/**
 * Switch to variable_set()/variable_get() node type settings.
 *
 * If enabled, cf_settings will now be utilized.
 *
 * see: https://drupal.org/node/2101573
 */
function node_accessibility_update_7100() {
  $query = db_select('node_accessibility_types', 'nat');
  $query
    ->fields('nat');
  $query
    ->orderBy('nat.type', 'ASC');
  $node_type_settings = array();
  $results = (array) $query
    ->execute()
    ->fetchAll();
  foreach ($results as $result) {
    $node_type_settings[$result->type] = array();
    $node_type_settings[$result->type]['required'] = $result->required;
    $node_type_settings[$result->type]['standards'] = unserialize($result->standards);
    $node_type_settings[$result->type]['method'] = $result->method;
    $node_type_settings[$result->type]['format'] = $result->format;
  }
  if (function_exists('cf_settings_register')) {
    cf_settings_register('node_accessibility_node_type_settings', 'drupal_variables', 'node_accessibility', array());
    cf_settings_register('node_accessibility_alter_revision_menu', 'drupal_variables', 'node_accessibility', TRUE);
  }
  variable_set('node_accessibility_node_type_settings', $node_type_settings);
  db_drop_table('node_accessibility_types');
}

Functions

Namesort descending Description
node_accessibility_install Implementation of hook_install().
node_accessibility_schema Implementation of hook_schema().
node_accessibility_uninstall Implementation of hook_uninstall().
node_accessibility_update_7100 Switch to variable_set()/variable_get() node type settings.