diff --git a/libraries/src/User/UserHelper.php b/libraries/src/User/UserHelper.php index f4450fc59acfa..a000478ae5f41 100644 --- a/libraries/src/User/UserHelper.php +++ b/libraries/src/User/UserHelper.php @@ -43,23 +43,22 @@ public static function addUserToGroup($userId, $groupId) // Add the user to the group if necessary. if (!in_array($groupId, $user->groups)) { - // Get the title of the group. + // Check whether the group exists. $db = \JFactory::getDbo(); $query = $db->getQuery(true) - ->select($db->quoteName('title')) + ->select($db->quoteName('id')) ->from($db->quoteName('#__usergroups')) ->where($db->quoteName('id') . ' = ' . (int) $groupId); $db->setQuery($query); - $title = $db->loadResult(); // If the group does not exist, return an exception. - if (!$title) + if ($db->loadResult() === null) { throw new \RuntimeException('Access Usergroup Invalid'); } // Add the group data to the user object. - $user->groups[$title] = $groupId; + $user->groups[$groupId] = $groupId; // Store the user object. $user->save();