Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 06-22-2012, 12:34 PM
John Lester John Lester is offline
 
Join Date: Nov 2004
Posts: 543
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Pruning users with sql

I find the default user pruning options to be pretty lame so I want to run a query or two to delete some spammers rather than going through them one by one.

I did some searching but either nobody has done what I want, or I'm waaaay off base on how to do it

Can you use multiple conditions in a query like that? Would you just use AND or is there a more efficient way? An example of what I want to do (and yes it probably isn't right ) is below. I'm not sure if I can use lastvisit (or what value to use) and I guess it's not critical but sure would be better if I could.

Code:
DELETE FROM 'users' WHERE 'username' LIKE %! AND 'postcount' =0 AND 'lastvisit' =
I want to delete users with ! in their names, have zero posts, and have not visited in X days.

Is it possible to use more than the ! in the query (ie ! and #)?

--------------- Added [DATE]1340372363[/DATE] at [TIME]1340372363[/TIME] ---------------

Would it be possible to use the condition that they have a url in their homepage?
Reply With Quote
  #2  
Old 06-22-2012, 02:09 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by John Lester View Post
I want to delete users with ! in their names, have zero posts, and have not visited in X days.

Is it possible to use more than the ! in the query (ie ! and #)?
Code:
DELETE FROM user WHERE (username LIKE '%!%' OR username LIKE '%#%') AND postcount = 0 AND lastactivity < (UNIX_TIMESTAMP() - (86400 * X))
You'd replace X with the number of days of inactivity. I removed the quotes from table and field names because they'd would need to be 'back ticks' and not single quotes, but they normally aren't needed anyway.


Quote:
Would it be possible to use the condition that they have a url in their homepage?
You could use a regular expression to match a url (if you google you'll find a number of examples), but I suppose if you're not concerned in matching only valid urls, you could just add "AND homepage LIKE '%http://%'.


Also I should mention, I've seen other people suggest deleting users with a query like this, but it doesn't remove everything the way deleting from the adminCP does. I guess you're going for users who don't have any posts (and so wouldn't have any attachments), and probably wouldn't have any PMs, but there will still be rows in the userfield and usertextfield tables. But I guess it works because none of those things would cause problems.
Reply With Quote
  #3  
Old 06-22-2012, 03:22 PM
John Lester John Lester is offline
 
Join Date: Nov 2004
Posts: 543
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thank you Kevin

I didn't think about it leaving anything behind in the userfield and never even thought about the usertextfield Not sure why I used ' when I darn well know it's ` *shrug*, and about them not being needed "usually" I did not know

I don't want to do it half assed and leave crumbs behind. I'll just do it in batches through the acp then

Although I would like to ask, in the example %!% would that include users that have more than one ! ? I would assume so, but that's gotten me into trouble before
Reply With Quote
  #4  
Old 06-22-2012, 08:10 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by John Lester View Post
I don't want to do it half assed and leave crumbs behind. I'll just do it in batches through the acp then
I was wondering if doing a JOIN of those tables would delete the rows from those tables as well. But I don't even know if you can have a join in a delete statement.



Quote:
I didn't think about it leaving anything behind in the userfield and never even thought about the usertextfield Not sure why
I believe so. I'd have to test it to know for sure.

After posting this I was out going about my business and was thinking that I really should have tested that sql before posting it, because a typo could have ended up deleting all your users or something. You should probably do something like test with a SELECT before doing the delete (if you end up doing it that way).

Another thing you could do is write some php to do it (maybe steal the "delete user" code from the admincp), then set it up as a scheduled task (if it hasn't been done already - I didn't do a search of mods).
Reply With Quote
  #5  
Old 06-23-2012, 03:33 AM
John Lester John Lester is offline
 
Join Date: Nov 2004
Posts: 543
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Oh I don't use the code on the live site until it's been used and abused on the test site I have yet to use it though because now you have me wondering about joining those tables
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:54 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03529 seconds
  • Memory Usage 2,205KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_code
  • (4)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (5)post_thanks_box
  • (5)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (5)post_thanks_postbit_info
  • (5)postbit
  • (5)postbit_onlinestatus
  • (5)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete