You are here

function openid_connect_update_8204 in OpenID Connect / OAuth client 2.x

Move all 'openid_connect_authmap' data to 'authmap'.

File

./openid_connect.install, line 210
Install, update and uninstall functions for the OpenID Connect module.

Code

function openid_connect_update_8204() {
  $database = \Drupal::database();

  // Get all records and move them to the authmap table.
  $query = $database
    ->select('openid_connect_authmap', 'a')
    ->fields('a');
  $authmap_records = $query
    ->execute()
    ->fetchAllAssoc('aid');
  foreach ($authmap_records as $authmap_record) {
    $database
      ->merge('authmap')
      ->keys([
      'uid' => $authmap_record->uid,
      'provider' => 'openid_connect.' . $authmap_record->client_name,
    ])
      ->fields([
      'authname' => $authmap_record->sub,
      'data' => 'N;',
    ])
      ->execute();
  }
}