service_container.install in Service Container 7.2
Same filename and directory in other branches
Creates the following tables:
- key_value
- key_value_expire
File
service_container.installView source
<?php
/**
* @file
* Creates the following tables:
*
* - key_value
* - key_value_expire
*/
/**
* Implements hook_requirements().
*/
function service_container_requirements($phase) {
// Attempt to load the "any" dependencies module.
if (!module_exists('any')) {
module_enable([
'any',
]);
}
// If "any" still doesn't exist then inform the user.
if (!module_exists('any')) {
$t = get_t();
$requirements["service_container-missing-any"] = [
'title' => $t('Missing "any" dependency'),
'description' => $t('The module "service_container" requires the !url project. Please download and install it first.', [
'!url' => 'https://www.drupal.org/project/any',
]),
'severity' => REQUIREMENT_ERROR,
];
return $requirements;
}
// Load the "any" module and let it perform requirement checks.
drupal_load('module', 'any');
return any_check_install_requirements($phase, 'service_container');
}
/**
* Implements hook_schema().
*/
function service_container_schema() {
$schema = array();
$schema['key_value'] = array(
'description' => 'Generic key-value storage table. See the state system for an example.',
'fields' => array(
'collection' => array(
'description' => 'A named collection of key and value pairs.',
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
),
'name' => array(
'description' => 'The key of the key-value pair. As KEY is a SQL reserved keyword, name was chosen instead.',
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
),
'value' => array(
'description' => 'The value.',
'type' => 'blob',
'not null' => TRUE,
'size' => 'big',
),
),
'primary key' => array(
'collection',
'name',
),
);
$schema['key_value_expire'] = array(
'description' => 'Generic key/value storage table with an expiration.',
'fields' => array(
'collection' => array(
'description' => 'A named collection of key and value pairs.',
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
),
'name' => array(
// KEY is an SQL reserved word, so use 'name' as the key's field name.
'description' => 'The key of the key/value pair.',
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
),
'value' => array(
'description' => 'The value of the key/value pair.',
'type' => 'blob',
'not null' => TRUE,
'size' => 'big',
),
'expire' => array(
'description' => 'The time since Unix epoch in seconds when this item expires. Defaults to the maximum possible time.',
'type' => 'int',
'not null' => TRUE,
'default' => 2147483647,
),
),
'primary key' => array(
'collection',
'name',
),
'indexes' => array(
'all' => array(
'name',
'collection',
'expire',
),
'expire' => array(
'expire',
),
),
);
return $schema;
}
Functions
Name![]() |
Description |
---|---|
service_container_requirements | Implements hook_requirements(). |
service_container_schema | Implements hook_schema(). |