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

XF 1.1 Turn Off Forums Automatically

Discussion in 'XenForo Questions and Support' started by tafreehm, Nov 17, 2012.

  1. tafreehm

    tafreehm Well-Known Member

    Hello,
    Is there anyway to automatically turn off/close and then turn back on forums a specific time of the day ? maybe through a cron job or something ?

    Please guide.
    Thanks
     
  2. Chris D

    Chris D XenForo Developer Staff Member

    It would require an add-on.

    I looked into it once, but couldn't get it to work. That may have been my inexperience at the time.

    If I get time I'll have another look.

    For now, no it isn't possible right now but could be with an add-on. I recommend posting at the Resource Requests forum.
     
    Jake Bunce and tafreehm like this.
  3. James

    James Well-Known Member

    You should be able to run a cron job to do it.
     
  4. tafreehm

    tafreehm Well-Known Member

    posted: http://xenforo.com/community/threads/auto-turn-on-off-forum.41085/
     
  5. tafreehm

    tafreehm Well-Known Member

    I wish I could do that..
     
  6. James

    James Well-Known Member

    You just create the code to write the option to the database, then set a cron up to run the code at the specified time.

    Hard part is writing to the db :)
     
  7. Chris D

    Chris D XenForo Developer Staff Member

    I get the feeling the hard part is what he'd struggle with :)

    I've actually pretty much written this already. I misunderstood earlier I thought it was individual nodes for some reason rather than the entire board.

    So it's only taken less than 30 minutes :D

    I have asked a question in the resource requests page to find out how long the board needs to be off for, but basically, here's the code. I'm going to add a few admin CP options which don't feature yet. It needs a Board On Cron Entry and a Board Off Cron Entry.

    PHP:
    <?php
      
    class BoardActiveCron_CronEntry_BoardOnOff
    {
        public static function 
    boardOn()
        {                
            
    $db XenForo_Application::getDb();
            
            
    $db->update('xf_option', array('option_value' => 1), 'option_id = "boardActive"');
            
            
    XenForo_Model::create('XenForo_Model_Option')->rebuildOptionCache();
        }
        
        public static function 
    boardOff()
        {
            
    $db XenForo_Application::getDb();
            
            
    $db->update('xf_option', array('option_value' => 0), 'option_id = "boardActive"');
            
            
    XenForo_Model::create('XenForo_Model_Option')->rebuildOptionCache();
        }
    }
     
  8. James

    James Well-Known Member

    Looking good!

    It'd be a lot easier if there was a function. For example, there's XenForo_Application::get('options'), it'd be better if we could update options with something like:
    XenForo_Application::set('options', 'boardActive', 0);
     
    Chris D likes this.
  9. Chris D

    Chris D XenForo Developer Staff Member

    Thanks!

    I agree. Maybe such a thing exists - I didn't really check :p

    Though the only difference I'd expect is for that function (if it existed) to automatically rebuild the option cache.
     
  10. Chris D

    Chris D XenForo Developer Staff Member

    Would you believe it... there is a function :p

    XenForo_Options::set($option, $subOption, $value);

    Still doesn't rebuild the option cache (as far as I can tell) but cuts out one line of code from calling the database. I will test it and report back.
     
    James likes this.
  11. James

    James Well-Known Member

    I knew the set() function had to be useful :p
     
  12. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

Share This Page