Osclass forums

Support forums => old => Topic started by: Aficionado on June 09, 2015, 04:44:21 pm

Title: [SOLVED] Cleanup old users with no ads and not logged in for xxx period
Post by: Aficionado on June 09, 2015, 04:44:21 pm
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
Title: Re: Cleanup old users with no ads and not logged in for xxx period
Post by: teseo on June 09, 2015, 05:53:03 pm
***CORRECTED***


Hi,

Again, as in this post (http://forums.osclass.org/3-5-x/slugs-missing/msg123424/#msg123424), 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
Title: Re: Cleanup old users with no ads and not logged in for xxx period
Post by: Aficionado 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
Title: Re: Cleanup old users with no ads and not logged in for xxx period
Post by: Aficionado 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 ?
Title: Re: Cleanup old users with no ads and not logged in for xxx period
Post by: teseo 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

Title: Re: Cleanup old users with no ads and not logged in for xxx period
Post by: SmaRTeY 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
Title: Re: Cleanup old users with no ads and not logged in for xxx period
Post by: Aficionado 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 ...

Title: Re: Cleanup old users with no ads and not logged in for xxx period
Post by: SmaRTeY 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.
Title: Re: Cleanup old users with no ads and not logged in for xxx period
Post by: Aficionado on June 10, 2015, 04:13:49 pm
@Teseo

Thanks for the code, works very well for me.

 :D
Title: Re: Cleanup old users with no ads and not logged in for xxx period
Post by: teseo 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.
Title: Re: [SOLVED] Cleanup old users with no ads and not logged in for xxx period
Post by: Aficionado on June 10, 2015, 05:18:24 pm
Maybe Cartagena68 could add this cleanup to his Renew Ads plugin.

Title: Re: Cleanup old users with no ads and not logged in for xxx period
Post by: SmaRTeY 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.
Title: Re: [SOLVED] Cleanup old users with no ads and not logged in for xxx period
Post by: Aficionado 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
Title: Re: [SOLVED] Cleanup old users with no ads and not logged in for xxx period
Post by: teseo 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
Title: Re: [SOLVED] Cleanup old users with no ads and not logged in for xxx period
Post by: Aficionado 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.

Title: Re: [SOLVED] Cleanup old users with no ads and not logged in for xxx period
Post by: Aficionado on September 13, 2016, 09:52:23 pm
Actually just now i realized that is a bug of Osclass.

Easy to replicate:

Mark FIRST a post as SPAM and then delete it. The count of the user items doesn't change.
Title: Re: [SOLVED] Cleanup old users with no ads and not logged in for xxx period
Post by: teseo on September 13, 2016, 10:00:52 pm
When you mark an ad as spam, the total count decreases already, so no difference later when you delete it.

Regards

Title: Re: [SOLVED] Cleanup old users with no ads and not logged in for xxx period
Post by: Aficionado on September 13, 2016, 10:15:48 pm
hm .....
Title: Re: [SOLVED] Cleanup old users with no ads and not logged in for xxx period
Post by: Aficionado on September 13, 2016, 10:22:00 pm
yeap.

This is the code from some spam plugin, marks as spam but doesn't update the count i guess.

Code: [Select]
function after_item_posted($item) {
if( getEnableOn() == 1 || getEnableOn() == 2 ){
  $arrstopword= getStopWords();
  $exparrstopword= explode(",", $arrstopword);
  foreach ($exparrstopword as $expstopword) {
    if (preg_match("/" . $expstopword. "/i", $item['s_title']) || preg_match("/" . $expstopword. "/i", $item['s_description'])) {
ModelSpamKiller::newInstance()->blockItem($item['pk_i_id']);
}
  }
  }
}

and

Code: [Select]

function blockItem($id){
            $this->dao->from($this->getItemTable()) ;
            $this->dao->set(array(
                'b_spam' => 1
            )) ;
            $this->dao->where(array(
                'pk_i_id' => $id
            )) ;
$this->dao->update() ;
        }
Title: Re: [SOLVED] Cleanup old users with no ads and not logged in for xxx period
Post by: teseo on September 13, 2016, 10:50:25 pm
That's why vanilla methods should be used if they exist, they are supposed to take care of everything:

Code: [Select]
if (preg_match("/" . $expstopword. "/i", $item['s_title']) || preg_match("/" . $expstopword. "/i", $item['s_description'])) {
// ModelSpamKiller::newInstance()->blockItem();
            $action = new ItemActions();
            $action->spam($item['pk_i_id']);
}

Regards