SMF Support > SMF 1.1.x Support

Cron Setup

(1/1)

Liam_michael:
On my forum, I would like an automatic setup where all stickies posted greater than 1 month (2629740 seconds) in board 4 to be unstickied.

I know how to set up cron jobs, but I don't know how to create a file such as what this one does. Will pay if the coding gets hectic.

A long time ago I had someone create me a php file that would automatically lock topics that were 6 months old, here it is for comparison.

Very much appreciate the help.

Oldiesmann:
I haven't tested this, but I believe this will work:


--- Code: ---<?php
include_once('/path/to/SSI.php');

$query = db_query("SELECT t.ID_TOPIC, m.ID_MSG FROM {$db_prefix}topics AS t LEFT JOIN {$db_prefix}messages AS m ON (m.ID_MSG = t.ID_FIRST_MSG) WHERE t.ID_BOARD = 4 AND t.isSticky = 1 AND m.posterTime <= UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 MONTH))", __FILE__, __LINE__);

if (mysql_num_rows($query) != 0)
{
    while($results = mysql_fetch_assoc($query))
    {
        db_query("UPDATE {$db_prefix}topics SET isSticky = 0 WHERE ID_TOPIC = " . $results['ID_TOPIC'], __FILE__, __LINE__);
    }
}
?>
--- End code ---

Just make sure you change the "/path/to/SSI.php" part to the appropriate value based on your setup.

Liam_michael:
Thank you, Oldiesmann.

Before I put this to the test, I'd like to add one more thing to the mix. The topic starter of the sticky cannot be a global moderator, moderator, or administrator. So, this affects everybody except these three groups.

On the same note, what if I want an interval of two weeks instead of a month?

Liam_michael:
Bump!! :)

Navigation

[0] Message Index

Go to full version