You are here

block_country.install in Block Country 7

Schema definitions install/update/uninstall hooks.

File

block_country.install
View source
<?php

/**
 * @file
 * Schema definitions install/update/uninstall hooks.
 */

/**
 * Implements hook_schema().
 */
function block_country_schema() {
  $schema = array();
  $schema['block_country'] = array(
    'description' => 'Block Country Table',
    'fields' => array(
      'country_block_id' => array(
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => 'Primary Key: Unique country_block_id.',
      ),
      'module' => array(
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
        'description' => "The block's origin module, from {block}.module.",
      ),
      'delta' => array(
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'description' => "The block's unique delta within module, from {block}.delta.",
      ),
      'country_code' => array(
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'description' => 'Country Code.',
      ),
    ),
    'primary key' => array(
      'country_block_id',
    ),
    'indexes' => array(
      'list' => array(
        'module',
        'delta',
      ),
    ),
  );
  return $schema;
}

/**
 * Implements hook_install().
 */
function block_country_install() {
  $schema['block'] = array();
  block_country_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_country_uninstall() {
  $schema['block'] = array();
  block_country_schema_alter($schema);
  foreach ($schema['block']['fields'] as $field => $specs) {
    db_drop_field('block', $field);
  }
}

/**
 * Implements hook_schema_alter().
 *
 * Other modules, such as block_class, i18n_block also
 * modify the block database table.
 */
function block_country_schema_alter(&$schema) {
  if (isset($schema['block'])) {
    $schema['block']['fields']['country_visiblility'] = array(
      'type' => 'int',
      'not null' => TRUE,
      'default' => 1,
      'description' => 'visibility on all countries.',
    );
  }
}