1
irmtfan
mass delete of users in 2.2+
  • 2005/11/3 17:03

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


i wrote a MySQL code to delete inactive users in 2.0 but in 2.2 i dont now how to delete users. there are 2 table "xoops_users" and " xoops_profile_users". i want a code to run it in cron job and this code delete all inactive users that register more than X days ago.

2
irmtfan
Re: mass delete of users in 2.2+
  • 2005/11/4 14:07

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


mysql code for delete inactive users in 2.0 is:


define
("user""user");

define("pass""pass");

define("host""localhost");

define("db""db");

$cxn mysql_connect(host ,userpass);

mysql_select_db(db);
$delete_time time() - ( 10 24 60 60 );  // 10 days/month * 24 hrs/day

// * 60 minutes/hour * 60 seconds/min.



$sql "DELETE from `xoops_users` WHERE `last_login` = '0' AND `user_regdate` < '$delete_time'";

//This script would delete everyuser older than 10 days that has been not active.



$result mysql_query($sql$cxn);


now i want the same code for 2.2 PLEASE...

3
Mithrandir
Re: mass delete of users in 2.2+

code for both 2.0.x and 2.2:

$member_handler xoops_gethandler('member');
$criteria = new Criteria("level"0); //target inactive users
$users $member_handler->getUsers($criteria);
foreach (
array_keys($users) as $i) {
    if (
$member_handler->deleteUser($users[$i]) ) {
        echo 
$users[$i]->getVar('uname')." Deleted";
    }
    else {
        echo 
"Could not delete ".$users[$i]->getVar('uname')."";
    }
}


Will only work with a POST request, so make a form that submits to this code with the POST method.

We will refine the administrative possibilities in the Profile module over the next iterations and welcome any ideas you may have for needed functionality and workflow.
"When you can flatten entire cities at a whim, a tendency towards quiet reflection and seeing-things-from-the-other-fellow's-point-of-view is seldom necessary."

Cusix Software

4
irmtfan
Re: mass delete of users in 2.2+
  • 2005/11/13 16:58

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


thank you mith. it works fine. but i want a script to:

1- run from a cron job NOT by click on a "submit" link.
2- i dont want delete all inactive users just want to delete inactive users that register more that X days ago.( to free their emails , ...)

5
abbey
Re: mass delete of users in 2.2+
  • 2005/11/13 17:01

  • abbey

  • Just popping in

  • Posts: 50

  • Since: 2005/3/17


But what do you do if you want to move your registered users to a new database?
Visit GhanaMusic.com: The Largest electronic news source of information on the Ghanaian music industry.

6
irmtfan
Re: mass delete of users in 2.2+
  • 2005/11/13 17:11

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


this script only delete all inactive users( whos dont click on activation link)there is no problem with registered users for move to another database or anything else.

7
irmtfan
Re: mass delete of users in 2.2+
  • 2005/11/14 17:07

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


now i can add the " delete all inactive users whose register more than X days ago":

// $Id: delete_users.php 
include '../../mainfile.php';
$member_handler xoops_gethandler('member');
$criteria = new Criteria("level"0); //target inactive users
$users $member_handler->getUsers($criteria);
$delete_regdatetime() - ( $days 24 60 60 );  // X days/month * 24 hrs/day
foreach (array_keys($users) as $i) {
   if (
$users[$i]->getVar('user_regdate') < $delete_regdate){ //all users whose register more than X days ago
    
if ($member_handler->deleteUser($users[$i]) ) {
        echo 
$users[$i]->getVar('uname')." Deleted";
    }
    else {
        echo 
"Could not delete ".$users[$i]->getVar('uname')."";
    }
    }

}
?>


and the html form is:
<form style="margin-bottom: 0px; margin-top: 0px;" action="<{$xoops_siteurl}>delete_users.php" method="post">
register more than X days ago
<input type="text" name="days" size="20"> <br>
<
input name="Submit" type="image" value="user_delete" />
form>


but still i want a way to run the script with a cron job not by click on a "submit" link. anybody can help?

8
helman
Re: mass delete of users in 2.2+
  • 2005/11/24 23:28

  • helman

  • Just popping in

  • Posts: 15

  • Since: 2005/9/30


This looks like what I need. Can anyone give me a little help putting this together?

I think I need to create a directory at the XOOPS directory level, copy the html into an html document, put the php code into a php file.

Then type the HTML address and press submit?

Shouldn't this be part of the user module?

Cheers

9
helman
Re: mass delete of users in 2.2+
  • 2005/11/30 1:27

  • helman

  • Just popping in

  • Posts: 15

  • Since: 2005/9/30


Anyone able to help here?

Many thanks

10
terrion
Re: mass delete of users in 2.2+
  • 2006/5/20 22:38

  • terrion

  • Friend of XOOPS

  • Posts: 299

  • Since: 2004/9/19


I'm needing the same thing. Thought I'd give this thread a bump.
Terrion
Purchase, renew, or transfer your domain name to Ultranet Domains and get a FREE 10GB hosting account. Virtual Dedicated Servers around $35/monthly, no contract. FREE 24/7 telephone ...

Login

Who's Online

381 user(s) are online (260 user(s) are browsing Support Forums)


Members: 0


Guests: 381


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits