PDA

View Full Version : auto task: clear MySQL table


SuperDude
08-03-2011, 12:01 AM
how can i make corn that clean 2 tables in the datebase? im talking about the chat messages, i want it be cleared evrey nigh on 00:00..
they called:
iwt_chatroom_messages
iwt_chat_convos

thanks.

kh99
08-03-2011, 12:13 PM
Probably the easiest thing to do is piggy back on the existing "Daily Cleanup" task by creating a plugin using hook cron_script_cleanup_daily and code like this:

$vbulletin->db->query_write("TRUNCATE TABLE iwt_chatroom_messages");
$vbulletin->db->query_write("TRUNCATE TABLE iwt_chat_convos");


I'm assuming those are the actual names of the tables and that you don't need to add TABLE_PREFIX to the beginning like you would with the vb tables.

The daily cleanup task is set by default to run at 00:10. If you really want it to happen at exactly 00:00 you could change that by editing the scheduled task and changing the "10" to "0" (although it's triggered by activity on your site, so if there's no activity at that time it won't happen until someone visits).

You could also just make a separate task for this by copying one of the existing php files in includes/cron to a different name, replace that task's code with the above code, then create a new scheduled task.

SuperDude
08-04-2011, 07:55 AM
thank you!!! its working great :)