Forums de discussion

method to delete a line from users_groups

thumbnail
asile elisa, modifié il y a 14 années.

method to delete a line from users_groups

Regular Member Publications: 126 Date d'inscription: 17/02/10 Publications récentes
hi everyone,

I added a new community Mycommunity and I find it in group table
I find haw to add a user in this community :it is done by the method

UserServiceUtil.addGroupUsers(idGroup, addUserIds);

and this method added a line in the table users_groups this table mapped a user with a particular group

but I did not find how to delete this assignment

thanks in advance
thumbnail
Sandeep Nair, modifié il y a 14 années.

RE: method to delete a line from users_groups

Liferay Legend Publications: 1744 Date d'inscription: 06/11/08 Publications récentes
Hi,

Try this

UserServiceUtil.unsetGroupUsers(groupId,userIds);


Regards,
Sandeep
thumbnail
asile elisa, modifié il y a 14 années.

RE: method to delete a line from users_groups

Regular Member Publications: 126 Date d'inscription: 17/02/10 Publications récentes
thanks it works ;)
thumbnail
asile elisa, modifié il y a 14 années.

RE: method to delete a line from users_groups

Regular Member Publications: 126 Date d'inscription: 17/02/10 Publications récentes
hi,
do you have an idea how can I update a line or I will have to remove it and recreat it?

thanks in advance.
thumbnail
Ivan Cheung, modifié il y a 14 années.

RE: method to delete a line from users_groups

Regular Member Publications: 113 Date d'inscription: 20/06/06 Publications récentes
asile elisa:
hi,
do you have an idea how can I update a line or I will have to remove it and recreat it?

thanks in advance.


Hmm, what exactly do you mean by "update a line"?
thumbnail
asile elisa, modifié il y a 14 années.

RE: method to delete a line from users_groups

Regular Member Publications: 126 Date d'inscription: 17/02/10 Publications récentes
hi,

I mean to change the assignement, change the user community,
change the idGroup for a particular user

thanks
thumbnail
Ivan Cheung, modifié il y a 14 années.

RE: method to delete a line from users_groups

Regular Member Publications: 113 Date d'inscription: 20/06/06 Publications récentes
You can use:

UserLocalServiceUtil.updateGroups(long userId, long[] newGroupIds)



If you look at the implementation you'll see that the logic unsets old groups and adds new groups.


		for (Group oldGroup : oldGroups) {
			long oldGroupId = oldGroup.getGroupId();

			oldGroupIds.add(oldGroupId);

			if (!ArrayUtil.contains(newGroupIds, oldGroupId)) {
				unsetGroupUsers(oldGroupId, new long[] {userId});
			}
		}

		for (long newGroupId : newGroupIds) {
			if (!oldGroupIds.contains(newGroupId)) {
				addGroupUsers(newGroupId, new long[] {userId});
			}
		}


thumbnail
asile elisa, modifié il y a 14 années.

RE: method to delete a line from users_groups

Regular Member Publications: 126 Date d'inscription: 17/02/10 Publications récentes
thank you
but I have an older version I use liferay 4.2 and I did not find this method in UserLocalServiceUtil.
thumbnail
Ivan Cheung, modifié il y a 14 années.

RE: method to delete a line from users_groups

Regular Member Publications: 113 Date d'inscription: 20/06/06 Publications récentes
Sorry, if the equivalent method is not available in 4.2, then you'll just have to do it the long way by unsetting and adding groups for each user.

Another option is if you extend the 4.2 version of UserLocalServiceImpl in the EXT environment to create an upgradeGroups equivalent.