You are here

function lockr_update_8401 in Lockr 4.x

Same name and namespace in other branches
  1. 8.4 lockr.install \lockr_update_8401()

Migrate wrapping keys from basic config to entities.

File

./lockr.install, line 62

Code

function lockr_update_8401() {
  $entity_type_manager = \Drupal::service('entity_type.manager');
  $storage = $entity_type_manager
    ->getStorage('lockr_secret');
  $config_factory = \Drupal::service('config.factory');
  $config = $config_factory
    ->getEditable('lockr.secret_info');
  foreach ($config
    ->get() as $name => $info) {
    $secret = $storage
      ->load($name);
    if (is_null($secret)) {
      $secret = $storage
        ->create([
        'id' => $name,
        'key_id' => $name,
      ]);
    }
    $secret
      ->setInfo($info);
    $secret
      ->save();
  }
  $config
    ->delete();
}