First Add-on help with TABLE_PREFIX

dbembibre

Active member
Im developing a simple add-on to close threads in certain forums based in the last post date.
The add-on work perfect, if i remove the table_prefix but i don't know how to have access to the table_prefix constant like in vBulletin.
Last thing is how can log a error to inform that the cron task was executed well or bad ??
I comment the code with my questions, thanks a lot for your help.

PHP:
class CloseThreadCron_CronEntry
{
    /*Clase para cerrar temas automaticamente basado en la ultima fecha de publicacion*/
   
    public static function runCloseThreads()
    {
        $options = XenForo_Application::get('options');
       
        $CloseInForums = $options->mtcCloseInForums;
        $CloseTime    = $options->mtcFromTime; //days passed from last post
        if (!empty($CloseInForums) && $CloseTime>0)
        {
            $forumsToClose = ' nodeid NOT IN ('.$CloseInForums.')';
           
              $SQL ="UPDATE ' . TABLE_PREFIX . 'thread SET open=0 WHERE open = 1 AND sticky = 0"
                . $forumsToClose
                . ' AND last_post_date <= ' . intval(time() - (60 * 60 * 24 * $CloseTime));
             
              //var_dump($SQL);
              //Query output
              //UPDATE ' . TABLE_PREFIX . 'thread SET open=0 WHERE open = 1 AND sticky = 0 nodeid NOT IN (7,101,31,30) AND lastpost_date <= 1367691823"
             
              $db = XenForo_Application::get('db');
              $db->query($SQL);
             
              //how log a error log to say "Close cron threads executed correctly" ??
             
              //need to close the connection ??
              //$db->Close();
   
        }
    }
 
there's no dynamic table prefix in xenforo

all original xenforo tables start ATM always with xf_ => use xf_thread in your query
 
Last edited:
Back
Top Bottom