You are here

bean_uuid.install in Bean (for Drupal 7) 7

Bean UUID installation and schema hooks.

File

bean_uuid/bean_uuid.install
View source
<?php

/**
 * @file
 * Bean UUID installation and schema hooks.
 */

/**
 * Implements hook_schema_alter().
 */
function bean_uuid_schema_alter(&$schema = array()) {
  module_load_include('install', 'uuid');
  $field = uuid_schema_field_definition();
  $schema['bean']['fields']['uuid'] = $field;
  $schema['bean_revision']['fields']['vuuid'] = $field;
}

/**
 * Implements hook_install().
 */
function bean_uuid_install() {
  module_load_include('install', 'uuid');
  $field = uuid_schema_field_definition();
  db_add_field('bean', 'uuid', $field);
  db_add_index('bean', 'uuid', array(
    'uuid',
  ));
  db_add_field('bean_revision', 'vuuid', $field);
  db_add_index('bean_revision', 'vuuid', array(
    'vuuid',
  ));
}

/**
 * Implements hook_enable().
 */
function bean_uuid_enable() {
  uuid_sync_all();
}

/**
 * Implements hook_uninstall().
 */
function bean_uuid_uninstall() {
  db_drop_field('bean', 'uuid');
  db_drop_index('bean', 'uuid');
  db_drop_field('bean_revision', 'vuuid');
  db_drop_index('bean_revision', 'vuuid');
}

/**
 * Add vuuid field to bean_revision table
 */
function bean_uuid_update_7201() {
  module_load_include('install', 'uuid');
  $field = uuid_schema_field_definition();
  db_add_field('bean_revision', 'vuuid', $field);
  db_add_index('bean_revision', 'vuuid', array(
    'vuuid',
  ));
}

/**
 * Remove duplicate vuuid field values on inactive bean revisions.
 */
function bean_uuid_update_7202() {

  // Retrieve all active vid values for subquery.
  $subquery = db_select('bean', 'b')
    ->fields('b', array(
    'vid',
  ));

  // Remove duplicate UUID values on inactive vuuid values.
  $fields = array(
    'vuuid' => '',
  );
  $query = db_update('bean_revision')
    ->fields($fields)
    ->condition('vid', $subquery, 'NOT IN')
    ->execute();
}

/**
 * Update removed vuuids with unique revision UUIDs.
 */
function bean_uuid_update_7203() {

  // Regenerate vuuid values.
  uuid_sync_all();
}

Functions

Namesort descending Description
bean_uuid_enable Implements hook_enable().
bean_uuid_install Implements hook_install().
bean_uuid_schema_alter Implements hook_schema_alter().
bean_uuid_uninstall Implements hook_uninstall().
bean_uuid_update_7201 Add vuuid field to bean_revision table
bean_uuid_update_7202 Remove duplicate vuuid field values on inactive bean revisions.
bean_uuid_update_7203 Update removed vuuids with unique revision UUIDs.