6.2.5 CE GA6, 6.2.10 EE GA1, 6.2.X EE, 7.0.0 DXP GA1, 7.0.0 DXP SP2
- Optional in 6.2.x: configure Solr 4 for Liferay 6.2. I couldn't reproduce the issue using Lucene.
- Start a Liferay tomcat bundle
- Log on as administrator user ("test")
- Go to Control Panel -> Server Administration -> Script
and run the attached groovy script: remove_usergroup... or remove_organization...
The script performs these actions:
- a new userGroup/organization is created
- a new user is created and added to the usergroup
- the user is removed from the usergroup/organization
- the usergroup/organization is deleted
The last action (usergroup deletion) should complete without error messages, because the group members were already removed
A "RequiredUserGroupException" message is thrown when trying to delete the usergroup.
Detailed information on root cause:
" The same issue occurs when trying to remove Organizations.
When trying to remove an organization and/or a usergroup after removing its associated users, we get the following exceptions :
- Usergroup : com.liferay.portal.RequiredUserGroupException
- Organization: com.liferay.portal.RequiredOrganizationException
We are using the following API to remove users :
- usergroups : UserLocalServiceUtil.unsetUserGroupUsers
- organizations : UserLocalServiceUtil.unsetOrganizationUsers
We found out that those two methods are reindexing search index User document after the assocation between user and usergroup/organization has been removed. However, when trying to remove the organization/usergroup using the methods :
- usergroup : UserGroupLocalServiceUtil.deleteUserGroup(usergroup)
- organization: OrganizationLocalServiceUtil.deleteOrganization(organization)
The first action in those two methods is to retrieve the users count in usergroup/organization:
- Usergroup : userLocalService.getUserGroupUsersCount
- Organization: userLocalService.getOrganizationUsersCount
Those two methods are calling the Search Index to retrieve the count. As the search index may not be up to date at the time being due to an asynchronous process to reindex user, the RequiredOrganizationException/RequiredUserGroupException exception is raised, even though the users relations were previously removed. "
Reproduced on 6.2.x (865b426c13a129dec3d3ca3ac6a1b75d378e32d2)
Reproduced on Master (ee853d5384071a1af8b730a4d31076688175b0f8)