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

Trouble with a own Cron

DSF

Well-known member
#1
I get this error for a xf-Cron

Fatal error: Using $this when not in object context in .......

What is wrong her?
I can't find the error :(

PHP:
<?php
 
class XenForo_CronEntry_TestDeleteThreads
{
    public static function runTestDeleteThreads()
    {
        $deleteDate = strtotime('-24 hours');
 
        $threads = $this -> _getDb() -> fetchAll ("
            SELECT * FROM xf_thread
            WHERE user_id = 28
            AND node_id = 8
            AND reply_count = 0
            AND last_post_date < ?", $deleteDate);
 
        foreach ($threads AS $thread)
        {
            $this->getModelFromCache('XenForo_Model_Thread')->deleteThread($thread['thread_id'], 'hard');
            XenForo_Helper_Cookie::clearIdFromCookie($thread['thread_id'], 'inlinemod_threads');
        }
    }
}
 

Onimua

Well-known member
#2
Try this instead.
PHP:
<?php
 
class XenForo_CronEntry_TestDeleteThreads
{
    public static function runTestDeleteThreads()
    {
        $deleteDate = strtotime('-24 hours');
 
        $threads = XenForo_Application::getDb()->fetchAll ("
            SELECT * FROM xf_thread
            WHERE user_id = 28
            AND node_id = 8
            AND reply_count = 0
            AND last_post_date < ?", $deleteDate);
 
        foreach ($threads AS $thread)
        {
            XenForo_Model::create('XenForo_Model_Thread')->deleteThread($thread['thread_id'], 'hard');
            XenForo_Helper_Cookie::clearIdFromCookie($thread['thread_id'], 'inlinemod_threads');
        }
    }
}