currently i struggle at the following problem:
my function looks so:
function sso_syncGroups($userID, $groupNames) {
// iterate
foreach($groupNames as $groupName) {
// Use special name
$groupName = 'SSO: ' . $groupName;
// Check wether group exists
$r = db_sab('SELECT id FROM '. $GLOBALS['DBHOST_TBL_PREFIX'] .'groups WHERE name='. _esc($groupName));
if($r) {
$groupId = $r->id;
} else {
$groupId = ins_m(
$GLOBALS['DBHOST_TBL_PREFIX'] .'groups',
'name',
_esc($groupName)
);
}
// Check wether user is in group and add it
$r = db_sab('SELECT id FROM '. $GLOBALS['DBHOST_TBL_PREFIX'] .'group_members WHERE group_id='. _esc($groupId) . ' AND user_id=' . _esc($userID));
if(!$r) {
ins_m(
$GLOBALS['DBHOST_TBL_PREFIX'] .'group_members',
'group_id, user_id',
array(
_esc($groupId),
_esc($userID)
)
);
}
}
// remove groups which are removed in external adapter
$list = '';
foreach($groupNames as $groupName) {
if($list !== '') {
$list.= ', ';
}
$list.= _esc($groupName);
}
$q = '
SELECT *
FROM '. $GLOBALS['DBHOST_TBL_PREFIX'] .'group_members
LEFT JOIN '. $GLOBALS['DBHOST_TBL_PREFIX'] .'groups ON '. $GLOBALS['DBHOST_TBL_PREFIX'] .'group_members.group_id = fud_groups.id
WHERE '. $GLOBALS['DBHOST_TBL_PREFIX'] .'group_members.user_id = ' . _esc($userID) . '
AND '. $GLOBALS['DBHOST_TBL_PREFIX'] .'groups.name NOT IN (' . $list . ')
AND '. $GLOBALS['DBHOST_TBL_PREFIX'] .'groups.name LIKE "SSO:%"
';
$groupsToRemove = uq($q);
if(method_exists($groupsToRemove, 'fetchAll')) {
$groupsToRemove = $groupsToRemove->fetchAll(PDO::FETCH_COLUMN);
foreach($groupsToRemove as $group) {
echo $group;
uq('DELETE FROM '. $GLOBALS['DBHOST_TBL_PREFIX'] .'group_members WHERE id = ' . _esc($group->id));
}
}
}
Using external_fud_login($User_ID) afterwards throws the following sql error - any idea?
HY000: Cannot execute queries while other unbuffered queries are active.
Thanks in advice - regards
Kay