You are here

function lockr_update_8302 in Lockr 4.x

Same name and namespace in other branches
  1. 8.4 lockr.install \lockr_update_8302()
  2. 8.3 lockr.install \lockr_update_8302()

Migrate wrapping keys from key to secret info config.

File

./lockr.install, line 30

Code

function lockr_update_8302() {
  $key_repository = \Drupal::service('key.repository');
  $configFactory = \Drupal::service('config.factory');
  $keys = $key_repository
    ->getKeysByProvider('lockr');
  $config = $configFactory
    ->getEditable('lockr.secret_info');
  foreach ($keys as $key) {
    $name = $key
      ->id();
    if ($config
      ->get($name)) {
      continue;
    }
    $provider = $key
      ->getKeyProvider();
    $key_config = $provider
      ->getConfiguration();
    if (isset($key_config['encoded'])) {
      $config
        ->set("{$name}.wrapping_key", $key_config['encoded']);
    }
  }
  $config
    ->save();
}