You are here

block_token.install in Block Token 7

Install, update and uninstall functions for the block_token module.

File

block_token.install
View source
<?php

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

/**
 * Implements hook_install().
 */
function block_token_install() {
  $schema['block'] = array();
  block_token_schema_alter($schema);
  foreach ($schema['block']['fields'] as $field => $spec) {
    if (db_field_exists('block', $field)) {
      watchdog('system', 'Module install: Attempt to recreate field: "%field", when it already exists.', array(
        '%field' => $field,
      ), WATCHDOG_WARNING);
    }
    else {
      db_add_field('block', $field, $spec);
    }
  }
}

/**
 * Implements hook_uninstall().
 */
function block_token_uninstall() {
  $schema['block'] = array();
  block_token_schema_alter($schema);
  foreach ($schema['block']['fields'] as $field => $specs) {
    if (db_field_exists('block', $field)) {
      db_drop_field('block', $field);
    }
    else {
      watchdog('system', 'Module uninstall: Attempt to drop field: "%field", when it does not exists.', array(
        '%field' => $field,
      ), WATCHDOG_WARNING);
    }
  }
}

/**
 * Implements hook_schema_alter().
 *
 * Other modules, such as i18n_block also modify the block database table.
 */
function block_token_schema_alter(&$schema) {
  if (isset($schema['block'])) {
    $schema['block']['fields']['block_token'] = array(
      'description' => 'Boolean indicating whether the Block Token should be created or not.',
      'type' => 'int',
      'not null' => TRUE,
      'default' => 0,
    );
  }
}