Log in

View Full Version : SQL query for deleting automatic forum pruning


malmazan
05-18-2008, 03:29 PM
What would the SQL query be for delete all threads older than 90 days from an array of forums?

I want to write a simple php file I can use with the "Scheduled Task" option on the vB adminCP to auto-prune the forums I use for classifieds.

Thanks

Lynne
05-18-2008, 03:46 PM
Maybe use an existing hack: Auto Prune Threads (https://vborg.vbsupport.ru/showthread.php?t=99881&highlight=prune)
If you don't want to use that one, you can at least download it and see what the query is.

malmazan
05-19-2008, 06:19 AM
Maybe use an existing hack: Auto Prune Threads (https://vborg.vbsupport.ru/showthread.php?t=99881&highlight=prune)
If you don't want to use that one, you can at least download it and see what the query is.

I just did that, but there are several queries and I am not savvy enough to be able to re-use them.

malmazan
03-02-2009, 08:07 AM
The original code is :

while ($forum = $vbulletin->db->fetch_array($forums))
{
$threads = $vbulletin->db->query_read("SELECT threadid, forumid, visible, open, pollid, title FROM " . TABLE_PREFIX . "thread WHERE forumid=$forum[forumid] AND visible IN (0,1,2) AND sticky IN (0,1) AND lastpost <= " . (TIMENOW - ($forum['pruneafter'] * 86400)));
while ($thread = $vbulletin->db->fetch_array($threads))
{
delete_thread($thread['threadid'], false, true, NULL, false, $thread);
}
build_forum_counters($forum['forumid']);
}

I would like to manually specify the forums and the number of days. Would this be correct?

while ($forum = $vbulletin->db->[7,8,9])
{
$threads = $vbulletin->db->query_read("SELECT threadid, forumid, visible, open, pollid, title FROM " . TABLE_PREFIX . "thread WHERE forumid=$forum[forumid] AND visible IN (0,1,2) AND sticky IN (0,1) AND lastpost <= " . (TIMENOW - (90* 86400)));
while ($thread = $vbulletin->db->fetch_array($threads))
{
delete_thread($thread['threadid'], false, true, NULL, false, $thread);
}
build_forum_counters($forum['forumid']);
}

Lynne
03-02-2009, 02:34 PM
No, that is not going to work. You should ask for help in the modification thread. They know the code and are best able to help you.