Posted by himagarwal on September 4, 2009 at 6:14pm
Jump to:
| Project: | User Points |
| Version: | 5.x-3.7 |
| Component: | User interface |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (fixed) |
Issue Summary
I'll be doing mass change in one of my website. Is it possible to delete all current users who have no user points and retain only those users who have userpoints?
Comments
#1
You need a small php script to do that.
Put this in a script called cleanup.php, and put the following in it:
<?php
require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
// Get a list of all users in the site
$result = db_query("SELECT uid FROM {users} WHERE uid > 1");
while($row = db_fetch_object($result)) {
// Find out how many points this user has
$points = userpoints_get_current_points($row->uid);
// Check if the points are zero
if (!$points) {
// Delete the user if they have no points
user_delete(array(), $row->uid);
}
}
?>
Then, browse to example.com/cleanup.php
After this runs, delete the script so no one can run it again.
#2
Thank you so much. That did the job :-)
#3
#4
Automatically closed -- issue fixed for 2 weeks with no activity.
#5
@kbahey,
Thank you for the earlier script. Is there also a script which deletes all the current users who have user points and retain only those users who have no user points. Well, exactly opposite of what you provided in above script.
#6
No.
This is left as an exercise for the reader ... ;-)
#7
Can anyone please help. I'm not a coder but I think this may be a little tweak in the above code. Any help will be appreciated.
#8
It would be like this:
<?php
// Delete users who have positive or negative points. Leave users who have
// no points as they are
require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
// Get a list of all users in the site
$result = db_query("SELECT uid FROM {users} WHERE uid > 1");
while($row = db_fetch_object($result)) {
// Find out how many points this user has
$points = userpoints_get_current_points($row->uid);
// Check if the user has positive or negative points
if ($points >0 || $point < 0) {
// Delete the user
user_delete(array(), $row->uid);
}
}
?>
#9
Thank you so much kbahey.
I will test it soon!
:-)
#10
It worked like a charm!
You've been kind. Thank you again.