Advertisement:

Author Topic: [SOLVED] Cleanup old users with no ads and not logged in for xxx period  (Read 4122 times)

Aficionado

  • Guest
I have 30000+ registered users (activated) that most are inactive (meaning Activated by not logged for a long time) and have no ads posted.

Is there a script or module for a cleanup ?

Thanks
« Last Edit: June 10, 2015, 04:57:31 pm by Aficionado »

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: Cleanup old users with no ads and not logged in for xxx period
« Reply #1 on: June 09, 2015, 05:53:03 pm »
***CORRECTED***


Hi,

Again, as in this post, you'll need to use this as one-time procedure through your theme functions.php.

Of course first do a full backup of your database, just in case. I think it would be a good idea to do this at midnight or so, because likely it'll eat up all your resources if we're talking about hundreds of users involved.

Add this at the very bottom of your theme functions.php (take care not to leave blank lines after this):

Code: [Select]
<?php
function cust_delete_inactive_users() {

    
$inactive_users User::newInstance()->search(050000'pk_i_id''ASC', array("dt_access_date < '2015-01-01'" => '''i_items' => ));

    foreach (
$inactive_users['users'] as $user) {
        
User::newInstance()->deleteUser($user['pk_i_id']);
    }

    echo 
"Done, " $inactive_users['rows'] . " inactive users where deleted from the database";
}

osc_add_hook('admin_content_footer''cust_delete_inactive_users');
?>


Change the date here (2015-01-01, year-month-day), all users that never have posted and haven't logged in after that date will be deleted.

Enter your Admin Dashboard and the process will start. Probably you'll get a timeout at first, wait a few minutes and do it again, repeat until no timeout and you may see this message in the footer (Below Osclass version):

Quote
Done, X inactive users where deleted from the database

Of course, if there were previous timeouts, you won't see the real number of deleted users, but the few last. If you want to know the exact amount compare the number before and after the procedure in your Users page.

Careful with all the steps, if something goes wrong restore your DB. At the end, delete the code from your functions.php (it wouldn't do harm, but unnecesary now).

Regards
« Last Edit: June 09, 2015, 06:34:35 pm by teseo »

Aficionado

  • Guest
Re: Cleanup old users with no ads and not logged in for xxx period
« Reply #2 on: June 09, 2015, 05:55:58 pm »
What should be the date format ?

I mean

year / month / day

or what we have put in osclass settings ? It is important to know.

Thanks

Aficionado

  • Guest
Re: Cleanup old users with no ads and not logged in for xxx period
« Reply #3 on: June 09, 2015, 05:57:37 pm »
Teseo looking at the script, what if a user has ads posted ? I don't see any check or i'm missing something ?

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: Cleanup old users with no ads and not logged in for xxx period
« Reply #4 on: June 09, 2015, 06:32:50 pm »
You're right, "with no ads" wasn't taken into account, I've fixed it in the original post now.

Quote
What should be the date format ?

I mean

year / month / day

Yes, year-month-day, it's like dates are stored in the database, independently of Admin settings.

Regards


SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2519
Re: Cleanup old users with no ads and not logged in for xxx period
« Reply #5 on: June 10, 2015, 02:04:49 am »
How about Butler Plugin? ::)

Fairly new, april 2015 by Osclass:
Quote
This plugin will help you get rid of the dreadful task of manually reviewing those listings and users. Just set expiration deadlines for each type of listings and users you choose(spam, non-activated, expired). Butler plugin will automatically delete those listings after the number of days you have set. You can also configure a maximum number of listings that will be deleted each time. It’s ideal if you have a high traffic website and will definitely help you gain more free space.


I have 30000+ registered users (activated) that most are inactive (meaning Activated by not logged for a long time) and have no ads posted.

Is there a script or module for a cleanup ?

Thanks
« Last Edit: June 10, 2015, 02:06:42 am by SmaRTeY »

Aficionado

  • Guest
Re: Cleanup old users with no ads and not logged in for xxx period
« Reply #6 on: June 10, 2015, 02:22:27 am »
@Smartey

The Butler plugin just deleted UNactivated users. Not inactive.

Not sure what the plugin programmer had in mind, but i can assure you he doesn't run an Osclass website ...

« Last Edit: June 10, 2015, 02:24:36 am by Aficionado »

SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2519
Re: Cleanup old users with no ads and not logged in for xxx period
« Reply #7 on: June 10, 2015, 02:24:25 am »
Ah okay I got ya, looked like a match but looks can be deceiving ;)

@Smartey

The Butler plugin just deleted UNactivated users. Not inactive.

Aficionado

  • Guest
Re: Cleanup old users with no ads and not logged in for xxx period
« Reply #8 on: June 10, 2015, 04:13:49 pm »
@Teseo

Thanks for the code, works very well for me.

 :D

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: Cleanup old users with no ads and not logged in for xxx period
« Reply #9 on: June 10, 2015, 04:42:56 pm »
You're welcome. :) Please add [SOLVED] to the title of this thread.

PS.- I didn't even know that plugin Butler, I guess progressive deleting using Cronjobs would be the way to go, but I don't have enough time to convert this into a modification of the plugin. It will have to do for now.

Aficionado

  • Guest
Maybe Cartagena68 could add this cleanup to his Renew Ads plugin.


SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2519
Re: Cleanup old users with no ads and not logged in for xxx period
« Reply #11 on: June 10, 2015, 10:04:55 pm »
Actually I suggested in Butler review the same; adding the option of removing activated users after x days of not having posted. Not sure if it will be picked up ofcourse ;)

You're welcome. :) Please add [SOLVED] to the title of this thread.

PS.- I didn't even know that plugin Butler, I guess progressive deleting using Cronjobs would be the way to go, but I don't have enough time to convert this into a modification of the plugin. It will have to do for now.

Aficionado

  • Guest
Re: [SOLVED] Cleanup old users with no ads and not logged in for xxx period
« Reply #12 on: September 13, 2016, 05:18:09 pm »
@Teseo

One question:

I see in Admin / Users their Items number >1 while in their profile shows no ads (and they have NO ads).

This part of your script in this thread:

Code: [Select]
    $inactive_users = User::newInstance()->search(0, 50000, 'pk_i_id', 'ASC', array("dt_access_date < '2015-01-01'" => '', 'i_items' => 0 ));

   

reads the item number as i write above ? Or something else ?

Thanks
« Last Edit: September 13, 2016, 05:21:31 pm by Aficionado »

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: [SOLVED] Cleanup old users with no ads and not logged in for xxx period
« Reply #13 on: September 13, 2016, 08:58:34 pm »
Hi,

That "i_items" should be the number of active ads that the user has, as stored on t_user table. Your numbers being inconsistent, well, I've seen worse. :D Any poorly programmed plugin might have caused that at some point. ???

Regards

Aficionado

  • Guest
Re: [SOLVED] Cleanup old users with no ads and not logged in for xxx period
« Reply #14 on: September 13, 2016, 09:47:00 pm »
Hi,

That "i_items" should be the number of active ads that the user has, as stored on t_user table. Your numbers being inconsistent, well, I've seen worse. :D Any poorly programmed plugin might have caused that at some point. ???

Regards

Thanks for the reply.

As for incosistent items, the thing is, i don't use any plugin that works with users or users items.

Apart from the Renew plugin from Cartagena but that (i guess) works only when a renew is happening.