1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

XF 1.1 Remove Inactive Threads, Automatically?:

Discussion in 'XenForo Questions and Support' started by CritiKiL, May 26, 2012.

  1. CritiKiL

    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 ;-)
     
  2. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    CritiKiL likes this.
  3. ragtek

    ragtek Guest

    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:)
     
    CritiKiL likes this.
  4. CritiKiL

    CritiKiL Active Member

    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 ;-(
     
  5. DSF

    DSF Well-Known Member

    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 ;)
     
    CritiKiL and Jake Bunce like this.

Share This Page