From bb0aaf89e8b4e3cb2b6c142d7f6e072bf3765fa9 Mon Sep 17 00:00:00 2001 From: Steve Bagwell Date: Fri, 12 May 2023 15:12:11 -0400 Subject: [PATCH] Create one error message for all update-failed users. --- application/common/sync/Synchronizer.php | 30 ++++++++++++++++-------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/application/common/sync/Synchronizer.php b/application/common/sync/Synchronizer.php index 2e2683f..edff262 100644 --- a/application/common/sync/Synchronizer.php +++ b/application/common/sync/Synchronizer.php @@ -137,22 +137,32 @@ protected function activateAndUpdateUser(User $user) */ protected function activateAndUpdateUsers(array $usersToUpdateAndActivate) { + $usersWithErrors = []; + $lastError = null; + $employeeIdsOfUsersUpdated = []; - foreach ($usersToUpdateAndActivate as $userToUpdateAndActivate) { + foreach ($usersToUpdateAndActivate as $nextUser) { try { - $this->activateAndUpdateUser($userToUpdateAndActivate); - $employeeIdsOfUsersUpdated[] = $userToUpdateAndActivate->getEmployeeId(); + $this->activateAndUpdateUser($nextUser); + $employeeIdsOfUsersUpdated[] = $nextUser->getEmployeeId(); } catch (Exception $e) { - $this->logger->error(sprintf( - 'Failed to update/activate user in the ID Broker (%s). Error %s: %s. [%s]', - $userToUpdateAndActivate->getStringForLogMessage(), - $e->getCode(), - $e->getMessage(), - 1494360119 - )); + $usersWithErrors[] = $nextUser->getStringForLogMessage(); + $lastError = $e; } } + if ($lastError !== null) { + $this->logger->error(sprintf( + 'Failed to update/activate user(s) in the ID Broker. Last error %s: %s. [%s].' + . ' Failed for %s users, including: %s', + $lastError->getCode(), + $lastError->getMessage(), + 1494360119, + count($usersWithErrors), + join(', ', array_slice($usersWithErrors, -6)) // last six users + )); + } + $this->logger->notice([ 'action' => 'update', 'attempted' => count($usersToUpdateAndActivate),