summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/Core/User/GroupSync.php27
-rw-r--r--app/Model/GroupModel.php20
2 files changed, 30 insertions, 17 deletions
diff --git a/app/Core/User/GroupSync.php b/app/Core/User/GroupSync.php
index d0bb647b..0e2a87fe 100644
--- a/app/Core/User/GroupSync.php
+++ b/app/Core/User/GroupSync.php
@@ -16,8 +16,8 @@ class GroupSync extends Base
* Synchronize group membership
*
* @access public
- * @param integer $userId
- * @param array $externalGroupIds
+ * @param integer $userId
+ * @param string[] $externalGroupIds
*/
public function synchronize($userId, array $externalGroupIds)
{
@@ -30,21 +30,18 @@ class GroupSync extends Base
* Add missing groups to the user
*
* @access protected
- * @param integer $userId
- * @param array $userGroups
- * @param array $externalGroupIds
+ * @param integer $userId
+ * @param array $userGroups
+ * @param string[] $externalGroupIds
*/
protected function addGroups($userId, array $userGroups, array $externalGroupIds)
{
$userGroupIds = array_column($userGroups, 'external_id', 'external_id');
+ $externalGroups = $this->groupModel->getByExternalIds($externalGroupIds);
- foreach ($externalGroupIds as $externalGroupId) {
- if (! isset($userGroupIds[$externalGroupId])) {
- $group = $this->groupModel->getByExternalId($externalGroupId);
-
- if (! empty($group)) {
- $this->groupMemberModel->addUser($group['id'], $userId);
- }
+ foreach ($externalGroups as $externalGroup) {
+ if (! isset($userGroupIds[$externalGroup['external_id']])) {
+ $this->groupMemberModel->addUser($externalGroup['id'], $userId);
}
}
}
@@ -53,9 +50,9 @@ class GroupSync extends Base
* Remove groups from the user
*
* @access protected
- * @param integer $userId
- * @param array $userGroups
- * @param array $externalGroupIds
+ * @param integer $userId
+ * @param array $userGroups
+ * @param string[] $externalGroupIds
*/
protected function removeGroups($userId, array $userGroups, array $externalGroupIds)
{
diff --git a/app/Model/GroupModel.php b/app/Model/GroupModel.php
index 5acf7e3f..ca15d409 100644
--- a/app/Model/GroupModel.php
+++ b/app/Model/GroupModel.php
@@ -45,10 +45,10 @@ class GroupModel extends Base
}
/**
- * Get a specific group by external id
+ * Get a specific group by externalID
*
* @access public
- * @param integer $external_id
+ * @param string $external_id
* @return array
*/
public function getByExternalId($external_id)
@@ -57,6 +57,22 @@ class GroupModel extends Base
}
/**
+ * Get specific groups by externalIDs
+ *
+ * @access public
+ * @param string[] $external_ids
+ * @return array
+ */
+ public function getByExternalIds(array $external_ids)
+ {
+ if (empty($external_ids)) {
+ return [];
+ }
+
+ return $this->db->table(self::TABLE)->in('external_id', $external_ids)->findAll();
+ }
+
+ /**
* Get all groups
*
* @access public