Osclass forums
Support forums => old => Topic started 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
-
***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):
<?php
function cust_delete_inactive_users() {
$inactive_users = User::newInstance()->search(0, 50000, 'pk_i_id', 'ASC', array("dt_access_date < '2015-01-01'" => '', 'i_items' => 0 ));
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):
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
-
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
-
Teseo looking at the script, what if a user has ads posted ? I don't see any check or i'm missing something ?
-
You're right, "with no ads" wasn't taken into account, I've fixed it in the original post now.
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
-
How about Butler Plugin? ::)
Fairly new, april 2015 by Osclass:
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
-
@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 ...
-
Ah okay I got ya, looked like a match but looks can be deceiving ;)
@Smartey
The Butler plugin just deleted UNactivated users. Not inactive.
-
@Teseo
Thanks for the code, works very well for me.
:D
-
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.
-
Maybe Cartagena68 could add this cleanup to his Renew Ads plugin.
-
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.
-
@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:
$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
-
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
-
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.
-
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.
-
When you mark an ad as spam, the total count decreases already, so no difference later when you delete it.
Regards
-
hm .....
-
yeap.
This is the code from some spam plugin, marks as spam but doesn't update the count i guess.
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
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() ;
}
-
That's why vanilla methods should be used if they exist, they are supposed to take care of everything:
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