You are here

function lockr_uninstall in Lockr 7.2

Same name and namespace in other branches
  1. 7.3 lockr.install \lockr_uninstall()
  2. 7 lockr.install \lockr_uninstall()

Implements hook_uninstall().

Delete any keys that use Lockr as the key provider.

File

./lockr.install, line 23
Install, uninstall, and update functions for lockr.

Code

function lockr_uninstall() {

  // Load the key configurations.
  $configs = db_query("SELECT * FROM {key_config} WHERE key_provider = :provider", array(
    ':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 = array();

  // 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', array(
    '%keys' => implode(', ', $deleted_keys),
  )), 'warning');
}