diff options
author | Bharat Mediratta <bharat@menalto.com> | 2009-05-26 05:28:59 +0000 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2009-05-26 05:28:59 +0000 |
commit | 7aed9239088b582a065da3fb63796ff66cd357c8 (patch) | |
tree | 8be9bc4faec21b20cbcc060ad5e9ca128465d09e | |
parent | 2966289b147ceae2fed79b9534840607bf38e0d8 (diff) |
Restructure the module lifecycle.
Install: <module>_installer::install() is called, any necessary tables
are created.
Activate: <module>_installer::activate() is called. Module
controllers are routable, helpers are accessible, etc. The module is
in use.
Deactivate: <module>_installer::deactivate() is called. Module code
is not accessible or routable. Module is *not* in use, but its tables
are still around.
Uninstall: <module>_installer::uninstall() is called. Module is
completely removed from the database.
Admin > Modules will install and activate modules, but will only
deactivate (will NOT uninstall modules).
37 files changed, 309 insertions, 196 deletions
diff --git a/core/controllers/admin_modules.php b/core/controllers/admin_modules.php index 17d75bcb..f7dd909d 100644 --- a/core/controllers/admin_modules.php +++ b/core/controllers/admin_modules.php @@ -28,33 +28,36 @@ class Admin_Modules_Controller extends Admin_Controller { public function save() { access::verify_csrf(); - $changes->install = array(); - $changes->uninstall = array(); + $changes->activate = array(); + $changes->deactivate = array(); + $activated_names = array(); + $deactivated_names = array(); foreach (module::available() as $module_name => $info) { if ($info->locked) { continue; } $desired = $this->input->post($module_name) == 1; - if ($info->installed && !$desired && module::is_installed($module_name)) { - $changes->uninstall[] = $module_name; - $uninstalled_names[] = $info->name; - module::uninstall($module_name); - } else if (!$info->installed && $desired && !module::is_installed($module_name)) { - $changes->install[] = $module_name; - $installed_names[] = $info->name; + if ($info->active && !$desired && module::is_active($module_name)) { + $changes->deactivate[] = $module_name; + $deactivated_names[] = $info->name; + module::deactivate($module_name); + } else if (!$info->active && $desired && !module::is_active($module_name)) { + $changes->activate[] = $module_name; + $activated_names[] = $info->name; module::install($module_name); + module::activate($module_name); } } module::event("module_change", $changes); // @todo this type of collation is questionable from a i18n perspective - if (isset($installed_names)) { - message::success(t("Installed: %names", array("names" => join(", ", $installed_names)))); + if ($activated_names) { + message::success(t("Activated: %names", array("names" => join(", ", $activated_names)))); } - if (isset($uninstalled_names)) { - message::success(t("Uninstalled: %names", array("names" => join(", ", $uninstalled_names)))); + if ($deactivated_names) { + message::success(t("Deactivated: %names", array("names" => join(", ", $deactivated_names)))); } url::redirect("admin/modules"); } diff --git a/core/controllers/scaffold.php b/core/controllers/scaffold.php index 9f306caf..463a092c 100644 --- a/core/controllers/scaffold.php +++ b/core/controllers/scaffold.php @@ -78,7 +78,7 @@ class Scaffold_Controller extends Template_Controller { function add_albums_and_photos($count, $desired_type=null) { srand(time()); $parents = ORM::factory("item")->where("type", "album")->find_all()->as_array(); - $owner_id = module::is_installed("user") ? user::active()->id : null; + $owner_id = user::active()->id; $test_images = glob(APPPATH . "tests/images/*.[Jj][Pp][Gg]"); @@ -162,7 +162,7 @@ class Scaffold_Controller extends Template_Controller { url::redirect("scaffold"); } - if (module::is_installed("akismet")) { + if (module::is_active("akismet")) { akismet::$test_mode = 1; } for ($i = 0; $i < $count; $i++) { @@ -291,20 +291,27 @@ class Scaffold_Controller extends Template_Controller { dir::unlink(VARPATH . "modules"); dir::unlink(VARPATH . "tmp"); - module::$module_names = array(); - module::$modules = array(); $db->clear_cache(); + module::$modules = array(); + module::$active = array(); // Use a known random seed so that subsequent packaging runs will reuse the same random // numbers, keeping our install.sql file more stable. srand(0); + try { core_installer::install(true); module::load_modules(); foreach (array("user", "comment", "organize", "info", "rss", "search", "slideshow", "tag") as $module_name) { module::install($module_name); + module::activate($module_name); + } + } catch (Exception $e) { + Kohana::log("error", $e->getTraceAsString()); + print $e->getTrace(); + throw $e; } url::redirect("scaffold/dump_database"); diff --git a/core/helpers/access.php b/core/helpers/access.php index b9472aa0..64ce91fa 100644 --- a/core/helpers/access.php +++ b/core/helpers/access.php @@ -389,7 +389,9 @@ class access_Core { * @return ORM_Iterator */ private static function _get_all_groups() { - if (module::is_installed("user")) { + // When we build the core package, it's possible that the user module is not installed yet. + // This is ok at packaging time, so work around it. + if (module::is_active("user")) { return ORM::factory("group")->find_all(); } else { return array(); diff --git a/core/helpers/block_manager.php b/core/helpers/block_manager.php index 9e8ab877..022626e5 100644 --- a/core/helpers/block_manager.php +++ b/core/helpers/block_manager.php @@ -41,7 +41,7 @@ class block_manager_Core { static function get_available() { $blocks = array(); - foreach (module::installed() as $module) { + foreach (module::active() as $module) { $class_name = "{$module->name}_block"; if (method_exists($class_name, "get_list")) { foreach (call_user_func(array($class_name, "get_list")) as $id => $title) { diff --git a/core/helpers/core.php b/core/helpers/core.php index 5023bb15..63f51f86 100644 --- a/core/helpers/core.php +++ b/core/helpers/core.php @@ -18,6 +18,10 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class core_Core { + /** + * If Gallery is in maintenance mode, then force all non-admins to get routed to a "This site is + * down for maintenance" page. + */ static function maintenance_mode() { $maintenance_mode = Kohana::config("core.maintenance_mode", false, false); @@ -27,4 +31,22 @@ class core_Core { Router::$method = "index"; } } + + /** + * This function is called when the Gallery is fully initialized. We relay it to modules as the + * "gallery_ready" event. Any module that wants to perform an action at the start of every + * request should implement the <module>_event::gallery_ready() handler. + */ + static function ready() { + module::event("gallery_ready"); + } + + /** + * This function is called right before the Kohana framework shuts down. We relay it to modules + * as the "gallery_shutdown" event. Any module that wants to perform an action at the start of + * every request should implement the <module>_event::gallery_shutdown() handler. + */ + static function shutdown() { + module::event("gallery_shutdown"); + } }
\ No newline at end of file diff --git a/core/helpers/core_installer.php b/core/helpers/core_installer.php index fc4dc1a6..81246359 100644 --- a/core/helpers/core_installer.php +++ b/core/helpers/core_installer.php @@ -41,44 +41,45 @@ class core_installer { $db->query("CREATE TABLE {graphics_rules} ( `id` int(9) NOT NULL auto_increment, - `priority` int(9) NOT NULL, + `active` BOOLEAN default 0, + `args` varchar(255) default NULL, `module_name` varchar(64) NOT NULL, - `target` varchar(32) NOT NULL, `operation` varchar(64) NOT NULL, - `args` varchar(255) default NULL, + `priority` int(9) NOT NULL, + `target` varchar(32) NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;"); $db->query("CREATE TABLE {items} ( + `id` int(9) NOT NULL auto_increment, `album_cover_item_id` int(9) default NULL, `captured` int(9) default NULL, `created` int(9) default NULL, `description` varchar(2048) default NULL, `height` int(9) default NULL, - `id` int(9) NOT NULL auto_increment, `left` int(9) NOT NULL, `level` int(9) NOT NULL, `mime_type` varchar(64) default NULL, `name` varchar(255) default NULL, `owner_id` int(9) default NULL, `parent_id` int(9) NOT NULL, + `rand_key` float default NULL, + `relative_path_cache` varchar(255) default NULL, + `resize_dirty` boolean default 1, `resize_height` int(9) default NULL, `resize_width` int(9) default NULL, - `resize_dirty` boolean default 1, `right` int(9) NOT NULL, + `sort_column` varchar(64) default NULL, + `sort_order` char(4) default 'ASC', + `thumb_dirty` boolean default 1, `thumb_height` int(9) default NULL, `thumb_width` int(9) default NULL, - `thumb_dirty` boolean default 1, `title` varchar(255) default NULL, `type` varchar(32) NOT NULL, `updated` int(9) default NULL, `view_count` int(9) default 0, - `width` int(9) default NULL, - `rand_key` float default NULL, - `relative_path_cache` varchar(255) default NULL, - `sort_column` varchar(64) default NULL, - `sort_order` char(4) default 'ASC', `weight` int(9) NOT NULL default 0, + `width` int(9) default NULL, PRIMARY KEY (`id`), KEY `parent_id` (`parent_id`), KEY `type` (`type`), @@ -101,14 +102,15 @@ class core_installer { $db->query("CREATE TABLE {messages} ( `id` int(9) NOT NULL auto_increment, `key` varchar(255) default NULL, - `value` varchar(255) default NULL, `severity` varchar(32) default NULL, + `value` varchar(255) default NULL, PRIMARY KEY (`id`), UNIQUE KEY(`key`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;"); $db->query("CREATE TABLE {modules} ( `id` int(9) NOT NULL auto_increment, + `active` BOOLEAN default 0, `name` varchar(64) default NULL, `version` int(9) default NULL, PRIMARY KEY (`id`), @@ -125,8 +127,8 @@ class core_installer { $db->query("CREATE TABLE {permissions} ( `id` int(9) NOT NULL auto_increment, - `name` varchar(64) default NULL, `display_name` varchar(64) default NULL, + `name` varchar(64) default NULL, PRIMARY KEY (`id`), UNIQUE KEY(`name`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;"); @@ -136,8 +138,8 @@ class core_installer { `key` char(32) NOT NULL, `locale` char(10) NOT NULL, `message` text NOT NULL, - `translation` text, `revision` int(9) DEFAULT NULL, + `translation` text, PRIMARY KEY (`id`), UNIQUE KEY(`key`, `locale`), KEY `locale_key` (`locale`, `key`)) @@ -145,11 +147,11 @@ class core_installer { $db->query("CREATE TABLE {outgoing_translations} ( `id` int(9) NOT NULL auto_increment, + `base_revision` int(9) DEFAULT NULL, `key` char(32) NOT NULL, `locale` char(10) NOT NULL, `message` text NOT NULL, `translation` text, - `base_revision` int(9) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY(`key`, `locale`), KEY `locale_key` (`locale`, `key`)) @@ -157,22 +159,22 @@ class core_installer { $db->query("CREATE TABLE {sessions} ( `session_id` varchar(127) NOT NULL, - `last_activity` int(10) UNSIGNED NOT NULL, `data` text NOT NULL, + `last_activity` int(10) UNSIGNED NOT NULL, PRIMARY KEY (`session_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;"); $db->query("CREATE TABLE {tasks} ( + `id` int(9) NOT NULL auto_increment, `callback` varchar(128) default NULL, `context` text NOT NULL, `done` boolean default 0, - `id` int(9) NOT NULL auto_increment, - `updated` int(9) default NULL, `name` varchar(128) default NULL, + `owner_id` int(9) default NULL, `percent_complete` int(9) default 0, `state` varchar(32) default NULL, `status` varchar(255) default NULL, - `owner_id` int(9) default NULL, + `updated` int(9) default NULL, PRIMARY KEY (`id`), KEY (`owner_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;"); diff --git a/core/helpers/core_menu.php b/core/helpers/core_menu.php index f7db2104..eb208560 100644 --- a/core/helpers/core_menu.php +++ b/core/helpers/core_menu.php @@ -73,7 +73,7 @@ class core_menu_Core { ->id("admin_menu") ->label(t("Admin"))); self::admin($admin_menu, $theme); - foreach (module::installed() as $module) { + foreach (module::active() as $module) { if ($module->name == "core") { continue; } diff --git a/core/helpers/graphics.php b/core/helpers/graphics.php index b82b6ba8..6d51e60d 100644 --- a/core/helpers/graphics.php +++ b/core/helpers/graphics.php @@ -46,6 +46,7 @@ class graphics_Core { $rule->operation = $operation; $rule->priority = $priority; $rule->args = serialize($args); + $rule->active = true; $rule->save(); self::mark_dirty($target == "thumb", $target == "resize"); @@ -72,14 +73,33 @@ class graphics_Core { * @param string $module_name */ static function remove_rules($module_name) { - $db = Database::instance(); - $status = $db->delete("graphics_rules", array("module_name" => $module_name)); + $status = Database::instance()->delete("graphics_rules", array("module_name" => $module_name)); if (count($status)) { self::mark_dirty(true, true); } } /** + * Activate the rules for this module, typically done when the module itself is deactivated. + * Note that this does not mark images as dirty so that if you deactivate and reactivate a + * module it won't cause all of your images to suddenly require a rebuild. + */ + static function activate_rules($module_name) { + Database::instance() + ->update("graphics_rules",array("active" => true), array("module_name" => $module_name)); + } + + /** + * Deactivate the rules for this module, typically done when the module itself is deactivated. + * Note that this does not mark images as dirty so that if you deactivate and reactivate a + * module it won't cause all of your images to suddenly require a rebuild. + */ + static function deactivate_rules($module_name) { + Database::instance() + ->update("graphics_rules",array("active" => false), array("module_name" => $module_name)); + } + + /** * Rebuild the thumb and resize for the given item. * @param Item_Model $item */ @@ -106,6 +126,7 @@ class graphics_Core { return; } + try { foreach ($ops as $target => $output_file) { if ($input_item->is_movie()) { // Convert the movie to a JPG first @@ -118,6 +139,7 @@ class graphics_Core { foreach (ORM::factory("graphics_rule") ->where("target", $target) + ->where("active", true) ->orderby("priority", "asc") ->find_all() as $rule) { $args = array($working_file, $output_file, unserialize($rule->args)); @@ -140,6 +162,12 @@ class graphics_Core { $item->resize_dirty = 0; } $item->save(); + } catch (Kohana_Exception $e) { + // Something went wrong rebuilding the image. Leave it dirty and move on. + // @todo we should handle this better. + Kohana::log("error", "Caught exception rebuilding image: {$item->title}\n" . + $e->getTraceAsString()); + } } /** diff --git a/core/helpers/log.php b/core/helpers/log.php index cd04e0c5..d0581bf3 100644 --- a/core/helpers/log.php +++ b/core/helpers/log.php @@ -80,9 +80,7 @@ class log_Core { $log->url = substr(url::abs_current(true), 0, 255); $log->referer = request::referrer(null); $log->timestamp = time(); - if (module::is_installed("user")) { $log->user_id = user::active()->id; - } $log->save(); } diff --git a/core/helpers/module.php b/core/helpers/module.php index a6fe64b0..539b003c 100644 --- a/core/helpers/module.php +++ b/core/helpers/module.php @@ -24,23 +24,20 @@ * Note: by design, this class does not do any permission checking. */ class module_Core { - public static $module_names = array(); + public static $active = array(); public static $modules = array(); public static $var_cache = null; - static function get_version($module_name) { - return ORM::factory("module")->where("name", $module_name)->find()->version; - } - /** * Set the version of the corresponding Module_Model * @param string $module_name * @param integer $version */ static function set_version($module_name, $version) { - $module = ORM::factory("module")->where("name", $module_name)->find(); + $module = self::get($module_name); if (!$module->loaded) { $module->name = $module_name; + $module->active = $module_name == "core"; // only core is active by default } $module->version = 1; $module->save(); @@ -52,25 +49,8 @@ class module_Core { * @param string $module_name */ static function get($module_name) { - return model_cache::get("module", $module_name, "name"); - } - - /** - * Delete the corresponding Module_Model - * @param string $module_name - */ - static function delete($module_name) { - $module = ORM::factory("module")->where("name", $module_name)->find(); - if ($module->loaded) { - $db = Database::instance(); - $db->delete("graphics_rules", array("module_name" => $module->name)); - $module->delete(); - - // We could delete the module vars here too, but it's nice to leave them around in case the - // module gets reinstalled. - - Kohana::log("debug", "$module_name: module deleted"); - } + // @todo can't easily use model_cache here because it throw an exception on missing models. + return ORM::factory("module", array("name" => $module_name)); } /** @@ -78,27 +58,29 @@ class module_Core { * @param string $module_name */ static function is_installed($module_name) { - return !empty(self::$module_names[$module_name]); + return array_key_exists($module_name, self::$modules); } /** - * Return the list of installed modules. + * Check to see if a module is active + * @param string $module_name */ - static function installed() { - return self::$modules; + static function is_active($module_name) { + return array_key_exists($module_name, self::$modules) && + self::$modules[$module_name]->active; } /** - * Return the list of available modules. + * Return the list of available modules, including uninstalled modules. */ static function available() { $modules = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS); foreach (array_merge(array("core/module.info"), glob(MODPATH . "*/module.info")) as $file) { $module_name = basename(dirname($file)); $modules->$module_name = new ArrayObject(parse_ini_file($file), ArrayObject::ARRAY_AS_PROPS); - $modules->$module_name->installed = - empty(self::$modules[$module_name]) ? - null : self::$modules[$module_name]->version; + $modules->$module_name->installed = self::is_installed($module_name); + $modules->$module_name->active = self::is_active($module_name); + $modules->$module_name->version = self::get_version($module_name); $modules->$module_name->locked = false; } @@ -111,35 +93,108 @@ class module_Core { } /** - * Install a module. + * Return a list of all the active modules in no particular order. */ - static function install($module_name) { - $installer_class = "{$module_name}_installer"; - Kohana::log("debug", "$installer_class install (initial)"); - if ($module_name != "core") { - require_once(DOCROOT . "modules/${module_name}/helpers/{$installer_class}.php"); + static function active() { + return self::$active; } + + /** + * Install a module. This will call <module>_installer::install(), which is responsible for + * creating database tables, setting module variables and and calling module::set_version(). + * Note that after installing, the module must be activated before it is available for use. + * @param string $module_name + */ + static function install($module_name) { $kohana_modules = Kohana::config("core.modules"); $kohana_modules[] = MODPATH . $module_name; Kohana::config_set("core.modules", $kohana_modules); + $installer_class = "{$module_name}_installer"; if (method_exists($installer_class, "install")) { call_user_func_array(array($installer_class, "install"), array()); } - self::load_modules(); + // Now the module is installed but inactive, so don't leave it in the active path + array_pop($kohana_modules); + Kohana::config_set("core.modules", $kohana_modules); + log::success( "module", t("Installed module %module_name", array("module_name" => $module_name))); } /** - * Uninstall a module. + * Activate an installed module. This will call <module>_installer::activate() which should take + * any steps to make sure that the module is ready for use. This will also activate any + * existing graphics rules for this module. + * @param string $module_name + */ + static function activate($module_name) { + $kohana_modules = Kohana::config("core.modules"); + $kohana_modules[] = MODPATH . $module_name; + Kohana::config_set("core.modules", $kohana_modules); + + $installer_class = "{$module_name}_installer"; + if (method_exists($installer_class, "activate")) { + call_user_func_array(array($installer_class, "activate"), array()); + } + + $module = self::get($module_name); + if ($module->loaded) { + $module->active = true; + $module->save(); + } + + self::load_modules(); + graphics::activate_rules($module_name); + log::success( + "module", t("Activated module %module_name", array("module_name" => $module_name))); + } + + /** + * Deactivate an installed module. This will call <module>_installer::deactivate() which + * should take any cleanup steps to make sure that the module isn't visible in any way. + * @param string $module_name + */ + static function deactivate($module_name) { + $installer_class = "{$module_name}_installer"; + if (method_exists($installer_class, "deactivate")) { + call_user_func_array(array($installer_class, "deactivate"), array()); + } + $module = self::get($module_name); + if ($module->loaded) { + $module->active = false; + $module->save(); + } + + self::load_modules(); + graphics::deactivate_rules($module_name); + log::success( + "module", t("Deactivated module %module_name", array("module_name" => $module_name))); + } + + /** + * Uninstall a deactivated module. This will call <module>_installer::uninstall() which should + * take whatever steps necessary to make sure that all traces of a module are gone. + * @param string $module_name */ static function uninstall($module_name) { $installer_class = "{$module_name}_installer"; - Kohana::log("debug", "$installer_class uninstall"); + if (method_exists($installer_class, "uninstall")) { call_user_func(array($installer_class, "uninstall")); + } + + graphics::remove_rule($module_name); + $module = self::get($module_name); + if ($module->loaded) { + $module->delete(); + } + + // We could delete the module vars here too, but it's nice to leave them around + // in case the module gets reinstalled. + + self::load_modules(); log::success( "module", t("Uninstalled module %module_name", array("module_name" => $module_name))); } @@ -153,19 +208,18 @@ class module_Core { $kohana_modules = $core["modules"]; $modules = ORM::factory("module")->find_all(); + self::$modules = array(); + self::$active = array(); foreach ($modules as $module) { - self::$module_names[$module->name] = $module->name; self::$modules[$module->name] = $module; - - // @todo For some reason if we don't load the core module here, the test framework fails. - // This requires some investigation. + if ($module->active) { + self::$active[] = $module; + } if ($module->name != "core") { $kohana_modules[] = MODPATH . $module->name; } } Kohana::config_set("core.modules", $kohana_modules); - - self::event("gallery_ready"); } /** @@ -178,7 +232,11 @@ class module_Core { array_shift($args); $function = str_replace(".", "_", $name); - foreach (self::installed() as $module) { + foreach (self::$modules as $module) { + if (!$module->active) { + continue; + } + $class = "{$module->name}_event"; if (method_exists($class, $function)) { call_user_func_array(array($class, $function), $args); @@ -187,17 +245,6 @@ class module_Core { } /** - * Kohana shutdown event handler - * @param string $module_name - * @param string $name - * @param string $default_value - * @return the value - */ - static function shutdown() { - self::event("gallery_shutdown"); - } - - /** * Get a variable from this module * @param string $module_name * @param string $name @@ -256,7 +303,6 @@ class module_Core { ->where("name", $name) ->find(); if (!$var->loaded) { - $var = ORM::factory("var"); $var->module_name = $module_name; $var->name = $name; } @@ -300,4 +346,12 @@ class module_Core { Database::instance()->delete("vars", array("module_name" => "core", "name" => "_cache")); self::$var_cache = null; } + + /** + * Return the version of the installed module. + * @param string $module_name + */ + static function get_version($module_name) { + return self::get($module_name)->version; + } } diff --git a/core/helpers/task.php b/core/helpers/task.php index 1bc2996a..a8a004ab 100644 --- a/core/helpers/task.php +++ b/core/helpers/task.php @@ -23,8 +23,8 @@ class task_Core { */ static function get_definitions() { $tasks = array(); - foreach (module::installed() as $module_name => $module_info) { - $class_name = "{$module_name}_task"; + foreach (module::active() as $module) { + $class_name = "{$module->name}_task"; if (method_exists($class_name, "available_tasks")) { foreach (call_user_func(array($class_name, "available_tasks")) as $task) { $tasks[$task->callback] = $task; diff --git a/core/hooks/init_gallery.php b/core/hooks/init_gallery.php index ce32fcfc..2c36795a 100644 --- a/core/hooks/init_gallery.php +++ b/core/hooks/init_gallery.php @@ -18,16 +18,19 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ +// If var/database.php doesn't exist, then we assume that the Gallery is not properly installed +// and send users to the installer. if (!file_exists(VARPATH . "database.php")) { url::redirect(url::abs_file("installer")); } Event::add("system.ready", array("I18n", "instance")); -Event::add("system.post_routing", array("theme", "load_themes")); Event::add("system.ready", array("module", "load_modules")); +Event::add("system.ready", array("core", "ready")); +Event::add("system.post_routing", array("theme", "load_themes")); 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")); +Event::add("system.shutdown", array("core", "shutdown")); // 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/Admin_View.php b/core/libraries/Admin_View.php index 94f9fead..acc3f8ec 100644 --- a/core/libraries/Admin_View.php +++ b/core/libraries/Admin_View.php @@ -59,7 +59,7 @@ class Admin_View_Core extends View { $menu = Menu::factory("root"); core_menu::admin($menu, $this); - foreach (module::installed() as $module) { + foreach (module::active() as $module) { if ($module->name == "core") { continue; } @@ -99,7 +99,7 @@ class Admin_View_Core extends View { case "admin_page_top": case "admin_head": $blocks = array(); - foreach (module::installed() as $module) { + foreach (module::active() as $module) { $helper_class = "{$module->name}_theme"; if (method_exists($helper_class, $function)) { $blocks[] = call_user_func_array( diff --git a/core/libraries/Theme_View.php b/core/libraries/Theme_View.php index dafb66f6..b5b97666 100644 --- a/core/libraries/Theme_View.php +++ b/core/libraries/Theme_View.php @@ -93,7 +93,7 @@ class Theme_View_Core extends View { if ($this->page_type != "login") { core_menu::site($menu, $this); - foreach (module::installed() as $module) { + foreach (module::active() as $module) { if ($module->name == "core") { continue; } @@ -111,7 +111,7 @@ class Theme_View_Core extends View { $menu = Menu::factory("root"); core_menu::album($menu, $this); - foreach (module::installed() as $module) { + foreach (module::active() as $module) { if ($module->name == "core") { continue; } @@ -128,7 +128,7 @@ class Theme_View_Core extends View { $menu = Menu::factory("root"); core_menu::photo($menu, $this); - foreach (module::installed() as $module) { + foreach (module::active() as $module) { if ($module->name == "core") { continue; } @@ -196,7 +196,7 @@ class Theme_View_Core extends View { case "thumb_info": case "thumb_top": $blocks = array(); - foreach (module::installed() as $module) { + foreach (module::active() as $module) { $helper_class = "{$module->name}_theme"; if (method_exists($helper_class, $function)) { $blocks[] = call_user_func_array( diff --git a/core/views/admin_modules.html.php b/core/views/admin_modules.html.php index fa303320..3fddd6cd 100644 --- a/core/views/admin_modules.html.php +++ b/core/views/admin_modules.html.php @@ -19,7 +19,7 @@ <tr class="<?= ($i % 2 == 0) ? "gEvenRow" : "gOddRow" ?>"> <? $data = array("name" => $module_name); ?> <? if ($module_info->locked) $data["disabled"] = 1; ?> - <td> <?= form::checkbox($data, '1', module::is_installed($module_name)) ?> </td> + <td> <?= form::checkbox($data, '1', module::is_active($module_name)) ?> </td> <td> <?= t($module_info->name) ?> </td> <td> <?= $module_info->version ?> </td> <td> <?= t($module_info->description) ?> </td> diff --git a/core/views/kohana_error_page.php b/core/views/kohana_error_page.php index 83ad5abb..d9bf9698 100644 --- a/core/views/kohana_error_page.php +++ b/core/views/kohana_error_page.php @@ -1,4 +1,4 @@ -<? defined("SYSPATH") or die("No direct script access.") ?> +<?php defined("SYSPATH") or die("No direct script access.") ?> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <style type="text/css"> diff --git a/installer/install.sql b/installer/install.sql index cbab91bd..69584cdb 100644 --- a/installer/install.sql +++ b/installer/install.sql @@ -66,15 +66,16 @@ SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; CREATE TABLE {graphics_rules} ( `id` int(9) NOT NULL auto_increment, - `priority` int(9) NOT NULL, + `active` tinyint(1) default '0', + `args` varchar(255) default NULL, `module_name` varchar(64) NOT NULL, - `target` varchar(32) NOT NULL, `operation` varchar(64) NOT NULL, - `args` varchar(255) default NULL, + `priority` int(9) NOT NULL, + `target` varchar(32) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8; SET character_set_client = @saved_cs_client; -INSERT INTO {graphics_rules} VALUES (1,100,'core','thumb','resize','a:3:{s:5:\"width\";i:200;s:6:\"height\";i:200;s:6:\"master\";i:2;}'),(2,100,'core','resize','resize','a:3:{s:5:\"width\";i:640;s:6:\"height\";i:480;s:6:\"master\";i:2;}'); +INSERT INTO {graphics_rules} VALUES (1,1,'a:3:{s:5:\"width\";i:200;s:6:\"height\";i:200;s:6:\"master\";i:2;}','core','resize',100,'thumb'),(2,1,'a:3:{s:5:\"width\";i:640;s:6:\"height\";i:480;s:6:\"master\";i:2;}','core','resize',100,'resize'); DROP TABLE IF EXISTS {groups}; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; @@ -106,8 +107,8 @@ CREATE TABLE {incoming_translations} ( `key` char(32) NOT NULL, `locale` char(10) NOT NULL, `message` text NOT NULL, - `translation` text, `revision` int(9) default NULL, + `translation` text, PRIMARY KEY (`id`), UNIQUE KEY `key` (`key`,`locale`), KEY `locale_key` (`locale`,`key`) @@ -117,35 +118,35 @@ DROP TABLE IF EXISTS {items}; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; CREATE TABLE {items} ( + `id` int(9) NOT NULL auto_increment, `album_cover_item_id` int(9) default NULL, `captured` int(9) default NULL, `created` int(9) default NULL, `description` varchar(2048) default NULL, `height` int(9) default NULL, - `id` int(9) NOT NULL auto_increment, `left` int(9) NOT NULL, `level` int(9) NOT NULL, `mime_type` varchar(64) default NULL, `name` varchar(255) default NULL, `owner_id` int(9) default NULL, `parent_id` int(9) NOT NULL, + `rand_key` float default NULL, + `relative_path_cache` varchar(255) default NULL, + `resize_dirty` tinyint(1) default '1', `resize_height` int(9) default NULL, `resize_width` int(9) default NULL, - `resize_dirty` tinyint(1) default '1', `right` int(9) NOT NULL, + `sort_column` varchar(64) default NULL, + `sort_order` char(4) default 'ASC', + `thumb_dirty` tinyint(1) default '1', `thumb_height` int(9) default NULL, `thumb_width` int(9) default NULL, - `thumb_dirty` tinyint(1) default '1', `title` varchar(255) default NULL, `type` varchar(32) NOT NULL, `updated` int(9) default NULL, `view_count` int(9) default '0', - `width` int(9) default NULL, - `rand_key` float default NULL, - `relative_path_cache` varchar(255) default NULL, - `sort_column` varchar(64) default NULL, - `sort_order` char(4) default 'ASC', `weight` int(9) NOT NULL default '0', + `width` int(9) default NULL, `view_1` smallint(6) NOT NULL default '0', `view_2` smallint(6) NOT NULL default '0', PRIMARY KEY (`id`), @@ -154,7 +155,7 @@ CREATE TABLE {items} ( KEY `random` (`rand_key`) ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; SET character_set_client = @saved_cs_client; -INSERT INTO {items} VALUES (NULL,NULL,UNIX_TIMESTAMP(),'',NULL,1,1,1,NULL,NULL,NULL,0,NULL,NULL,1,2,NULL,NULL,1,'Gallery','album',1242792233,0,NULL,NULL,'','weight','ASC',1,1,1); +INSERT INTO {items} VALUES (1,NULL,NULL,UNIX_TIMESTAMP(),'',NULL,1,1,NULL,NULL,NULL,0,NULL,'',1,NULL,NULL,2,'weight','ASC',1,NULL,NULL,'Gallery','album',1243295552,0,1,NULL,1,1); DROP TABLE IF EXISTS {items_tags}; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; @@ -189,8 +190,8 @@ SET character_set_client = utf8; CREATE TABLE {messages} ( `id` int(9) NOT NULL auto_increment, `key` varchar(255) default NULL, - `value` varchar(255) default NULL, `severity` varchar(32) default NULL, + `value` varchar(255) default NULL, PRIMARY KEY (`id`), UNIQUE KEY `key` (`key`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; @@ -200,23 +201,24 @@ SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; CREATE TABLE {modules} ( `id` int(9) NOT NULL auto_increment, + `active` tinyint(1) default '0', `name` varchar(64) default NULL, `version` int(9) default NULL, PRIMARY KEY (`id`), UNIQUE KEY `name` (`name`) ) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8; SET character_set_client = @saved_cs_client; -INSERT INTO {modules} VALUES (1,'core',1),(2,'user',1),(3,'comment',1),(4,'organize',1),(5,'info',1),(6,'rss',1),(7,'search',1),(8,'slideshow',1),(9,'tag',1); +INSERT INTO {modules} VALUES (1,1,'core',1),(2,1,'user',1),(3,1,'comment',1),(4,1,'organize',1),(5,1,'info',1),(6,1,'rss',1),(7,1,'search',1),(8,1,'slideshow',1),(9,1,'tag',1); DROP TABLE IF EXISTS {outgoing_translations}; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; CREATE TABLE {outgoing_translations} ( `id` int(9) NOT NULL auto_increment, + `base_revision` int(9) default NULL, `key` char(32) NOT NULL, `locale` char(10) NOT NULL, `message` text NOT NULL, `translation` text, - `base_revision` int(9) default NULL, PRIMARY KEY (`id`), UNIQUE KEY `key` (`key`,`locale`), KEY `locale_key` (`locale`,`key`) @@ -227,13 +229,13 @@ SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; CREATE TABLE {permissions} ( `id` int(9) NOT NULL auto_increment, - `name` varchar(64) default NULL, `display_name` varchar(64) default NULL, + `name` varchar(64) default NULL, PRIMARY KEY (`id`), UNIQUE KEY `name` (`name`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8; SET character_set_client = @saved_cs_client; -INSERT INTO {permissions} VALUES (1,'view','View'),(2,'view_full','View Full Size'),(3,'edit','Edit'),(4,'add','Add'); +INSERT INTO {permissions} VALUES (1,'View','view'),(2,'View Full Size','view_full'),(3,'Edit','edit'),(4,'Add','add'); DROP TABLE IF EXISTS {search_records}; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; @@ -247,14 +249,14 @@ CREATE TABLE {search_records} ( FULLTEXT KEY `data` (`data`) ) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; SET character_set_client = @saved_cs_client; -INSERT INTO {search_records} VALUES (1,1,0,' Gallery '); +INSERT INTO {search_records} VALUES (1,1,0,''); DROP TABLE IF EXISTS {sessions}; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; CREATE TABLE {sessions} ( `session_id` varchar(127) NOT NULL, - `last_activity` int(10) unsigned NOT NULL, `data` text NOT NULL, + `last_activity` int(10) unsigned NOT NULL, PRIMARY KEY (`session_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; SET character_set_client = @saved_cs_client; @@ -273,16 +275,16 @@ DROP TABLE IF EXISTS {tasks}; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; CREATE TABLE {tasks} ( + `id` int(9) NOT NULL auto_increment, `callback` varchar(128) default NULL, `context` text NOT NULL, `done` tinyint(1) default '0', - `id` int(9) NOT NULL auto_increment, - `updated` int(9) default NULL, `name` varchar(128) default NULL, + `owner_id` int(9) default NULL, `percent_complete` int(9) default '0', `state` varchar(32) default NULL, `status` varchar(255) default NULL, - `owner_id` int(9) default NULL, + `updated` int(9) default NULL, PRIMARY KEY (`id`), KEY `owner_id` (`owner_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; @@ -333,4 +335,4 @@ CREATE TABLE {vars} ( UNIQUE KEY `module_name` (`module_name`,`name`) ) ENGINE=InnoDB AUTO_INCREMENT=22 DEFAULT CHARSET=utf8; SET character_set_client = @saved_cs_client; -INSERT INTO {vars} VALUES (1,'core','active_site_theme','default'),(2,'core','active_admin_theme','admin_default'),(3,'core','page_size','9'),(4,'core','thumb_size','200'),(5,'core','resize_size','640'),(6,'core','default_locale','en_US'),(7,'core','image_quality','75'),(9,'core','blocks_dashboard_sidebar','a:4:{i:689770875;a:2:{i:0;s:4:\"core\";i:1;s:11:\"block_adder\";}i:833924182;a:2:{i:0;s:4:\"core\";i:1;s:5:\"stats\";}i:1854926446;a:2:{i:0;s:4:\"core\";i:1;s:13:\"platform_info\";}i:879824473;a:2:{i:0;s:4:\"core\";i:1;s:12:\"project_news\";}}'),(14,'core','blocks_dashboard_center','a:4:{i:1735074092;a:2:{i:0;s:4:\"core\";i:1;s:7:\"welcome\";}i:1952263764;a:2:{i:0;s:4:\"core\";i:1;s:12:\"photo_stream\";}i:352594192;a:2:{i:0;s:4:\"core\";i:1;s:11:\"log_entries\";}i:943490963;a:2:{i:0;s:7:\"comment\";i:1;s:15:\"recent_comments\";}}'),(17,'core','version','3.0 pre-beta svn'),(18,'core','choose_default_tookit','1'),(20,'comment','spam_caught','0'); +INSERT INTO {vars} VALUES (1,'core','active_site_theme','default'),(2,'core','active_admin_theme','admin_default'),(3,'core','page_size','9'),(4,'core','thumb_size','200'),(5,'core','resize_size','640'),(6,'core','default_locale','en_US'),(7,'core','image_quality','75'),(9,'core','blocks_dashboard_sidebar','a:4:{i:280595051;a:2:{i:0;s:4:\"core\";i:1;s:11:\"block_adder\";}i:652858034;a:2:{i:0;s:4:\"core\";i:1;s:5:\"stats\";}i:940891777;a:2:{i:0;s:4:\"core\";i:1;s:13:\"platform_info\";}i:478383514;a:2:{i:0;s:4:\"core\";i:1;s:12:\"project_news\";}}'),(14,'core','blocks_dashboard_center','a:4:{i:1592623773;a:2:{i:0;s:4:\"core\";i:1;s:7:\"welcome\";}i:869840165;a:2:{i:0;s:4:\"core\";i:1;s:12:\"photo_stream\";}i:1904124669;a:2:{i:0;s:4:\"core\";i:1;s:11:\"log_entries\";}i:1825935772;a:2:{i:0;s:7:\"comment\";i:1;s:15:\"recent_comments\";}}'),(17,'core','version','3.0 pre-beta svn'),(18,'core','choose_default_tookit','1'),(20,'comment','spam_caught','0'); diff --git a/modules/akismet/helpers/akismet_installer.php b/modules/akismet/helpers/akismet_installer.php index 3bb8aff1..920c58b7 100644 --- a/modules/akismet/helpers/akismet_installer.php +++ b/modules/akismet/helpers/akismet_installer.php @@ -23,12 +23,13 @@ class akismet_installer { if ($version == 0) { module::set_version("akismet", 1); } + } + static function activate() { akismet::check_config(); } - static function uninstall() { + static function deactivate() { site_status::clear("akismet_config"); - module::delete("akismet"); } } diff --git a/modules/comment/helpers/comment_installer.php b/modules/comment/helpers/comment_installer.php index 695aa298..b1cfcdc0 100644 --- a/modules/comment/helpers/comment_installer.php +++ b/modules/comment/helpers/comment_installer.php @@ -61,6 +61,5 @@ class comment_installer { module::event("item_related_update_batch", $sql); $db->query("DROP TABLE IF EXISTS {comments};"); - module::delete("comment"); } } diff --git a/modules/exif/helpers/exif_installer.php b/modules/exif/helpers/exif_installer.php index 5f37996a..77cf3f3d 100644 --- a/modules/exif/helpers/exif_installer.php +++ b/modules/exif/helpers/exif_installer.php @@ -33,14 +33,18 @@ class exif_installer { KEY(`item_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;"); module::set_version("exif", 1); + } + } + + static function activate() { exif::check_index(); } + + static function deactivate() { + site_status::clear("exif_index_out_of_date"); } static function uninstall() { - $db = Database::instance(); - $db->query("DROP TABLE IF EXISTS {exif_records};"); - site_status::clear("exif_index_out_of_date"); - module::delete("exif"); + Database::instance()->query("DROP TABLE IF EXISTS {exif_records};"); } } diff --git a/modules/g2_import/helpers/g2_import.php b/modules/g2_import/helpers/g2_import.php index d035e004..37efcad0 100644 --- a/modules/g2_import/helpers/g2_import.php +++ b/modules/g2_import/helpers/g2_import.php @@ -111,13 +111,13 @@ class g2_import_Core { $stats["photos"] = g2(GalleryCoreApi::fetchItemIdCount("GalleryPhotoItem")); $stats["movies"] = g2(GalleryCoreApi::fetchItemIdCount("GalleryMovieItem")); - if (g2_import::g2_module_active("comment") && module::is_installed("comment")) { + if (g2_import::g2_module_active("comment") && module::is_active("comment")) { list (, $stats["comments"]) = g2(GalleryCommentHelper::fetchAllComments($root_album_id, 1)); } else { $stats["comments"] = 0; } - if (g2_import::g2_module_active("tags") && module::is_installed("tag")) { + if (g2_import::g2_module_active("tags") && module::is_active("tag")) { $result = g2($gallery->search("SELECT COUNT(DISTINCT([TagItemMap::itemId])) FROM [TagItemMap]")) ->nextResult(); @@ -441,7 +441,7 @@ class g2_import_Core { } static function import_keywords_as_tags($keywords, $item) { - if (!module::is_installed("tag")) { + if (!module::is_active("tag")) { return; } @@ -466,7 +466,8 @@ class g2_import_Core { // Precaution: if the Gallery2 item was watermarked, or we have the Gallery3 watermark module // active then we'd have to do something a lot more sophisticated here. For now, just skip // this step in those cases. - if (module::is_installed("watermark") && module::get_var("watermark", "name")) { + // @todo we should probably use an API here, eventually. + if (module::is_active("watermark") && module::get_var("watermark", "name")) { return; } diff --git a/modules/g2_import/helpers/g2_import_installer.php b/modules/g2_import/helpers/g2_import_installer.php index 1e60a83d..2bfb7f8c 100644 --- a/modules/g2_import/helpers/g2_import_installer.php +++ b/modules/g2_import/helpers/g2_import_installer.php @@ -33,8 +33,4 @@ class g2_import_installer { module::set_version("g2_import", 1); } } - - static function uninstall() { - module::delete("g2_import"); - } } diff --git a/modules/gallery_unit_test/controllers/gallery_unit_test.php b/modules/gallery_unit_test/controllers/gallery_unit_test.php index 1195dc3d..5206f9fb 100644 --- a/modules/gallery_unit_test/controllers/gallery_unit_test.php +++ b/modules/gallery_unit_test/controllers/gallery_unit_test.php @@ -90,8 +90,8 @@ class Gallery_Unit_Test_Controller extends Controller { @mkdir('test/var/logs', 0777, true); // Reset our caches - module::$module_names = array(); module::$modules = array(); + module::$active = array(); module::$var_cache = array(); $db->clear_cache(); @@ -100,6 +100,7 @@ class Gallery_Unit_Test_Controller extends Controller { core_installer::install(true); module::load_modules(); module::install("user"); + module::activate("user"); $modules = array(); foreach (glob(MODPATH . "*/helpers/*_installer.php") as $file) { $module_name = basename(dirname(dirname($file))); @@ -107,6 +108,7 @@ class Gallery_Unit_Test_Controller extends Controller { continue; } module::install($module_name); + module::activate($module_name); } $filter = count($_SERVER["argv"]) > 2 ? $_SERVER["argv"][2] : null; diff --git a/modules/image_block/helpers/image_block_installer.php b/modules/image_block/helpers/image_block_installer.php index b9ee4d5f..57279d05 100644 --- a/modules/image_block/helpers/image_block_installer.php +++ b/modules/image_block/helpers/image_block_installer.php @@ -23,8 +23,4 @@ class image_block_installer { module::set_version("image_block", 1); } } - - static function uninstall() { - module::delete("image_block"); - } } diff --git a/modules/info/helpers/info_installer.php b/modules/info/helpers/info_installer.php index f291b508..94fc22d0 100644 --- a/modules/info/helpers/info_installer.php +++ b/modules/info/helpers/info_installer.php @@ -24,8 +24,4 @@ class info_installer { module::set_version("info", 1); } } - - static function uninstall() { - module::delete("info"); - } } diff --git a/modules/notification/helpers/notification_installer.php b/modules/notification/helpers/notification_installer.php index 71f33640..ad10184b 100644 --- a/modules/notification/helpers/notification_installer.php +++ b/modules/notification/helpers/notification_installer.php @@ -47,7 +47,5 @@ class notification_installer { $db = Database::instance(); $db->query("DROP TABLE IF EXISTS {subscriptions};"); $db->query("DROP TABLE IF EXISTS {pending_notifications};"); - - module::delete("notification"); } } diff --git a/modules/organize/helpers/organize_installer.php b/modules/organize/helpers/organize_installer.php index f739709c..ea0f4e3d 100644 --- a/modules/organize/helpers/organize_installer.php +++ b/modules/organize/helpers/organize_installer.php @@ -24,8 +24,4 @@ class organize_installer { module::set_version("organize", 1); } } - - static function uninstall() { - module::delete("organize"); - } } diff --git a/modules/recaptcha/helpers/recaptcha_installer.php b/modules/recaptcha/helpers/recaptcha_installer.php index ccc27aae..6269c632 100644 --- a/modules/recaptcha/helpers/recaptcha_installer.php +++ b/modules/recaptcha/helpers/recaptcha_installer.php @@ -20,16 +20,16 @@ class recaptcha_installer { static function install() { $version = module::get_version("recaptcha"); - if ($version == 0) { module::set_version("recaptcha", 1); } + } + static function activate() { recaptcha::check_config(); } static function uninstall() { site_status::clear("recaptcha_config"); - module::delete("recaptcha"); } } diff --git a/modules/rss/helpers/rss_installer.php b/modules/rss/helpers/rss_installer.php index ffd1ca75..2beafb33 100644 --- a/modules/rss/helpers/rss_installer.php +++ b/modules/rss/helpers/rss_installer.php @@ -24,8 +24,4 @@ class rss_installer { module::set_version("rss", 1); } } - - static function uninstall() { - module::delete("rss"); - } } diff --git a/modules/search/helpers/search.php b/modules/search/helpers/search.php index 2c7be123..15efa3b2 100644 --- a/modules/search/helpers/search.php +++ b/modules/search/helpers/search.php @@ -67,8 +67,8 @@ class search_Core { $record->item_id = $item->id; } - foreach (module::installed() as $module_name => $module_info) { - $class_name = "{$module_name}_search"; + foreach (module::active() as $module) { + $class_name = "{$module->name}_search"; if (method_exists($class_name, "item_index_data")) { $data[] = call_user_func(array($class_name, "item_index_data"), $record->item()); } @@ -83,12 +83,16 @@ class search_Core { ->select("items.id") ->from("items") ->join("search_records", "items.id", "search_records.item_id", "left") + ->open_paren() ->where("search_records.item_id", null) ->orwhere("search_records.dirty", 1) + ->close_paren() ->get() ->count(); + $total = ORM::factory("item")->count_all(); $percent = round(100 * ($total - $remaining) / $total); + return array($remaining, $total, $percent); } } diff --git a/modules/search/helpers/search_installer.php b/modules/search/helpers/search_installer.php index a3d0f79e..5fc9b37b 100644 --- a/modules/search/helpers/search_installer.php +++ b/modules/search/helpers/search_installer.php @@ -31,18 +31,23 @@ class search_installer { KEY(`item_id`), FULLTEXT INDEX (`data`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;"); - - // populate the index with dirty records - $db->query("INSERT INTO {search_records} (`item_id`) SELECT `id` FROM {items}"); module::set_version("search", 1); + } + } + + static function activate() { + // Update the root item. This is a quick hack because the search module is activated as part + // of the official install, so this way we don't start off with a "your index is out of date" + // banner. + search::update(model_cache::get("item", 1)); search::check_index(); } + + static function deactivate() { + site_status::clear("search_index_out_of_date"); } static function uninstall() { - $db = Database::instance(); - $db->query("DROP TABLE {search_records}"); - site_status::clear("search_index_out_of_date"); - module::delete("search"); + Database::instance()->query("DROP TABLE {search_records}"); } } diff --git a/modules/server_add/helpers/server_add_installer.php b/modules/server_add/helpers/server_add_installer.php index 7094dfbe..b592b448 100644 --- a/modules/server_add/helpers/server_add_installer.php +++ b/modules/server_add/helpers/server_add_installer.php @@ -28,9 +28,11 @@ class server_add_installer { server_add::check_config(); } + static function deactivate() { + site_status::clear("server_add_configuration"); + } + static function uninstall() { access::delete_permission("server_add"); - module::delete("server_add"); - site_status::clear("server_add_configuration"); } } diff --git a/modules/slideshow/helpers/slideshow_event.php b/modules/slideshow/helpers/slideshow_event.php index 12765922..c6cd7dc7 100644 --- a/modules/slideshow/helpers/slideshow_event.php +++ b/modules/slideshow/helpers/slideshow_event.php @@ -19,10 +19,10 @@ */ class slideshow_event_Core { static function module_change($changes) { - if (!module::is_installed("rss") || in_array("rss", $changes->uninstall)) { + if (!module::is_active("rss") || in_array("rss", $changes->deactivate)) { site_status::warning( t("The Slideshow module requires the RSS module. " . - "<a href=\"%url\">Install the RSS module now</a>", + "<a href=\"%url\">Activate the RSS module now</a>", array("url" => url::site("admin/modules"))), "slideshow_needs_rss"); } else { diff --git a/modules/slideshow/helpers/slideshow_installer.php b/modules/slideshow/helpers/slideshow_installer.php index 959e9f55..b46f5471 100644 --- a/modules/slideshow/helpers/slideshow_installer.php +++ b/modules/slideshow/helpers/slideshow_installer.php @@ -25,8 +25,7 @@ class slideshow_installer { } } - static function uninstall() { - module::delete("slideshow"); + static function deactivate() { site_status::clear("slideshow_needs_rss"); } } diff --git a/modules/tag/helpers/tag_installer.php b/modules/tag/helpers/tag_installer.php index 74fa97a5..07544c54 100644 --- a/modules/tag/helpers/tag_installer.php +++ b/modules/tag/helpers/tag_installer.php @@ -46,6 +46,5 @@ class tag_installer { $db = Database::instance(); $db->query("DROP TABLE IF EXISTS {tags};"); $db->query("DROP TABLE IF EXISTS {items_tags};"); - module::delete("tag"); } } diff --git a/modules/user/helpers/user_installer.php b/modules/user/helpers/user_installer.php index 66ac0048..68868fc1 100644 --- a/modules/user/helpers/user_installer.php +++ b/modules/user/helpers/user_installer.php @@ -99,11 +99,11 @@ class user_installer { try { Session::instance()->destroy(); } catch (Exception $e) { + // We don't care if there was a problem destroying the session. } $db = Database::instance(); $db->query("DROP TABLE IF EXISTS {users};"); $db->query("DROP TABLE IF EXISTS {groups};"); $db->query("DROP TABLE IF EXISTS {groups_users};"); - module::delete("user"); } }
\ No newline at end of file diff --git a/modules/watermark/helpers/watermark_installer.php b/modules/watermark/helpers/watermark_installer.php index 6b54bd33..ed4265ec 100644 --- a/modules/watermark/helpers/watermark_installer.php +++ b/modules/watermark/helpers/watermark_installer.php @@ -40,8 +40,6 @@ class watermark_installer { } static function uninstall() { - graphics::remove_rules("watermark"); - module::delete("watermark"); Database::instance()->query("DROP TABLE {watermarks}"); dir::unlink(VARPATH . "modules/watermark"); } |