function openid_connect_update_8105 in OpenID Connect / OAuth client 8
Same name and namespace in other branches
- 2.x openid_connect.install \openid_connect_update_8105()
Delete duplicate entries in the openid_connect_authmap table.
File
- ./
openid_connect.install, line 120 - Install, update and uninstall functions for the OpenID Connect module.
Code
function openid_connect_update_8105() {
$database = \Drupal::database();
// Get the IDs for the duplicate entries.
$query = $database
->select('openid_connect_authmap', 'a1')
->fields('a1', [
'aid',
]);
$query
->innerJoin('openid_connect_authmap', 'a2', 'a1.uid = a2.uid AND a1.client_name = a2.client_name AND a1.sub = a2.sub');
$query
->where('a1.aid > a2.aid');
$aids = $query
->distinct()
->execute()
->fetchAllAssoc('aid');
if (!empty($aids)) {
// If duplicates exist, delete them.
$database
->delete('openid_connect_authmap')
->condition('aid', array_keys($aids), 'IN')
->execute();
}
}