Auto lock for old posts

Looking for a MOD? Have a MOD request? Post here for help. (Note: This forum is community supported; phpBB does not have official MOD authors)
Ideas Centre
adiz
Registered User
Posts: 59
Joined: Wed Aug 05, 2009 1:22 pm

Auto lock for old posts

Post 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?
Skinny Vinny
Registered User
Posts: 230
Joined: Tue Dec 01, 2009 7:10 pm

Re: Auto lock for old posts

Post 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.
adiz
Registered User
Posts: 59
Joined: Wed Aug 05, 2009 1:22 pm

Re: Auto lock for old posts

Post 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);
Skinny Vinny
Registered User
Posts: 230
Joined: Tue Dec 01, 2009 7:10 pm

Re: Auto lock for old posts

Post 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.
pro_hunter
Registered User
Posts: 138
Joined: Mon Nov 19, 2007 7:49 pm

Re: Auto lock for old posts

Post 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
Rattus Norvegicus
Registered User
Posts: 5
Joined: Wed Apr 20, 2011 9:06 pm

Re: Auto lock for old posts

Post 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?
angelorosso
Registered User
Posts: 9
Joined: Sun Apr 22, 2012 4:32 pm

Re: Auto lock for old posts

Post by angelorosso »

I have the same problem: it's possible to apply this function in some sections of forum?
User avatar
HGN
Former Team Member
Posts: 4706
Joined: Wed Dec 03, 2008 1:53 pm
Location: The Netherlands
Name: Alfred
Contact:

Re: Auto lock for old posts

Post 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 .
angelorosso
Registered User
Posts: 9
Joined: Sun Apr 22, 2012 4:32 pm

Re: Auto lock for old posts

Post by angelorosso »

Ok, thanks!!!! :D
angelorosso
Registered User
Posts: 9
Joined: Sun Apr 22, 2012 4:32 pm

Re: Auto lock for old posts

Post 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
angelorosso
Registered User
Posts: 9
Joined: Sun Apr 22, 2012 4:32 pm

Re: Auto lock for old posts

Post by angelorosso »

up :D
angelorosso
Registered User
Posts: 9
Joined: Sun Apr 22, 2012 4:32 pm

Re: Auto lock for old posts

Post by angelorosso »

*** this is my error, MOD can delete this message, thanks
User avatar
HGN
Former Team Member
Posts: 4706
Joined: Wed Dec 03, 2008 1:53 pm
Location: The Netherlands
Name: Alfred
Contact:

Re: Auto lock for old posts

Post 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' 
angelorosso
Registered User
Posts: 9
Joined: Sun Apr 22, 2012 4:32 pm

Re: Auto lock for old posts

Post by angelorosso »

Thanks! ;)
User avatar
imkingdavid
Former Team Member
Posts: 2672
Joined: Sun Jul 26, 2009 7:59 pm
Location: EST
Name: David King

Re: Auto lock for old posts

Post 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.
Don't forget to smile today. :)
Please do NOT contact for support via PM or email.
Locked

Return to “[3.0.x] MOD Requests”