Commit 3b000319 authored by jcnventura's avatar jcnventura Committed by Joao Ventura

Issue #2932976 by jcnventura: Rename plugin IDs in users_data.

parent 4e4becd0
......@@ -90,3 +90,51 @@ function ga_login_update_8002() {
$config->save();
}
/**
* Update plugin names from tfa prefix to ga_login in users_data.
*/
function ga_login_update_8003(&$sandbox) {
/** @var \Drupal\user\UserData $user_data */
$user_data = \Drupal::service('user.data');
$tfa_settings = $user_data->get('tfa', NULL, 'tfa_user_settings');
// Setup batch.
if (!isset($sandbox['total'])) {
$sandbox['total'] = count($tfa_settings);
$sandbox['current'] = 0;
}
$batch_size = 50;
foreach (array_slice($tfa_settings, $sandbox['current'], $batch_size, TRUE) as $uid => $user_settings) {
$changed = FALSE;
$plugins = $user_settings['data']['plugins'];
$new_plugins = [];
foreach ($plugins as $key => $plugin) {
switch ($key) {
case 'tfa_hotp':
case 'tfa_totp':
$new_key = str_replace('tfa_', 'ga_login_', $key);
$new_plugins[$new_key] = $new_key;
$changed = TRUE;
break;
default:
$new_plugins[$key] = $key;
break;
}
}
if ($changed) {
$user_settings['data']['plugins'] = $new_plugins;
$user_data->set('tfa', $uid, 'tfa_user_settings', $user_settings);
}
$sandbox['current']++;
}
if ($sandbox['total'] == 0) {
$sandbox['#finished'] = 1;
}
else {
$sandbox['#finished'] = ($sandbox['current'] / $sandbox['total']);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment