Maintenance Mode or Offline Mode

edited January 2012 in Feature Requests
Any idea how to implement a feature that allows the site to be in an offline mode that can be used for doing administrative tasks and disallow browsing to the website?

Drupal has this kind of feature in the core called "Maintenance Mode". It is quite handy, especially when you need to do database schema updates.

Erik

Comments

  • edited January 2012
    Obviously if you're in a pinch and have access, replace the root level index file.

    Is a config file setting good enough or are you wanting checkbox type thing in fuel admin?

    Best spot is likely fuels page_router controller
  • edited January 2012
    Scratch page_router comment.

    Assuming a config flag would do:

    Backup your fuel_routes file and try this one.

    <?php /* |-------------------------------------------------------------------------- | FUEL ROUTES |-------------------------------------------------------------------------- | | The following are routes used by FUEL specifically | */ $route[substr(FUEL_ROUTE, 0, -1)] = 'fuel/dashboard'; $module_folder = MODULES_PATH.'/'; # Config isn't loaded yet so do it manually include($module_folder.FUEL_FOLDER.'/config/fuel.php'); $maintenance_mode = true; # To prevent the overhead of this on every request, we do a quick check of the path... IN_FUEL_ADMIN is defined in a presystem hook if (IN_FUEL_ADMIN) { include($module_folder.FUEL_FOLDER.'/config/fuel_modules.php'); $modules = array_keys($config['modules']); $modules = array_merge($config['modules_allowed'], $modules); # So we can pass forward param $route[FUEL_ROUTE.'login|'.FUEL_ROUTE.'login/:any'] = 'fuel/login'; foreach($modules as $module) { # Grab any routes in the module specific folder $routes_path = $module_folder.$module.'/config/'.$module.'_routes.php'; if (file_exists($routes_path)) include($routes_path); # Check FUEL folder for controller first... if not there then we use the default module to map to else if ( ! file_exists($module_folder.FUEL_FOLDER.'/controllers/'.$module.EXT) AND ! file_exists($module_folder.$module.'/controllers/'.$module.'_module'.EXT) ) { $route[FUEL_ROUTE.$module] = FUEL_FOLDER.'/module'; $route[FUEL_ROUTE.$module.'/(.*)'] = FUEL_FOLDER.'/module/$1'; } # Check if controller does exist in FUEL folder and if so, create the proper ROUTE if it does not equal the FUEL_FOLDER else if (file_exists($module_folder.FUEL_FOLDER.'/controllers/'.$module.EXT)) { $route[FUEL_ROUTE.$module] = FUEL_FOLDER.'/'.$module; $route[FUEL_ROUTE.$module.'/(.*)'] = FUEL_FOLDER.'/'.$module.'/$1'; } # Check module specific folder next else if (file_exists($module_folder.$module.'/controllers/'.$module.'_module'.EXT)) { $route[FUEL_ROUTE.$module] = $module.'/'.$module.'_module'; $route[FUEL_ROUTE.$module.'/(.*)'] = $module.'/'.$module.'_module/$1'; } } # Catch all $route[FUEL_ROUTE.'(:any)'] = FUEL_FOLDER."/$1"; } else if ($maintenance_mode) { $route['(.*)'] = 'maintenance'; } if ( ! $maintenance_mode) { # Load any public routes for advanced modules foreach ($config['modules_allowed'] as $module) { $routes_path = $module_folder.$module.'/config/'.$module.'_public_routes.php'; if (file_exists($routes_path)) include($routes_path); } } /* End of file fuel_routes.php */ /* Location: ./modules/fuel/config/fuel_routes.php */



    Note the $maintenance_mode var at the top. You could move that to a config file. I've left it there so you see the whole lot.

    If that's true, it sends everything to 'maintenance' which is a file in the views folder. That last section is something I added to load my advanced modules routes files aswell.
  • edited 2:46AM
    This would work! Thank you for putting this up. Would this affect the Fuel Admin as well? I would like it to NOT affect the Fuel admin area, but just the other routes for the rest of the website.

    I would highly recommend that you guys put this into the Fuel Admin area so that it would be very quick to go in and disable the site from being visited with a simple click of a checkbox. For now though, this will help me out as I need to perform a DB schema update that is going to require me to shut down the site temporarily.

    Thanks!
    Erik
  • edited 2:46AM
    I tried replacing this code with the fuel/modules/fuel/config/fuel_routes.php file and it doesn't appear to be working. I'm assuming all URLs other than Fuel will redirect to "maintenance" but that is not happening. Everything appears to be functioning the same.
  • edited 2:46AM
    Hmm works for me.

    I just set it to true on my site:
    http://redgemmedia.co.nz - just a view
    http://redgemmedia.co.nz/portfolio - advanced module
    http://redgemmedia.co.nz/services - cms page
    http://redgemmedia.co.nz/contact - cms page with controller
    http://redgemmedia.co.nz/cms - fuel login (goes to correct page)


    There is one problem that I didn't get a fix for. The Dashboard. It's AJAX calls to the modules don't have 'fuel' in the path EG /backup/dashboard so it doesn't think it's IN_FUEL_ADMIN. I would have preferred to use is_fuelified() but it looked to be too early to get at it.

    This all should really be in a system hook.
  • edited 2:46AM
    Ok, I got it to work. I think it wasn't working because I hadn't created a view file called "maintenance.php". It is working just as I was hoping. Thanks a bunch for this!

    I would like to reiterate my suggestion to build this into your core system and expose the option to turn maintenance mode on or off in the Fuel Admin. This would make this feature golden.

    Thanks,
    Erik
  • edited 2:46AM
    Sorry to bring up this old thread, but I could have sworn that I've seen a maintenance mode feature in the Fuel settings, but it doesn't look like there is one.

    I needed to take a site down and had to create a plain index.php and rename the Fuel index.php in order to take the site down quickly.

    I wonder why this hasn't been incorporated yet? It would be awesome if there was a simple Maintenance Mode feature with a default view file. :)
  • edited 2:46AM
    This may help:
    http://forum.getfuelcms.com/discussion/comment/8969#Comment_8969
    $config['settings']['offline'] = array('type' => 'checkbox', 'value' => 1);

    I just noticed that the homepage wasn't showing offline, so I just pushed a fix for that to the develop branch as well:
    https://github.com/daylightstudio/FUEL-CMS/tree/develop
Sign In or Register to comment.