Page 1 of 2

Auto lock for old posts

Posted: Mon Dec 21, 2009 2:11 pm
by adiz
I would like to lock old post automatically.

Any post that didn't have a reply for the last 30 days, will be locked automatically.

Any mod or code for this one?

Re: Auto lock for old posts

Posted: Mon Dec 21, 2009 3:55 pm
by Skinny Vinny
Always backup your database before installing mods on a production board, and test first on a copy whenever possible!

That said...
In cron.php (at or around line 63), find

Code: Select all

// another cron process altered the table between script start and UPDATE query so exit
if ($db->sql_affectedrows() != 1)
{
	exit;
}
Add below (before switch ($cron_type)):

Code: Select all

$lock=time()-86400*30;
$sql="update ".TOPICS_TABLE." set topic_status='".ITEM_LOCKED."' where topic_last_post_time<".$lock;
$db->sql_query($sql);
This exact position isnt important, but keeps calls from running in parallel with the rest of the cron tasks. It's a simple update, so that's really not a big deal here.

May take up to an hour to run when loaded to a live board. For an immediate run, you could throw it onto almost any phpbb33 page script (index, veiwtopic, etc), but remove it afterwards (otherwise it will run on every request for that page).

You could edit the '30' in the $lock line to however many days you want.
Also, if you wanted an auto lock on only selected forums (or skip selected forums), that would be a pretty simple addition to this.

Nothing fancy here, but hope it helps.

Re: Auto lock for old posts

Posted: Tue Dec 22, 2009 12:07 pm
by adiz
Thank you very much!

If I would like to run it for test after 5 minutes, do I need to change the code to this -

Code: Select all

$lock=time()-300*1;
$sql="update ".TOPICS_TABLE." set topic_status='".ITEM_LOCKED."' where topic_last_post_time<".$lock;
$db->sql_query($sql);

Re: Auto lock for old posts

Posted: Tue Dec 22, 2009 6:34 pm
by Skinny Vinny
Yes, that will lock anything older than 300 seconds (*1 not needed there but won't hurt it). If running it from the cron.php file though, note that the cron file only pulls through if last run was over an hour ago.

Re: Auto lock for old posts

Posted: Mon May 10, 2010 11:04 pm
by pro_hunter
will this work on 3.0.7 ???

or is there a mod i could use.

tried Post Expire viewtopic.php?t=1976495

but i got errors so put my my original php files

Re: Auto lock for old posts

Posted: Thu Apr 21, 2011 11:13 am
by Rattus Norvegicus
adiz wrote:Thank you very much!

If I would like to run it for test after 5 minutes, do I need to change the code to this -

Code: Select all

$lock=time()-300*1;
$sql="update ".TOPICS_TABLE." set topic_status='".ITEM_LOCKED."' where topic_last_post_time<".$lock;
$db->sql_query($sql);
I have used this cron job for a few months now, and it works perfectly.

But can anyone tell me if it's possible to specify wich forums this cron job will affect instead of all of them... and how this is done?

Re: Auto lock for old posts

Posted: Sun Nov 04, 2012 8:21 pm
by angelorosso
I have the same problem: it's possible to apply this function in some sections of forum?

Re: Auto lock for old posts

Posted: Sun Nov 04, 2012 10:27 pm
by HGN
You have to know the forum_id's of the forums you want to apply the function to.

The code should be changed to

Code: Select all

$lock=time()-86400*30;
$sql="update ".TOPICS_TABLE." set topic_status='".ITEM_LOCKED."' where topic_last_post_time<".$lock." AND forum_id IN (id1, id2, id3)";
$db->sql_query($sql);
Replace id1, id2, id3 with the applicable forum id's .

Re: Auto lock for old posts

Posted: Mon Nov 05, 2012 8:33 pm
by angelorosso
Ok, thanks!!!! :D

Re: Auto lock for old posts

Posted: Wed Nov 07, 2012 5:37 pm
by angelorosso
Hi guys, I've another question....

it's possible to move topic in other section????

for example, it's possible this for move topic after 7 day of their closer?

Code: Select all

$move=time()-86400*37;
$sql="update ".TOPICS_TABLE." set forum_id='".id1."' where topic_last_post_time<".$move." AND forum_id IN (id1, id2, id3)";
$db->sql_query($sql);
]

and in this code

Code: Select all

$lock=time()-86400*30;
$sql="update ".TOPICS_TABLE." set topic_status='".ITEM_LOCKED."' where topic_last_post_time<".$lock." AND forum_id IN (id1, id2, id3)";
$db->sql_query($sql);
it's possible change this

Code: Select all

$sql="update ".TOPICS_TABLE." set topic_status='".ITEM_LOCKED."'
in this?

Code: Select all

$sql="update ".TOPICS_TABLE." set topic_status='".1."'
because i've noted that in "topic_status" there is 1 for close topic, and 0 for open topic

Re: Auto lock for old posts

Posted: Fri Nov 09, 2012 1:07 pm
by angelorosso
up :D

Re: Auto lock for old posts

Posted: Sun Nov 11, 2012 8:51 am
by angelorosso
*** this is my error, MOD can delete this message, thanks

Re: Auto lock for old posts

Posted: Sun Nov 11, 2012 11:04 am
by HGN
Did you try?

I modified your suggested code a little bit

Code: Select all

$move=time()-86400*37;
$sql="update ".TOPICS_TABLE." set forum_id= 'new_id' where topic_last_post_time<".$move." AND forum_id IN (id1, id2, id3)";
$db->sql_query($sql);
Replace new_id with the actual forum_id you want to have the topic go to.
Make a database backup and try...


[quote=""angelorosso"]

Code: Select all

$lock=time()-86400*30;
$sql="update ".TOPICS_TABLE." set topic_status='".ITEM_LOCKED."' where topic_last_post_time<".$lock." AND forum_id IN (id1, id2, id3)";
$db->sql_query($sql);
it's possible change this

Code: Select all

$sql="update ".TOPICS_TABLE." set topic_status='".ITEM_LOCKED."'
in this?

Code: Select all

$sql="update ".TOPICS_TABLE." set topic_status='".1."'
because i've noted that in "topic_status" there is 1 for close topic, and 0 for open topic[/quote]
Why would you want to do that?
It should be possible to use the following, but I don't see a valid reason.

Code: Select all

$sql="update ".TOPICS_TABLE." set topic_status = '1' 

Re: Auto lock for old posts

Posted: Sun Nov 11, 2012 1:37 pm
by angelorosso
Thanks! ;)

Re: Auto lock for old posts

Posted: Mon Nov 12, 2012 1:17 am
by imkingdavid
Just so you know, I created a MOD that adds a topic age notification and optionally automatically locks topics that are deemed "old" (aka age is greater than the specified threshold). This doesn't lock the topics unless a user attempts to reply to it, and only if you have it set to lock old topics in the ACP. https://www.phpbb.com/customise/db/mod/ ... e_warning/
This also does not provide for moving the topic after a given amount of time (e.g. moving to a trash or archive forum), but that is a good idea for a future version.