From 0186194ae969dfebe260733a587e83984a11230f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Mon, 20 Feb 2023 17:34:53 +0100 Subject: [PATCH] Properly test and log when a group is not found MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Avoid an error about passing null instead of IGroup to the event constructor, instead skip the failed group and log the problem. Signed-off-by: Côme Chilliet --- apps/user_ldap/lib/Jobs/UpdateGroups.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/apps/user_ldap/lib/Jobs/UpdateGroups.php b/apps/user_ldap/lib/Jobs/UpdateGroups.php index 86b4b2b59f425..48687494a6105 100644 --- a/apps/user_ldap/lib/Jobs/UpdateGroups.php +++ b/apps/user_ldap/lib/Jobs/UpdateGroups.php @@ -44,7 +44,7 @@ use Psr\Log\LoggerInterface; class UpdateGroups extends TimedJob { - /** @var ?array */ + /** @var ?array */ private ?array $groupsFromDB = null; private Group_Proxy $groupBackend; private IEventDispatcher $dispatcher; @@ -157,6 +157,17 @@ private function handleKnownGroups(array $groups): void { $hasChanged = false; $groupObject = $this->groupManager->get($group); + if ($groupObject === null) { + /* We are not expecting the group to not be found since it was returned by $this->groupBackend->getGroups() */ + $this->logger->error( + 'bgJ "updateGroups" – Failed to get group {group} for update', + [ + 'app' => 'user_ldap', + 'group' => $group + ] + ); + continue; + } foreach (array_diff($knownUsers, $actualUsers) as $removedUser) { $userObject = $this->userManager->get($removedUser); if ($userObject instanceof IUser) {