PDA

View Full Version : vBCron and Pruning


Indy
01-13-2004, 08:47 PM
From what I was reading at vB, vB3 almost had this.

I would like to have vBCron prune threads older than xx days in selectable forums/catagories. Not worried about resetting counts, etc. since I do this manually every once in a while when I turn off the forums for maintenance.

I have a couple of FSOT type forums and we try to keep them pruned, but don't always do it!

Thanks!
Dan

allan grossman
01-29-2004, 12:12 PM
I'm interested in this also - as I'm running a Usenet gateway and don't really need to keep more than six months' worth of posts.

I'd also like to see this incorporated with a cron job to flush and rebuild the search index. Anybody got ideas?

MRaburn
02-25-2004, 06:52 AM
I think this is much needed but have never really found anyone in the VB arena to take the time to make something for the bigger boards. I've been waiting for years.

Andreas
02-25-2004, 08:43 AM
@Indyshooter
Try this:


ALTER TABLE forum ADD pruneafter INT DEFAULT 0 NOT NULL
In admincp/forum.php FIND

print_yes_no_row($vbphrase['warn_administrators'], 'options[warnall]', $forum['warnall']);


BELOW that ADD

print_input_row("Prune After<dfn>Stetting this to a value > 0 will automatically prune all threads from this forum where the last reply is older then the set amount of days</dfn>", 'forum[pruneafter]', $forum['pruneafter']);

Place the following as prune.php in includes/cron

<?php
error_reporting(E_ALL & ~E_NOTICE);

if ($DB_site == NULL)
{
exit;
}

require_once('./includes/functions_databuild.php');
$forums = $DB_site->query("SELECT forumid, pruneafter FROM " . TABLE_PREFIX . "forum WHERE pruneafter > 0");
while ($forum = $DB_site->fetch_array($forums)) {
$threads = $DB_site->query("SELECT threadid FROM " . TABLE_PREFIX . "thread WHERE forumid=$forum[forumid] AND lastpost <= " . (TIMENOW - ($forum['pruneafter'] * 86400)));
while ($thread = $DB_site->fetch_array($threads)) {
delete_thread($thread['threadid'], 0);
}
build_forum_counters($forum['forumid']);
}

log_cron_action('Forums pruned', $nextitem);

?>

Go to Forum Manager, Edit the Forums you want to be pruned automatically and set the number of days
Create a Cron Job for prune.php


Use AS-IS, no warranties.

EricR
02-29-2004, 06:44 PM
Many thanks Kirby, this is just what I was looking for :) I just have a few questions.

1) If I add a new forum later do I have to rerun the query?

2) Will this ignore sticky topics? If I have something as a sticky I'd like it to be exempt from any/all pruning functions including this auto-prune.


I have this installed and I've setup a few "tests" to confirm that it is working. I ran the task manually and it appears to work, I'll know more tomorrow after the scheduled task runs :)

Andreas
03-01-2004, 12:03 AM
If I add a new forum later do I have to rerun the query?
No. You will just have to set the amount of days in forum manager.

ill this ignore sticky topics? If I have something as a sticky I'd like it to be exempt from any/all pruning functions including this auto-prune.
No, it will also delete sticky threads. But this can be modified easily:

Replace

$threads = $DB_site->query("SELECT threadid FROM " . TABLE_PREFIX . "thread WHERE forumid=$forum[forumid] AND lastpost <= " . (TIMENOW - ($forum['pruneafter'] * 86400)));


With

$threads = $DB_site->query("SELECT threadid FROM " . TABLE_PREFIX . "thread WHERE forumid=$forum[forumid] AND sticky != 1 AND lastpost <= " . (TIMENOW - ($forum['pruneafter'] * 86400)));


Then it should ingore sticky threads.

EricR
03-01-2004, 12:42 AM
Thank you! :)

EricR
03-03-2004, 11:16 PM
Just wanted to say thanks again Kirby, the script passed all of my tests :) All of the expired posts (open and closed) were automatically deleted and the sticky posts were unharmed https://vborg.vbsupport.ru/external/2011/01/19.gif Excellent!

Limitter
03-04-2004, 06:17 AM
Modyfication by Pogo

http://www.vbulletin-germany.com/forum/showthread.php?s=&threadid=9253

Limitter

Catch-22|BL
03-27-2004, 03:26 PM
KirbyDE, I would encourage you to release your post as a hack. People will appreciate this information because it is useful for many large boards. I have to spend at least five hours a month sitting at my computer to manually do the prunes and it is very annoying.

allan grossman
03-27-2004, 06:54 PM
Thank you, Kirby - that's exactly what I needed.

edit: I also think if they incorporate this into vB 3.1 they should slip Kirby a couple hundred bucks for his trouble :)

allan grossman
03-27-2004, 07:34 PM
Modyfication by Pogo

http://www.vbulletin-germany.com/forum/showthread.php?s=&threadid=9253

Ich spreche kein Deutch :)

What does the mod do?

Indy
03-28-2004, 04:42 AM
KirbyDE - Many Thanks!!

Haven't had a chance to apply your hack yet since I've been in the process of moving to a new server and all of the associated stuff that goes along with it.

I plan on doing so though!

Thanks again!
Indy

RCK
07-09-2004, 08:53 PM
Yeah thanks for your help KirbyDE :)

JoeWho
10-11-2005, 07:20 PM
Hi,

Will this work on 3.5.0.r3

I would like to use this if it would work?

JoeWho

EricR
11-06-2005, 02:46 AM
Hi,

Will this work on 3.5.0.r3

I would like to use this if it would work?

JoeWho

This does not work with 3.5+, but thankfully Andreas released a plugin which makes it oh-so-simple. For those of use who already had this on 3.0, here's the steps to complete your upgrade to 3.5+.
Grab the 3.5 plugin from Andreas's post here (https://vborg.vbsupport.ru/showthread.php?s=&threadid=99881) and install it. Overwrite can be left at the default "no".
If you made any custom changes to the prune.php file you'll need to make the same changes to the plugin. To do so, open the Plugin Manager and edit the plugin "Auto-Prune Threads". This is the new location for the code that was previously in prune.php. For example, to preserve Stickies (make them immune to auto-prune), change the following:
Find this (appears only once)
sticky IN (0,1)
and change it to this
sticky != 1
Delete your /includes/prune.php file, it is no longer needed.
Delete your "Prune" task (which used to call the prune.php file) from the Scheduled Task Manager, it is no longer needed.

For 3.5, auto-prune is part of the hourly cleanup #1 in case you ever want to run it manually.

Many many thanks to Andreas for writing this AND helping me thru the upgrade steps :)