You are here

block_machine_name.install in Block Machine Name 7

Install, uninstall and schema functions for the Block Machine Name module.

File

block_machine_name.install
View source
<?php

/**
 * @file
 * Install, uninstall and schema functions for the Block Machine Name module.
 */

/**
 * Implements hook_schema().
 */
function block_machine_name_schema() {
  $schema['block_machine_name_boxes'] = array(
    'description' => '',
    'export' => array(
      'key' => 'machine_name',
      'can disable' => FALSE,
    ),
    'fields' => array(
      'delta' => array(
        'description' => 'Delta',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
      ),
      'machine_name' => array(
        'description' => 'machine_name',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
      ),
      'module' => array(
        'type' => 'varchar',
        'description' => "Module",
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
    ),
    'primary key' => array(
      'machine_name',
    ),
  );
  return $schema;
}

/**
 * Add the 'module' field to block_machine_name_boxes and set its values to 'block'.
 */
function block_machine_name_update_7100(&$sandbox) {

  // Add a 'module' field
  $spec = array(
    'type' => 'varchar',
    'description' => "Module",
    'length' => 255,
    'not null' => TRUE,
    'default' => '',
  );
  db_add_field('block_machine_name_boxes', 'module', $spec);

  // All entries in this table up to now would have come from the block module, so set all values for 'module' to 'block'
  db_query("UPDATE {block_machine_name_boxes} SET module = 'block'");

  // The primary key for this table is no longer really unique, multiple module's may have the same block delta
  db_drop_primary_key('block_machine_name_boxes');

  // Rename 'bid' to 'delta', since it's really a more accurate name
  $spec = array(
    'description' => 'Unique ID for block within a module.',
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 0,
    'no export' => FALSE,
  );
  db_change_field('block_machine_name_boxes', 'bid', 'delta', $spec);
}

/**
 * Change machine name to be primary key and not just index.
 */
function block_machine_name_update_7101(&$sandbox) {
  db_add_primary_key('block_machine_name_boxes', array(
    'machine_name',
  ));
}

/**
 * Change 'delta' field to varchar
 */
function block_machine_name_update_7102(&$sandbox) {
  $spec = array(
    'description' => 'Delta',
    'type' => 'varchar',
    'length' => 32,
    'not null' => TRUE,
    'default' => '',
  );
  db_change_field('block_machine_name_boxes', 'bid', 'delta', $spec);
}

Functions

Namesort descending Description
block_machine_name_schema Implements hook_schema().
block_machine_name_update_7100 Add the 'module' field to block_machine_name_boxes and set its values to 'block'.
block_machine_name_update_7101 Change machine name to be primary key and not just index.
block_machine_name_update_7102 Change 'delta' field to varchar