You are here

values.install in Values 6

Same filename and directory in other branches
  1. 7 values.install

Install file for Values module.

File

values.install
View source
<?php

/**
 * @file
 * Install file for Values module.
 */

/**
 * Implementation of hook_install().
 */
function values_install() {
  drupal_install_schema('values');
}

/**
 * Implementation of hook_uninnstall().
 */
function values_uninstall() {
  drupal_uninstall_schema('values');
}

/**
 * Implementation of hook_schema().
 */
function values_schema() {
  $schema['values_list'] = array(
    'description' => t('List of configured value lists.'),
    'export' => array(
      'key' => 'name',
      'identifier' => 'values',
      'default hook' => 'default_values_values',
      'api' => array(
        'owner' => 'values',
        'api' => 'default_values_list',
        'minimum_version' => 1,
        'current_version' => 1,
      ),
    ),
    'fields' => array(
      'name' => array(
        'description' => t('Unique ID for value lists.'),
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'description' => array(
        'description' => t('A human-readable name of a value list'),
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'data' => array(
        'description' => t('Configured list of values.'),
        'type' => 'text',
        'size' => 'big',
        'serialize' => TRUE,
      ),
    ),
    'unique keys' => array(
      'name' => array(
        'name',
      ),
    ),
    'primary key' => array(
      'name',
    ),
  );
  return $schema;
}

/**
 * Implementation of hook_update_N().
 * Make 'value' field longer (255).
 */
function values_update_6100(&$sandbox) {
  $ret = array();
  $spec = array(
    'type' => 'varchar',
    'length' => 255,
    'not null' => TRUE,
  );
  db_change_field($ret, 'values_values', 'value', 'value', $spec);
  return $ret;
}

/**
 * Implementation of hook_update_N().
 * Condense schema into a single table to handle exportables easily.
 */
function values_update_6101(&$sandbox) {
  $ret = array();

  // Define the new table
  $schema['values_list'] = array(
    'description' => t('List of configured value lists.'),
    'export' => array(
      'key' => 'name',
      'identifier' => 'values',
      'default hook' => 'default_values_values',
      'api' => array(
        'owner' => 'values',
        'api' => 'default_values_list',
        'minimum_version' => 1,
        'current_version' => 1,
      ),
    ),
    'fields' => array(
      'name' => array(
        'description' => t('Unique ID for value lists.'),
        'type' => 'varchar',
        'length' => 255,
      ),
      'description' => array(
        'description' => t('A human-readable name of a value list'),
        'type' => 'varchar',
        'length' => 255,
      ),
      'data' => array(
        'description' => t('Configured list of values.'),
        'type' => 'text',
        'size' => 'big',
        'serialize' => TRUE,
      ),
    ),
    'unique keys' => array(
      'name' => array(
        'name',
      ),
    ),
    'primary key' => array(
      'name',
    ),
  );
  db_create_table($ret, 'values_list', $schema['values_list']);

  // Migrate existing data to the new schema
  $values_sets = db_query('SELECT * FROM {values_sets}');
  while ($set = db_fetch_object($values_sets)) {
    $values = new stdClass();
    $values->name = $set->id;
    $values->description = $set->description;
    $values->data = array();
    $values_values = db_query("SELECT * FROM {values_values} WHERE id = '%s' ORDER BY weight ASC", $set->id);
    while ($value = db_fetch_array($values_values)) {
      unset($value['id']);
      $values->data[] = $value;
    }
    drupal_write_record('values_list', $values);
  }

  // Remove old tables
  db_drop_table($ret, 'values_sets');
  db_drop_table($ret, 'values_values');
  return $ret;
}

/**
 * Implementation of hook_update_N().
 * Clear menu caches to enable new menu items.
 */
function values_update_6102(&$sandbox) {
  menu_cache_clear_all();
  drupal_set_message(t('Menu cache cleared.'));
  return array();
}

Functions

Namesort descending Description
values_install Implementation of hook_install().
values_schema Implementation of hook_schema().
values_uninstall Implementation of hook_uninnstall().
values_update_6100 Implementation of hook_update_N(). Make 'value' field longer (255).
values_update_6101 Implementation of hook_update_N(). Condense schema into a single table to handle exportables easily.
values_update_6102 Implementation of hook_update_N(). Clear menu caches to enable new menu items.