field_encrypt.install in Field Encryption 7
Same filename and directory in other branches
Insallation functions for the Field Encryption module.
File
field_encrypt.installView source
<?php
/**
* @file
* Insallation functions for the Field Encryption module.
*/
/**
* Implements hook_enable().
*/
function field_encrypt_enable() {
// Clear the cache of existing data.
cache_clear_all('*', 'cache_field', TRUE);
// Set up the new class for this bin.
$old_cache = variable_get('cache_class_cache_field', NULL);
variable_set('field_encrypt_old_cache', $old_cache);
$default_cache_class = variable_get('cache_default_class', 'DrupalDatabaseCache');
switch ($default_cache_class) {
case 'DrupalDatabaseCache':
variable_set('cache_class_cache_field', 'FieldEncryptDatabaseCache');
break;
case 'MemCacheDrupal':
variable_set('cache_class_cache_field', 'FieldEncryptMemCacheDrupal');
break;
}
}
/**
* Implements hook_disable().
*/
function field_encrypt_disable() {
// Clear the cache of existing data.
cache_clear_all('*', 'cache_field', TRUE);
// Set the old class for this bin, if there was one.
$old_cache = variable_get('field_encrypt_old_cache', NULL);
if ($old_cache === NULL) {
variable_del('cache_class_cache_field');
}
else {
variable_set('cache_class_cache_field', $old_cache);
}
}
/**
* Update database schema to re-used existing field tables.
*/
function field_encrypt_update_7000() {
// Get all the current entries.
$results = db_select('field_encrypt', 'fe')
->fields('fe')
->execute()
->fetchAll();
// Drop the old database table.
db_drop_table('field_encrypt');
if (count($results) > 0) {
module_load_include('inc', 'field_encrypt');
$fields = array();
foreach ($results as $result) {
if (!isset($fields[$result->field_name])) {
$fields[$result->field_name] = field_info_field($result->field_name);
}
$field_info = $fields[$result->field_name];
$data = unserialize(field_encrypt_decrypt($result->value));
$table = key($field_info['storage']['details']['sql'][FIELD_LOAD_CURRENT]);
unset($result->value);
foreach ($field_info['storage']['details']['sql'][FIELD_LOAD_CURRENT][$table] as $field) {
if (isset($data[$field])) {
$result->{$field} = $data[$field];
}
}
foreach (array(
FIELD_LOAD_CURRENT,
FIELD_LOAD_REVISION,
) as $key) {
$table = key($field_info['storage']['details']['sql'][$key]);
drupal_write_record($table, $result);
}
}
}
$fields = field_info_fields();
foreach ($fields as $field_info) {
if (isset($field_info['settings']['field_encrypt']['encrypt']) && $field_info['settings']['field_encrypt']['encrypt']) {
module_load_include('inc', 'field_encrypt');
$has_data = field_has_data($field_info['field_name']);
field_encrypt_do_encrypt($field_info, $has_data);
}
}
}
Functions
Name | Description |
---|---|
field_encrypt_disable | Implements hook_disable(). |
field_encrypt_enable | Implements hook_enable(). |
field_encrypt_update_7000 | Update database schema to re-used existing field tables. |