Skip to content
Snippets Groups Projects
Commit 279002ee authored by Marco Villegas's avatar Marco Villegas Committed by Neil Drumm
Browse files

Issue #3437760: Keycloak related user counting drush commands

parent c3ce6a6d
Branches
No related tags found
3 merge requests!312Issue # 3494493: Documentation: Document Maintainer Widget,!299Remove heroes from components field. Update CTA section and add variants.,!243Add new drupalorg-keycloak-users-count drush command
......@@ -156,6 +156,9 @@ function drupalorg_drush_command() {
'drupalorg-keycloak-random-users-integrity' => [
'description' => 'Integrity check migration of random users',
],
'drupalorg-keycloak-users-count' => [
'description' => 'Reports total users in drupal and keycloak',
],
];
}
......@@ -1872,3 +1875,26 @@ function drush_drupalorg_keycloak_random_users_integrity() {
}
printf("Finished integrity check of (%d) users.\n", count($uids));
}
function drush_drupalorg_keycloak_users_count() {
printf("Starting user counting.\n");
$drupal_users_count = db_select('users')
->countQuery()
->execute()
->fetchField();
$drupal_authmap_count = db_select('authmap')
->countQuery()
->execute()
->fetchField();
$integration = new KeycloakIntegration();
$keycloak_users_count = $integration->countUsers();
if ($drupal_users_count == $keycloak_users_count && $drupal_users_count == $drupal_authmap_count) {
printf("Total user count matches: %d.\n", $drupal_users_count);
}
else {
printf("Total user counts does not match.\n");
printf("Drupal users: %d.\n", $drupal_users_count);
printf("Drupal authmap: %d.\n", $drupal_authmap_count);
printf("Keycloak users: %d.\n", $keycloak_users_count);
}
}
......@@ -333,4 +333,13 @@ class KeycloakIntegration {
return $success;
}
public function countUsers() {
$this->authenticate();
$result = $this->invoke(sprintf('admin/realms/%s/users/count', $this->authOptions()['realm']), 'GET');
$success = \in_array($result->getStatusCode(), range(200, 299), TRUE);
if ($success) {
return (string) $result->getBody();
}
return NULL;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment