You are viewing the PKP Support Forum | PKP Home Wiki

Delete users from the DB?

Are you responsible for making OJS work -- installing, upgrading, migrating or troubleshooting? Do you think you've found a bug? Post in this forum.

Moderators: jmacgreg, btbell, michael, bdgregg, barbarah, asmecher

Forum rules
What to do if you have a technical problem with OJS:

1. Search the forum. You can do this from the Advanced Search Page or from our Google Custom Search, which will search the entire PKP site. If you are encountering an error, we especially recommend searching the forum for said error.

2. Check the FAQ to see if your question or error has already been resolved.

3. Post a question, but please, only after trying the above two solutions. If it's a workflow or usability question you should probably post to the OJS Editorial Support and Discussion subforum; if you have a development question, try the OJS Development subforum.

Delete users from the DB?

Postby drw » Wed Feb 08, 2012 5:49 am

I'm working on an old OJS site (version which has a couple of thousand 'fake' registered users.
Given that it is possible to identify them, Is it possible to just delete their records from the DB users table?
If not, what else do I need to do?

many thanks,

Posts: 7
Joined: Fri Aug 19, 2011 1:08 am

Re: Delete users from the DB?

Postby JasonNugent » Sun Feb 12, 2012 12:56 pm

Hi David,

This can be a frustrating problem on older versions of OJS that did not have captcha enabled. Normally, the mergeUsers tool in the tools directory handles this sort of thing, but it only does one user at a time. There are several tables in the database that may contain user information and which wouldn't be referenced directly by username (like the user_settings table). Deleting those records can be tricky. Since these fake users would probably not have any roles or important content in OJS, my suggestion would be to write a script that wrapped the mergeUsers.php tool and called it for each of the users you wanted removed. You could assign the fake users' content (of which there would be none) to a normal user in your system. The mergeUsers tool removes the old account once it is done.

It is usually a good idea to back up your database before doing mass prunes of user accounts. Just in case.

Site Admin
Posts: 910
Joined: Tue Jan 10, 2006 6:20 am

Re: Delete users from the DB?

Postby drw » Thu Feb 16, 2012 5:04 pm

Thanks so much Jason.
Seems pretty complicated. Can you suggest somewhere I can look to see if anyone might have written such a script already?
Perhaps I'll have a go at what you suggest if the deleting from the users table causes problems. :?

I'm trying to instantiate a new v2.3.6 following the instructions in the README file and it fails, so I'm not particularly encouraged at this stage. I'll post separately about this.

Posts: 7
Joined: Fri Aug 19, 2011 1:08 am

Re: Delete users from the DB?

Postby jmacgreg » Sat Feb 25, 2012 5:09 pm

Hi David,

Just deleting the user information from the users table will likely cause problems, or at the very least leave cruft lying around in the DB, as user information is stored in other tables than the users table. This is what I do when faced with the same situation (and there are probably many ways to do this):

1) get all the spam users' user IDs (usually by querying the database to select all user IDs against a common spam identification trait -- for example, if the phone or fax field in the users table is "123456");
2) save these IDs to a text file, eg. called userIds.txt;
3) run the following PHP script

Code: Select all

$ids = file('userIds.txt', FILE_SKIP_EMPTY_LINES);

foreach ($ids as $member_id => $id) {
        echo exec ("php ojs/tools/mergeUsers.php admin " .escapeshellcmd($id));

... where "admin" is the name of the user you want all the spam users merged to.

NB: don't place/store the script anywhere where it's web-accessible. And always make a backup of your database before running something like this.

Posts: 4191
Joined: Tue Feb 14, 2006 10:50 am

Return to OJS Technical Support

Who is online

Users browsing this forum: Baidu [Spider], Google [Bot] and 2 guests