0

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?

Navankur Chauhan
  • 407
  • 6
  • 22

2 Answers2

2

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.

Olaf Kock
  • 46,930
  • 8
  • 59
  • 90
  • the problem i am facing is more related to creating the users again with the same email address. when i recreate them they gets imported to the liferay datbase and dont gets authenticate...also that doesnot shows any logs of exception etc. so i am unable to find the cause ... – Navankur Chauhan Jan 07 '17 at 05:56
  • If you have already manually deleted rows from your database all bets are off. You should never do that, because this api routines don't recognize the data they find – Olaf Kock Jan 08 '17 at 20:20
  • Yes I tried deleting the users manually from the mentioned tables. So what are the options now. – Navankur Chauhan Jan 10 '17 at 09:36
  • 1
    1. establish policies so that this doesn't happen again, 2. restore from backup (from before any manual operation on the database. Otherwise: The database is inconsistent already, and it's hard to name every table that now also needs to be touched (and I assume that these were not the only changes you did manually to the database). As first aid, "reindex all" from "Server Administration" in Control Panel might help, but it's definitely not all you need. – Olaf Kock Jan 10 '17 at 10:43
1

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("a@vc.com","abc@abc.com"));
for (User user : users) {
    if (places.contains(user.getEmailAddress())) {
        System.out.println("user "+user.getEmailAddress()+" deleted");
        UserLocalServiceUtil.deleteUser(user);
    }
}

`

Hope this helps!!

Navankur Chauhan
  • 407
  • 6
  • 22
Varun Chawla
  • 303
  • 1
  • 6
  • 19
  • 1
    @Navankur Thats all the game of logic . Use this.. `List users = UserLocalServiceUtil.getUsers(QueryUtil.ALL_POS, QueryUtil.ALL_POS); ArrayList places = new ArrayList<(Arrays.asList("a@vc.com","abc@abc.com"); for (User user : users) { if (!places.contains(user.getEmailAddress())) { System.out.println("user "+user.getEmailAddress()+" deleted"); UserLocalServiceUtil.deleteUser(user); } }` – Varun Chawla Jan 13 '17 at 11:16