Delete all current users who don't have userpoints

himagarwal - September 4, 2009 - 18:14
Project:User Points
Version:5.x-3.7
Component:User interface
Category:support request
Priority:normal
Assigned:Unassigned
Status:closed
Description

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?

#1

kbahey - September 4, 2009 - 19:00
Status:active» postponed (maintainer needs more info)

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

himagarwal - September 4, 2009 - 19:13

Thank you so much. That did the job :-)

#3

kbahey - September 4, 2009 - 19:15
Status:postponed (maintainer needs more info)» fixed

#4

System Message - September 18, 2009 - 19:20
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

#5

himagarwal - October 5, 2009 - 12:47

@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

kbahey - October 5, 2009 - 13:54

No.

This is left as an exercise for the reader ... ;-)

#7

himagarwal - October 6, 2009 - 15:42

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

kbahey - October 6, 2009 - 15:47

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

himagarwal - October 7, 2009 - 11:52

Thank you so much kbahey.

I will test it soon!

:-)

#10

himagarwal - October 8, 2009 - 12:17

It worked like a charm!

You've been kind. Thank you again.

 
 

Drupal is a registered trademark of Dries Buytaert.