Maintenance Mode or Offline Mode
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
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
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.
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
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.
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
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.
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