Reputation: 417
for an project we are using the liferay and for the user handling we are using the ldap.
The user when deleted from the ldap is not updating the database of the liferay and hence if a user to be added after deleting it, it is causing the problem.
I tried to found out the cause and seems like one has to delete the users from many tables. Manually we can delete it like mentioned below.
DELETE FROM Users_UserGroups WHERE userId = 'userid';
DELETE FROM Users_Roles WHERE userId = 'userid';
DELETE FROM Users_Orgs WHERE userId = 'userid';
DELETE FROM Contact_ WHERE userId = 'userid';
DELETE FROM Group_ WHERE classPK = 'userid';
DELETE FROM User_ WHERE userId = 'userid';
but programatically how can we do that.
I tried using:
UserLocalServiceUtil.deleteUser(UserLocalServiceUtil
.getUserByEmailAddress(companyid, email));
But its not working properly. what are the other ways to do that?
Upvotes: 0
Views: 1749
Reputation: 323
Get the email of the users that you want to delete from the User_ table . And insert it in ArrayList .
In my case i have placed this code in a sample program and run this code once.
`
List<User> users = UserLocalServiceUtil.getUsers(QueryUtil.ALL_POS, QueryUtil.ALL_POS);
ArrayList<String> places = new ArrayList<String>(Arrays.asList("[email protected]","[email protected]"));
for (User user : users) {
if (places.contains(user.getEmailAddress())) {
System.out.println("user "+user.getEmailAddress()+" deleted");
UserLocalServiceUtil.deleteUser(user);
}
}
`
Hope this helps!!
Upvotes: 1
Reputation: 48057
Despite my comment "please define it's not working properly", I'd like to give an answer that shows up an alternative. Instead of giving you the solution to the words of your question, this will address the underlying problem. If you need an actual answer to the words of your question, please describe what you're observing.
Deleting a user is a dangerous operation: You might leave dangling references, e.g. if that user has participated in some activities in a portlet. They might be authors of blog posts, content articles or message board messages. And this is not an exhaustive list.
Therefor it's always better to just deactivate a user - this way their name, portrait image and other data is always available even long after they're allowed to log in.
Upvotes: 2