XF 1.1 Remove Inactive Threads, Automatically?:

CritiKiL

Active member
I have looked around to no avail. I have seen many forums who maintain a constant 13 posts maximum and I would like to know how to have inactive threads to remove themselves automatically-set, after a certain time period without observation...Thanks in advance ;-)
 
you could use something like

PHP:
                $threadModel =XenForo_Model::create('XenForo_Model_Thread');
 
 
        $threads = $threadModel->getThreadsInForum(2, array(
            'last_post_date' => array('>', XenForo_Application::$time - 86400 * 2),
            'deleted' => false,
            'moderated' => false));
 
 
 
        foreach ($threads AS $threadId => $thread) {
            if ($thread['first_post_id'] == $thread['last_post_id']){
                $dw = XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread');
                $dw->setExistingData($thread);
                $dw->delete();
            }
        }

this snippet gets all threads from forumId 2, checks if there was a reply, if not, it deletes it


You'll just need an new cronjob with this code:)
 
you could use something like

PHP:
                $threadModel =XenForo_Model::create('XenForo_Model_Thread');
 
 
        $threads = $threadModel->getThreadsInForum(2, array(
            'last_post_date' => array('>', XenForo_Application::$time - 86400 * 2),
            'deleted' => false,
            'moderated' => false));
 
 
 
        foreach ($threads AS $threadId => $thread) {
            if ($thread['first_post_id'] == $thread['last_post_id']){
                $dw = XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread');
                $dw->setExistingData($thread);
                $dw->delete();
            }
        }

this snippet gets all threads from forumId 2, checks if there was a reply, if not, it deletes it


You'll just need an new cronjob with this code:)
Sorry I'm just now getting back over to this. So how would I set all of this up? What file do I add this snippet into and I wouldn't know how to set up a cron job for this either ;-(
 
1. Create the script: CritiKiLDeleteThreads.php
2. Insert this Code:
PHP:
<?php
 
class XenForo_CronEntry_CritiKiLDeleteThreads
{
    public static function runDeleteMyThreads()
    {
 
                $threadModel =XenForo_Model::create('XenForo_Model_Thread');
 
 
        $threads = $threadModel->getThreadsInForum(2, array(
            'last_post_date' => array('>', XenForo_Application::$time - 86400 * 2),
            'deleted' => false,
            'moderated' => false));
 
 
 
        foreach ($threads AS $threadId => $thread) {
            if ($thread['first_post_id'] == $thread['last_post_id']){
                $dw = XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread');
                $dw->setExistingData($thread);
                $dw->delete();
            }
        }
    }
}

3. Put the file into: /library/XenForo/CronEntry
4. Define in ACP a new Cronjob with Cron Callback Class: XenForo_CronEntry_CritiKiLDeleteThreads and Method: runDeleteMyThreads
5. Enjoy ;)
 
Top Bottom