key.install in Key 7
Same filename and directory in other branches
Install, update and uninstall functions for the Key module.
File
key.installView source
<?php
/**
* @file
* Install, update and uninstall functions for the Key module.
*/
/**
* Implements hook_schema().
*
* Create table to store key configurations.
*/
function key_schema() {
$schema['key_config'] = array(
'description' => 'Stores key configurations.',
'fields' => array(
'name' => array(
'description' => 'The machine name of the configuration.',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
),
'label' => array(
'description' => 'The human-readable label of the configuration.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'description' => array(
'description' => 'A brief description of the configuration.',
'type' => 'text',
'not null' => TRUE,
'size' => 'medium',
),
'type' => array(
'description' => 'The type of key.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'provider' => array(
'description' => 'The key provider to use.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'provider_settings' => array(
'description' => 'Additional settings for the key provider.',
'type' => 'blob',
'not null' => FALSE,
'size' => 'big',
),
'created' => array(
'description' => 'The Unix timestamp when the configuration was created.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'changed' => array(
'description' => 'The Unix timestamp when the configuration was last saved.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
),
'indexes' => array(
'label' => array(
'label',
),
'type' => array(
'type',
),
'provider' => array(
'provider',
),
),
'primary key' => array(
'name',
),
);
$schema['key_integration'] = array(
'description' => 'Stores settings for key integrations.',
'fields' => array(
'name' => array(
'description' => 'The machine name of the integration.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'enabled' => array(
'description' => 'A boolean indicating if this integration is enabled.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'settings' => array(
'description' => 'Additional settings for the integration.',
'type' => 'blob',
'not null' => FALSE,
'size' => 'big',
),
),
'indexes' => array(
'enabled' => array(
'enabled',
),
),
'primary key' => array(
'name',
),
);
return $schema;
}
/**
* Implements hook_install().
*/
function key_install() {
// Add a randomly generated default key.
$fields = array(
'name' => 'default',
'label' => 'Default',
'description' => 'A randomly generated basic key.',
'type' => 'general',
'provider' => 'variable',
'provider_settings' => array(
'variable_name' => 'default',
),
);
$key = drupal_random_key();
key_save_config($fields, $key, FALSE, FALSE);
}
/**
* Change the "kind" db field to "type".
*/
function key_update_7101() {
if (db_field_exists('key_config', 'kind')) {
db_change_field('key_config', 'kind', 'type', array(
'description' => 'The type of key.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
));
}
}
/**
* Add an index to the "type" db field.
*/
function key_update_7102() {
if (!db_index_exists('key_config', 'type')) {
db_add_index('key_config', 'type', array(
'type',
));
}
}
/**
* Add an index to the "type" db field.
*/
function key_update_7103() {
if (!db_index_exists('key_config', 'storage_method')) {
db_add_index('key_config', 'storage_method', array(
'storage_method',
));
}
}
/**
* Change "storage method" db field to "provider".
*/
function key_update_7104() {
if (db_field_exists('key_config', 'storage_method')) {
db_change_field('key_config', 'storage_method', 'provider', array(
'description' => 'The key provider to use.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
));
}
}
/**
* Change "storage settings" db field to "provider settings".
*/
function key_update_7105() {
if (db_field_exists('key_config', 'storage_settings')) {
db_change_field('key_config', 'storage_settings', 'provider_settings', array(
'description' => 'Additional settings for the key provider.',
'type' => 'blob',
'not null' => FALSE,
'size' => 'big',
));
}
}
Functions
Name | Description |
---|---|
key_install | Implements hook_install(). |
key_schema | Implements hook_schema(). |
key_update_7101 | Change the "kind" db field to "type". |
key_update_7102 | Add an index to the "type" db field. |
key_update_7103 | Add an index to the "type" db field. |
key_update_7104 | Change "storage method" db field to "provider". |
key_update_7105 | Change "storage settings" db field to "provider settings". |