diff options
author | Tim Almdal <tnalmdal@shaw.ca> | 2009-03-05 00:32:33 +0000 |
---|---|---|
committer | Tim Almdal <tnalmdal@shaw.ca> | 2009-03-05 00:32:33 +0000 |
commit | 7786bb09d32570d9be33727a3fe4fb460fcceeaf (patch) | |
tree | 69cbb683c9a3fc290474536c933a8179d33b51b4 /core | |
parent | 514e6658f6efc6409cfcf2fa85f0566d80217bad (diff) |
Implement a Maintenance mode as per ticket: #15
Diffstat (limited to 'core')
-rw-r--r-- | core/config/config.php | 7 | ||||
-rw-r--r-- | core/controllers/maintenance.php | 30 | ||||
-rw-r--r-- | core/helpers/core.php | 30 | ||||
-rw-r--r-- | core/hooks/init_gallery.php | 1 | ||||
-rw-r--r-- | core/libraries/Theme_View.php | 8 |
5 files changed, 76 insertions, 0 deletions
diff --git a/core/config/config.php b/core/config/config.php index 3bdb70c1..d120b24b 100644 --- a/core/config/config.php +++ b/core/config/config.php @@ -126,3 +126,10 @@ 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 be have normally if an adminstrator logs on. + */ +//$config["maintenance_mode"] = true; diff --git a/core/controllers/maintenance.php b/core/controllers/maintenance.php new file mode 100644 index 00000000..908e90b5 --- /dev/null +++ b/core/controllers/maintenance.php @@ -0,0 +1,30 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2008 Bharat Mediratta + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ +class Maintenance_Controller extends Controller { + function index() { + $album = ORM::factory("item", 1); + $v = new Theme_View("maintenance.html", "reset"); + $v->title = t("%title Unavailable", array("title" => $album->title)); + $v->content = t("%title is currently unavailable as it is undergoing maintenance", + array("title" => $album->title)); + + print $v; + } +}
\ No newline at end of file diff --git a/core/helpers/core.php b/core/helpers/core.php new file mode 100644 index 00000000..5e5a12a7 --- /dev/null +++ b/core/helpers/core.php @@ -0,0 +1,30 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2008 Bharat Mediratta + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ +class core_Core { + static function maintenance_mode() { + $maintenance_mode = Kohana::config("core.maintenance_mode", false, false); + + if (Router::$controller != "login" && !empty($maintenance_mode) && !user::active()->admin) { + Router::$controller = "maintenance"; + Router::$controller_path = APPPATH . "controllers/maintenance.php"; + Router::$method = "index"; + } + } +}
\ No newline at end of file diff --git a/core/hooks/init_gallery.php b/core/hooks/init_gallery.php index 014c29ea..13c61256 100644 --- a/core/hooks/init_gallery.php +++ b/core/hooks/init_gallery.php @@ -22,6 +22,7 @@ Event::add("system.post_routing", array("theme", "load_themes")); Event::add("system.ready", array("module", "load_modules")); Event::add("system.post_routing", array("url", "parse_url")); Event::add("system.shutdown", array("module", "shutdown")); +Event::add("system.post_routing", array("core", "maintenance_mode")); // Override the cookie if we have a session id in the URL. // @todo This should probably be an event callback diff --git a/core/libraries/Theme_View.php b/core/libraries/Theme_View.php index 1f8ca559..ea2a17f9 100644 --- a/core/libraries/Theme_View.php +++ b/core/libraries/Theme_View.php @@ -39,6 +39,14 @@ class Theme_View_Core extends View { $this->set_global('theme', $this); $this->set_global('user', user::active()); $this->set_global("page_type", $page_type); + + $maintenance_mode = Kohana::config("core.maintenance_mode", false, false); + if (!empty($maintenance_mode)) { + $album = ORM::factory("item", 1); + message::warning(t("%title is currently unavailable as it is undergoing maintenance", + array("title" => $album->title))); + } + } public function url($path, $absolute_url=false) { |