lockr.install in Lockr 7.3
Same filename and directory in other branches
Install, uninstall, and update functions for lockr.
File
lockr.installView source
<?php
/**
* @file
* Install, uninstall, and update functions for lockr.
*/
/**
* Implements hook_enable().
*/
function lockr_enable() {
if (module_exists('lockr_pantheon')) {
module_disable([
'lockr_pantheon',
]);
drupal_set_message(t('We have disabled the previous version of Lockr. All existing keys and settings have been migrated successfully.'), 'warning');
}
}
/**
* Implements hook_uninstall().
*
* Delete any keys that use Lockr as the key provider.
*/
function lockr_uninstall() {
// Load the key configurations.
$configs = db_query("SELECT * FROM {key_config} WHERE key_provider = :provider", [
':provider' => 'lockr',
])
->fetchAllAssoc('id', PDO::FETCH_ASSOC);
// If no keys use Lockr, don't bother to continue.
if (empty($configs)) {
return;
}
// Load the module and plugin.
drupal_load('module', 'lockr');
require_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'lockr') . "/plugins/key_provider/lockr.inc";
$deleted_keys = [];
// Delete each Lockr key and the key value.
foreach ($configs as $id => $config) {
db_delete('key_config')
->condition('id', $id)
->execute();
key_provider_lockr_delete_key_value($config);
$deleted_keys[] = $config['label'];
}
drupal_set_message(t('The following Lockr keys were deleted: %keys', [
'%keys' => implode(', ', $deleted_keys),
]), 'warning');
}
/**
* Migrate wrapping keys to config.
*/
function lockr_update_7300() {
$keys = key_get_keys_by_provider('lockr');
$secret_info = [];
foreach ($keys as $id => $key) {
$secret_info[$id] = [
'wrapping_key' => $key['key_provider_settings']['encoded'],
];
}
if ($secret_info) {
variable_set('lockr_secret_info', $secret_info);
}
}
// ex: se ft=php:
Functions
Name | Description |
---|---|
lockr_enable | Implements hook_enable(). |
lockr_uninstall | Implements hook_uninstall(). |
lockr_update_7300 | Migrate wrapping keys to config. |