diff options
author | Bharat Mediratta <bharat@menalto.com> | 2010-08-01 21:00:30 -0700 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2010-08-01 21:00:30 -0700 |
commit | c33b24c9faf5d83e4f1bfc6d3778da6c37139b3f (patch) | |
tree | 0284f35a4d3d58c474e562d5e149ca0d1a212244 | |
parent | 49eb3e32b9b8df20360ee6ceb388f00828063efa (diff) |
Make maintenance mode a variable instead of a config. Then create
links on the Admin > Maintenance page to allow you to turn it on and
off. This should be efficient since we cache all vars and look them
up on every request anyway.
This also allows us to have the Fix task enable maintenance mode while
it's running which greatly reduces the chances that somebody will come
along and hork the database while we're tinkering with MPTT pointers.
Fixes ticket #1259.
-rw-r--r-- | application/config/config.php | 7 | ||||
-rw-r--r-- | modules/gallery/controllers/admin_maintenance.php | 6 | ||||
-rw-r--r-- | modules/gallery/helpers/gallery.php | 6 | ||||
-rw-r--r-- | modules/gallery/helpers/gallery_installer.php | 10 | ||||
-rw-r--r-- | modules/gallery/helpers/gallery_task.php | 9 | ||||
-rw-r--r-- | modules/gallery/libraries/Theme_View.php | 8 | ||||
-rw-r--r-- | modules/gallery/module.info | 2 | ||||
-rw-r--r-- | modules/gallery/views/admin_maintenance.html.php | 26 |
8 files changed, 51 insertions, 23 deletions
diff --git a/application/config/config.php b/application/config/config.php index 9a8f4299..3b92ac73 100644 --- a/application/config/config.php +++ b/application/config/config.php @@ -151,10 +151,3 @@ if (TEST_MODE) { array(MODPATH . "gallery_unit_test", MODPATH . "unit_test")); } - -/** - * Setting the maintenance_mode to block all non administrative access. In - * this mode a user can attempt to logon, but will be unable to access anything. - * The application will behave normally if an adminstrator logs on. - */ -//$config["maintenance_mode"] = true; diff --git a/modules/gallery/controllers/admin_maintenance.php b/modules/gallery/controllers/admin_maintenance.php index 3567b4f0..a9cc933c 100644 --- a/modules/gallery/controllers/admin_maintenance.php +++ b/modules/gallery/controllers/admin_maintenance.php @@ -226,4 +226,10 @@ class Admin_Maintenance_Controller extends Admin_Controller { "done" => (bool) $task->done))); } } + + public function maintenance_mode($value) { + access::verify_csrf(); + module::set_var("gallery", "maintenance_mode", $value); + url::redirect("admin/maintenance"); + } } diff --git a/modules/gallery/helpers/gallery.php b/modules/gallery/helpers/gallery.php index d4078209..33a6830c 100644 --- a/modules/gallery/helpers/gallery.php +++ b/modules/gallery/helpers/gallery.php @@ -25,9 +25,9 @@ class gallery_Core { * down for maintenance" page. */ static function maintenance_mode() { - $maintenance_mode = Kohana::config("core.maintenance_mode", false, false); - - if (Router::$controller != "login" && !empty($maintenance_mode) && !identity::active_user()->admin) { + if (Router::$controller != "login" && + module::get_var("gallery", "maintenance_mode", false) && + !identity::active_user()->admin) { Router::$controller = "maintenance"; Router::$controller_path = MODPATH . "gallery/controllers/maintenance.php"; Router::$method = "index"; diff --git a/modules/gallery/helpers/gallery_installer.php b/modules/gallery/helpers/gallery_installer.php index 39c35711..f5589618 100644 --- a/modules/gallery/helpers/gallery_installer.php +++ b/modules/gallery/helpers/gallery_installer.php @@ -295,7 +295,8 @@ class gallery_installer { module::set_var("gallery", "credits", (string) $powered_by_string); module::set_var("gallery", "simultaneous_upload_limit", 5); module::set_var("gallery", "admin_area_timeout", 90 * 60); - module::set_version("gallery", 30); + module::set_var("gallery", "maintenance_mode", 0); + module::set_version("gallery", 31); } static function upgrade($version) { @@ -554,7 +555,12 @@ class gallery_installer { if ($version == 29) { $db->query("ALTER TABLE {caches} ADD KEY (`key`);"); module::set_version("gallery", $version = 30); - } + } + + if ($version == 30) { + module::set_var("gallery", "maintenance_mode", 0); + module::set_version("gallery", $version = 31); + } } static function uninstall() { diff --git a/modules/gallery/helpers/gallery_task.php b/modules/gallery/helpers/gallery_task.php index da9fba49..f5c25ddc 100644 --- a/modules/gallery/helpers/gallery_task.php +++ b/modules/gallery/helpers/gallery_task.php @@ -56,8 +56,8 @@ class gallery_task_Core { $tasks[] = Task_Definition::factory() ->callback("gallery_task::fix") ->name(t("Fix your Gallery")) - ->description(t("Fix up a variety of little problems that might be causing " . - "your Gallery to act a little weird")) + ->description(t("Fix a variety of problems that might cause your Gallery to act " . + "strangely. Requires maintenance mode.")) ->severity(log::SUCCESS); return $tasks; @@ -343,6 +343,10 @@ class gallery_task_Core { $completed = $task->get("completed"); $state = $task->get("state"); + if (!module::get_var("gallery", "maintenance_mode")) { + module::set_var("gallery", "maintenance_mode", 1); + } + // This is a state machine that checks each item in the database. It verifies the following // attributes for an item. // 1. Left and right MPTT pointers are correct @@ -543,6 +547,7 @@ class gallery_task_Core { $task->done = true; $task->state = "success"; $task->percent_complete = 100; + module::set_var("gallery", "maintenance_mode", 0); } else { $task->percent_complete = round(100 * $completed / $total); } diff --git a/modules/gallery/libraries/Theme_View.php b/modules/gallery/libraries/Theme_View.php index 6246c6f1..7b90c034 100644 --- a/modules/gallery/libraries/Theme_View.php +++ b/modules/gallery/libraries/Theme_View.php @@ -46,9 +46,11 @@ class Theme_View_Core extends Gallery_View { $this->set_global("thumb_proportion", $this->thumb_proportion()); } - $maintenance_mode = Kohana::config("core.maintenance_mode", false, false); - if ($maintenance_mode) { - message::warning(t("This site is currently in maintenance mode")); + if (module::get_var("gallery", "maintenance_mode", false)) { + if (identity::active_user()->admin) { + message::warning(t("This site is currently in maintenance mode. Visit the <a href=\"%maintenance_url\">maintenance page</a>", array("maintenance_url" => url::site("admin/maintenance")))); + } else + message::warning(t("This site is currently in maintenance mode.")); } } diff --git a/modules/gallery/module.info b/modules/gallery/module.info index df2be978..7d28a7c1 100644 --- a/modules/gallery/module.info +++ b/modules/gallery/module.info @@ -1,3 +1,3 @@ name = "Gallery 3" description = "Gallery core application" -version = 30 +version = 31 diff --git a/modules/gallery/views/admin_maintenance.html.php b/modules/gallery/views/admin_maintenance.html.php index ad0e2f55..4bfc57f0 100644 --- a/modules/gallery/views/admin_maintenance.html.php +++ b/modules/gallery/views/admin_maintenance.html.php @@ -1,13 +1,29 @@ <?php defined("SYSPATH") or die("No direct script access.") ?> <div id="g-admin-maintenance" class="g-block"> - <h1> <?= t("Maintenance tasks") ?> </h1> - <p> - <?= t("Occasionally your Gallery will require some maintenance. Here are some tasks you can use to keep it running smoothly.") ?> - </p> + <h1> <?= t("Maintenance") ?> </h1> + <div class="g-block-content"> + <div id="g-maintenance-mode"> + <?= t("When you're performing maintenance on your Gallery, you can enable <b>maintenance mode</b> which prevents any non-admin from accessing your Gallery. Some of the tasks below will automatically put your Gallery in maintenance mode for you.") ?> + <ul id="g-action-status" class="g-message-block"> + <? if (module::get_var("gallery", "maintenance_mode")): ?> + <li class="g-warning"> + <?= t("Maintenance mode is <b>on</b>. Non admins cannot access your Gallery. <a href=\"%enable_maintenance_mode_url\">Turn off maintenance mode</a>", array("enable_maintenance_mode_url" => url::site("admin/maintenance/maintenance_mode/0?csrf=$csrf"))) ?> + </li> + <? else: ?> + <li class="g-info"> + <?= t("Maintenance mode is off. User access is permitted. <a href=\"%enable_maintenance_mode_url\">Turn on maintenance mode</a>", array("enable_maintenance_mode_url" => url::site("admin/maintenance/maintenance_mode/1?csrf=$csrf"))) ?> + </li> + <? endif ?> + </ul> + </div> + </div> <div class="g-block-content"> <div id="g-available-tasks"> - <h2> <?= t("Available tasks") ?> </h2> + <h2> <?= t("Maintenance tasks") ?> </h2> + <p> + <?= t("Occasionally your Gallery will require some maintenance. Here are some tasks you can use to keep it running smoothly.") ?> + </p> <table> <tr> <th> |