PDA

View Full Version : Automatically Lock Old Threads (Via vB Cron)


Gavin B.
05-29-2005, 10:00 PM
This vB cron allows you to define a certain period of time for threads to be automatically locked.


Copy-paste the following into a new PHP file, and upload to ./includes/cron/YOURFILENAME.php
Enter the adminCP and go to scheduled tasks, click "add new scheduled task"
Setup when you want the script to run, and add the filename into the 'filename' field.



<?php

error_reporting(E_ALL & ~E_NOTICE);

// start editing
// forum ID's to monitor - put a comma between each one

DEFINE('FORUM_IDS', '15,59,14');

// time span to go back to.
// eg for months use; 6 MONTH or 9 MONTH
// years; 1 YEAR or 2 YEAR
// days; 5 DAY or 29 DAY

DEFINE('TIME_SPAN', '6 MONTH');

// stop editing here

if (!is_object($DB_site))
{
exit;
}

$DB_site->query("UPDATE " . TABLE_PREFIX . "thread SET open=0 WHERE forumid IN(". FORUM_IDS .") AND FROM_UNIXTIME(dateline) < DATE_SUB(CURDATE(),INTERVAL ". TIME_SPAN .")");

log_cron_action('Old Threads Locked', $nextitem);

?>

Corriewf
05-31-2005, 12:39 AM
I love the concept however this needs to be revised for last post activity as a lot of members use the same thread as an update thread which can go on for a long time.

TrentTech
05-31-2005, 02:00 AM
Is the time based on when the thread is created, or when the last reply was?

Delphy
06-01-2005, 11:00 AM
I wrote something similar for my board a while back.

What I would do is change the query to:

$DB_site->query("UPDATE " . TABLE_PREFIX . "thread SET open=0 WHERE forumid IN(". FORUM_IDS .") AND open <> 0 AND FROM_UNIXTIME(lastpost) < DATE_SUB(CURDATE(),INTERVAL ". TIME_SPAN .")");


This way you are:
1) Only locking threads that aren't already locked (saves re-locking already locked threads)
2) Basing it on the lastpost in the thread, so you don't lock active threads that are created within your timespan

What I also do is hard delete any that are locked and within another timeframe using the same cron job.

Regards,
Delphy

Corriewf
06-01-2005, 01:58 PM
Thanks for that...... So when are the sims coming out to psp?

Logikos
06-02-2005, 05:56 PM
Something like this has already been released. https://vborg.vbsupport.ru/showthread.php?s=&threadid=70302 and it goes by the last post date.