From 89a67dba63f8ac61b90e4c4f1ba1b0cdbdf20b26 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Tue, 29 Sep 2009 08:50:53 -0700 Subject: * Remove the @todo in module event and always try to call gallery_event::$function first * Refactor gallery.php to move site_menu, admin_menu, and context_menu to gallery_event.php * Change Theme_View and Admin_view to call module::event("site_menu|admin_menu|context_menu"...) --- modules/gallery/helpers/module.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'modules/gallery/helpers/module.php') diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php index a3088c38..ae8bcc11 100644 --- a/modules/gallery/helpers/module.php +++ b/modules/gallery/helpers/module.php @@ -283,9 +283,28 @@ class module_Core { array_shift($args); $function = str_replace(".", "_", $name); + if (method_exists("gallery_event", $function)) { + switch (count($args)) { + case 0: + gallery_event::$function(); + break; + case 1: + gallery_event::$function($args[0]); + break; + case 2: + gallery_event::$function($args[0], $args[1]); + break; + default: + call_user_func_array(array("gallery_event", $function), $args); + } + } + // @todo: consider calling gallery_event first, since for things menus we need it to do some // setup foreach (self::$active as $module) { + if ($module->name == "gallery") { + continue; + } $class = "{$module->name}_event"; if (method_exists($class, $function)) { call_user_func_array(array($class, $function), $args); -- cgit v1.2.3 From e6f62396111e2cd9aef8e3244851eca3ec65aee4 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Tue, 29 Sep 2009 09:10:41 -0700 Subject: Remove the @todo and optimize the gallery_event call for 3 and 4 arguments... context menu events have 4 arguments. --- modules/gallery/helpers/module.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'modules/gallery/helpers/module.php') diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php index ae8bcc11..8e203566 100644 --- a/modules/gallery/helpers/module.php +++ b/modules/gallery/helpers/module.php @@ -294,13 +294,18 @@ class module_Core { case 2: gallery_event::$function($args[0], $args[1]); break; + case 3: + gallery_event::$function($args[0], $args[1], $args[2]); + break; + case 4: // Context menu events have 4 arguments so lets optimize them + gallery_event::$function($args[0], $args[1], $args[2], $args[3]); + break; default: + Kohana::log("error", "Number of arguments: " . count($args)); call_user_func_array(array("gallery_event", $function), $args); } } - // @todo: consider calling gallery_event first, since for things menus we need it to do some - // setup foreach (self::$active as $module) { if ($module->name == "gallery") { continue; -- cgit v1.2.3 From 39cd84d86c69090ccf861b9bd2b4758350a47de2 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Tue, 29 Sep 2009 09:11:43 -0700 Subject: Remove a debugging log statement --- modules/gallery/helpers/module.php | 1 - 1 file changed, 1 deletion(-) (limited to 'modules/gallery/helpers/module.php') diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php index 8e203566..a27fdbc5 100644 --- a/modules/gallery/helpers/module.php +++ b/modules/gallery/helpers/module.php @@ -301,7 +301,6 @@ class module_Core { gallery_event::$function($args[0], $args[1], $args[2], $args[3]); break; default: - Kohana::log("error", "Number of arguments: " . count($args)); call_user_func_array(array("gallery_event", $function), $args); } } -- cgit v1.2.3 From 81eaf1e46cb1646bf6b5d5c2f86ea3b3c7a0bd06 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Wed, 30 Sep 2009 17:30:01 -0700 Subject: Add functionality to activate sidebar blocks when the module is activated and deactivate the sidebar blocks when the module is deactivated. --- modules/gallery/helpers/block_manager.php | 23 +++++++++++++++++++++++ modules/gallery/helpers/gallery_installer.php | 2 +- modules/gallery/helpers/module.php | 6 ++++++ 3 files changed, 30 insertions(+), 1 deletion(-) (limited to 'modules/gallery/helpers/module.php') diff --git a/modules/gallery/helpers/block_manager.php b/modules/gallery/helpers/block_manager.php index 233e4f2e..906a251d 100644 --- a/modules/gallery/helpers/block_manager.php +++ b/modules/gallery/helpers/block_manager.php @@ -32,12 +32,35 @@ class block_manager_Core { self::set_active($location, $blocks); } + static function activate_sidebar_blocks($module_name) { + $block_class = "{$module_name}_block"; + if (method_exists($block_class, "get_site_list")) { + $blocks = call_user_func(array($block_class, "get_site_list")); + Kohana::log("error", Kohana::debug($blocks)); + foreach (array_keys($blocks) as $id) { + list ($unused, $block_id) = explode(":", $id); + self::add("site.sidebar", $module_name, $block_id); + } + } + } + static function remove($location, $block_id) { $blocks = self::get_active($location); unset($blocks[$block_id]); self::set_active($location, $blocks); } + static function deactivate_sidebar_blocks($module_name) { + $block_class = "{$module_name}_block"; + if (method_exists($block_class, "get_site_list")) { + $blocks = call_user_func(array($block_class, "get_site_list")); + foreach (array_keys($blocks) as $id) { + list ($unused, $block_id) = explode(":", $id); + self::remove("site.sidebar", $module_name, $block_id); + } + } + } + static function get_available_admin_blocks() { return self::_get_blocks("get_admin_list"); } diff --git a/modules/gallery/helpers/gallery_installer.php b/modules/gallery/helpers/gallery_installer.php index 743808ea..b1ea1f19 100644 --- a/modules/gallery/helpers/gallery_installer.php +++ b/modules/gallery/helpers/gallery_installer.php @@ -386,7 +386,7 @@ class gallery_installer { $sidebar_blocks = block_manager::get_active("site.sidebar"); if (empty($sidebar_blocks)) { $available_blocks = block_manager::get_available_site_blocks(); - foreach (array_key(block_manager::get_available_site_blocks()) as $id) { + foreach (array_keys(block_manager::get_available_site_blocks()) as $id) { $sidebar_blocks[] = explode(":", $id); } block_manager::set_active("site.sidebar", $sidebar_blocks); diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php index a27fdbc5..fe37f4f9 100644 --- a/modules/gallery/helpers/module.php +++ b/modules/gallery/helpers/module.php @@ -195,6 +195,9 @@ class module_Core { module::load_modules(); graphics::activate_rules($module_name); + + block_manager::activate_sidebar_blocks($module_name); + log::success( "module", t("Activated module %module_name", array("module_name" => $module_name))); } @@ -219,6 +222,9 @@ class module_Core { module::load_modules(); graphics::deactivate_rules($module_name); + + block_manager::deactivate_sidebar_blocks($module_name); + log::success( "module", t("Deactivated module %module_name", array("module_name" => $module_name))); } -- cgit v1.2.3 From aa0529d557ed0609bf7e5b23a5cf2437f7998c4b Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Sun, 4 Oct 2009 09:45:17 -0700 Subject: Create a gallery::plugin_path which returns the appropriate path to the module or theme. This checks for the existence of an application/modules or application/themes first. --- modules/gallery/controllers/admin_themes.php | 31 +++++++++++++----------- modules/gallery/helpers/gallery.php | 13 ++++++++++ modules/gallery/helpers/gallery_installer.php | 4 ++-- modules/gallery/helpers/module.php | 34 +++++++++++++++++---------- modules/gallery/helpers/theme.php | 7 ++---- 5 files changed, 55 insertions(+), 34 deletions(-) (limited to 'modules/gallery/helpers/module.php') diff --git a/modules/gallery/controllers/admin_themes.php b/modules/gallery/controllers/admin_themes.php index 24f91aba..722cfb45 100644 --- a/modules/gallery/controllers/admin_themes.php +++ b/modules/gallery/controllers/admin_themes.php @@ -29,17 +29,20 @@ class Admin_Themes_Controller extends Admin_Controller { private function _get_themes() { $themes = array(); - foreach (scandir(THEMEPATH) as $theme_name) { - if ($theme_name[0] == ".") { - continue; - } - - $file = THEMEPATH . "$theme_name/theme.info"; - $theme_info = new ArrayObject(parse_ini_file($file), ArrayObject::ARRAY_AS_PROPS); - $theme_info->description = t($theme_info->description); - $theme_info->name = t($theme_info->name); + foreach (array(APPPATH . "themes/", THEMEPATH) as $themepath) { + foreach (scandir($themepath) as $theme_name) { + if ($theme_name[0] == ".") { + continue; + } + $file = $themepath . "$theme_name/theme.info"; + if (file_exists($file)) { + $theme_info = new ArrayObject(parse_ini_file($file), ArrayObject::ARRAY_AS_PROPS); + $theme_info->description = t($theme_info->description); + $theme_info->name = t($theme_info->name); - $themes[$theme_name] = $theme_info; + $themes[$theme_name] = $theme_info; + } + } } return $themes; } @@ -47,8 +50,8 @@ class Admin_Themes_Controller extends Admin_Controller { public function preview($type, $theme_name) { $view = new View("admin_themes_preview.html"); $theme_name = preg_replace("/[^\w]/", "", $theme_name); - $view->info = new ArrayObject( - parse_ini_file(THEMEPATH . "$theme_name/theme.info"), ArrayObject::ARRAY_AS_PROPS); + $view->info = new ArrayObject(parse_ini_file( + gallery::plugin_path("$theme_name/theme.info", "theme")), ArrayObject::ARRAY_AS_PROPS); $view->theme_name = $theme_name; $view->type = $type; if ($type == "admin") { @@ -63,8 +66,8 @@ class Admin_Themes_Controller extends Admin_Controller { access::verify_csrf(); $theme_name = preg_replace("/[^\w]/", "", $theme_name); - $info = new ArrayObject( - parse_ini_file(THEMEPATH . "$theme_name/theme.info"), ArrayObject::ARRAY_AS_PROPS); + $info = new ArrayObject(parse_ini_file( + gallery::plugin_path("$theme_name/theme.info", "theme")), ArrayObject::ARRAY_AS_PROPS); if ($type == "admin" && $info->admin) { module::set_var("gallery", "active_admin_theme", $theme_name); diff --git a/modules/gallery/helpers/gallery.php b/modules/gallery/helpers/gallery.php index 37a08d08..6d387d76 100644 --- a/modules/gallery/helpers/gallery.php +++ b/modules/gallery/helpers/gallery.php @@ -110,4 +110,17 @@ class gallery_Core { return $file_name; } + /** + * Return a full path to the theme or module file. It checks the APPPATH/(themes|modules) first + * then the THEMEPATH | MODPATH + * @param $file the file or directory + * @param $type ("module" | "theme" optional: defaults to "module") + * @return string + */ + static function plugin_path($file, $type="module") { + if (!file_exists($ofile = APPPATH . "{$type}s/$file")) { + $ofile = $type == "module" ? MODPATH . $file : THEMEPATH . $file; + } + return $ofile; + } } \ No newline at end of file diff --git a/modules/gallery/helpers/gallery_installer.php b/modules/gallery/helpers/gallery_installer.php index b1ea1f19..e834a62c 100644 --- a/modules/gallery/helpers/gallery_installer.php +++ b/modules/gallery/helpers/gallery_installer.php @@ -245,8 +245,8 @@ class gallery_installer { // Instantiate default themes (site and admin) foreach (array("wind", "admin_wind") as $theme_name) { - $theme_info = new ArrayObject(parse_ini_file(THEMEPATH . $theme_name . "/theme.info"), - ArrayObject::ARRAY_AS_PROPS); + $file = gallery::plugin_path("$theme_name/theme.info", "theme"); + $theme_info = new ArrayObject(parse_ini_file($file, ArrayObject::ARRAY_AS_PROPS); $theme = ORM::factory("theme"); $theme->name = $theme_name; $theme->version = $theme_info->version; diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php index fe37f4f9..99c52cab 100644 --- a/modules/gallery/helpers/module.php +++ b/modules/gallery/helpers/module.php @@ -77,15 +77,23 @@ class module_Core { static function available() { if (empty(self::$available)) { $modules = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS); - foreach (glob(MODPATH . "*/module.info") as $file) { - $module_name = basename(dirname($file)); - $modules->$module_name = new ArrayObject(parse_ini_file($file), ArrayObject::ARRAY_AS_PROPS); - $m =& $modules->$module_name; - $m->installed = self::is_installed($module_name); - $m->active = self::is_active($module_name); - $m->code_version = $m->version; - $m->version = self::get_version($module_name); - $m->locked = false; + foreach (array(APPPATH . "modules/", MODPATH) as $modpath) { + foreach (scandir($modpath) as $module_name) { + if ($module_name[0] == ".") { + continue; + } + $file = "{$modpath}$module_name/module.info"; + if (file_exists($file)) { + $modules->$module_name = + new ArrayObject(parse_ini_file($file), ArrayObject::ARRAY_AS_PROPS); + $m =& $modules->$module_name; + $m->installed = self::is_installed($module_name); + $m->active = self::is_active($module_name); + $m->code_version = $m->version; + $m->version = self::get_version($module_name); + $m->locked = false; + } + } } // Lock certain modules @@ -113,7 +121,7 @@ class module_Core { */ static function install($module_name) { $kohana_modules = Kohana::config("core.modules"); - array_unshift($kohana_modules, MODPATH . $module_name); + array_unshift($kohana_modules, gallery::plugin_path($module_name)); Kohana::config_set("core.modules", $kohana_modules); $installer_class = "{$module_name}_installer"; @@ -140,7 +148,7 @@ class module_Core { */ static function upgrade($module_name) { $kohana_modules = Kohana::config("core.modules"); - array_unshift($kohana_modules, MODPATH . $module_name); + array_unshift($kohana_modules, gallery::plugin_path($module_name)); Kohana::config_set("core.modules", $kohana_modules); $version_before = module::get_version($module_name); @@ -179,7 +187,7 @@ class module_Core { */ static function activate($module_name) { $kohana_modules = Kohana::config("core.modules"); - array_unshift($kohana_modules, MODPATH . $module_name); + array_unshift($kohana_modules, gallery::plugin_path($module_name)); Kohana::config_set("core.modules", $kohana_modules); $installer_class = "{$module_name}_installer"; @@ -271,7 +279,7 @@ class module_Core { $gallery = $module; } else { self::$active[] = $module; - $kohana_modules[] = MODPATH . $module->name; + $kohana_modules[] = gallery::plugin_path($module->name); } } self::$active[] = $gallery; // put gallery last in the module list to match core.modules diff --git a/modules/gallery/helpers/theme.php b/modules/gallery/helpers/theme.php index fb8f7ca7..3ba11aa2 100644 --- a/modules/gallery/helpers/theme.php +++ b/modules/gallery/helpers/theme.php @@ -30,11 +30,8 @@ class theme_Core { */ static function load_themes() { $modules = Kohana::config("core.modules"); - if (Router::$controller == "admin") { - array_unshift($modules, THEMEPATH . module::get_var("gallery", "active_admin_theme")); - } else { - array_unshift($modules, THEMEPATH . module::get_var("gallery", "active_site_theme")); - } + array_unshift($modules, gallery::plugin_path(module::get_var("gallery", + (Router::$controller == "admin") ? "active_admin_theme" : "active_site_theme"), "theme")); Kohana::config_set("core.modules", $modules); } -- cgit v1.2.3 From 2634a683b30982963264faf9867d32d1aa71a182 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Sun, 4 Oct 2009 10:04:35 -0700 Subject: Revert "Create a gallery::plugin_path which returns the appropriate path to the module or theme. This checks for the existence of an application/modules or application/themes first." This reverts commit e1e1461a77caf5bff457927f098366497de6ffff. --- modules/gallery/controllers/admin_themes.php | 31 +++++++++++------------- modules/gallery/helpers/gallery.php | 13 ---------- modules/gallery/helpers/gallery_installer.php | 4 ++-- modules/gallery/helpers/module.php | 34 ++++++++++----------------- modules/gallery/helpers/theme.php | 7 ++++-- 5 files changed, 34 insertions(+), 55 deletions(-) (limited to 'modules/gallery/helpers/module.php') diff --git a/modules/gallery/controllers/admin_themes.php b/modules/gallery/controllers/admin_themes.php index 722cfb45..24f91aba 100644 --- a/modules/gallery/controllers/admin_themes.php +++ b/modules/gallery/controllers/admin_themes.php @@ -29,20 +29,17 @@ class Admin_Themes_Controller extends Admin_Controller { private function _get_themes() { $themes = array(); - foreach (array(APPPATH . "themes/", THEMEPATH) as $themepath) { - foreach (scandir($themepath) as $theme_name) { - if ($theme_name[0] == ".") { - continue; - } - $file = $themepath . "$theme_name/theme.info"; - if (file_exists($file)) { - $theme_info = new ArrayObject(parse_ini_file($file), ArrayObject::ARRAY_AS_PROPS); - $theme_info->description = t($theme_info->description); - $theme_info->name = t($theme_info->name); - - $themes[$theme_name] = $theme_info; - } + foreach (scandir(THEMEPATH) as $theme_name) { + if ($theme_name[0] == ".") { + continue; } + + $file = THEMEPATH . "$theme_name/theme.info"; + $theme_info = new ArrayObject(parse_ini_file($file), ArrayObject::ARRAY_AS_PROPS); + $theme_info->description = t($theme_info->description); + $theme_info->name = t($theme_info->name); + + $themes[$theme_name] = $theme_info; } return $themes; } @@ -50,8 +47,8 @@ class Admin_Themes_Controller extends Admin_Controller { public function preview($type, $theme_name) { $view = new View("admin_themes_preview.html"); $theme_name = preg_replace("/[^\w]/", "", $theme_name); - $view->info = new ArrayObject(parse_ini_file( - gallery::plugin_path("$theme_name/theme.info", "theme")), ArrayObject::ARRAY_AS_PROPS); + $view->info = new ArrayObject( + parse_ini_file(THEMEPATH . "$theme_name/theme.info"), ArrayObject::ARRAY_AS_PROPS); $view->theme_name = $theme_name; $view->type = $type; if ($type == "admin") { @@ -66,8 +63,8 @@ class Admin_Themes_Controller extends Admin_Controller { access::verify_csrf(); $theme_name = preg_replace("/[^\w]/", "", $theme_name); - $info = new ArrayObject(parse_ini_file( - gallery::plugin_path("$theme_name/theme.info", "theme")), ArrayObject::ARRAY_AS_PROPS); + $info = new ArrayObject( + parse_ini_file(THEMEPATH . "$theme_name/theme.info"), ArrayObject::ARRAY_AS_PROPS); if ($type == "admin" && $info->admin) { module::set_var("gallery", "active_admin_theme", $theme_name); diff --git a/modules/gallery/helpers/gallery.php b/modules/gallery/helpers/gallery.php index 6d387d76..37a08d08 100644 --- a/modules/gallery/helpers/gallery.php +++ b/modules/gallery/helpers/gallery.php @@ -110,17 +110,4 @@ class gallery_Core { return $file_name; } - /** - * Return a full path to the theme or module file. It checks the APPPATH/(themes|modules) first - * then the THEMEPATH | MODPATH - * @param $file the file or directory - * @param $type ("module" | "theme" optional: defaults to "module") - * @return string - */ - static function plugin_path($file, $type="module") { - if (!file_exists($ofile = APPPATH . "{$type}s/$file")) { - $ofile = $type == "module" ? MODPATH . $file : THEMEPATH . $file; - } - return $ofile; - } } \ No newline at end of file diff --git a/modules/gallery/helpers/gallery_installer.php b/modules/gallery/helpers/gallery_installer.php index e834a62c..b1ea1f19 100644 --- a/modules/gallery/helpers/gallery_installer.php +++ b/modules/gallery/helpers/gallery_installer.php @@ -245,8 +245,8 @@ class gallery_installer { // Instantiate default themes (site and admin) foreach (array("wind", "admin_wind") as $theme_name) { - $file = gallery::plugin_path("$theme_name/theme.info", "theme"); - $theme_info = new ArrayObject(parse_ini_file($file, ArrayObject::ARRAY_AS_PROPS); + $theme_info = new ArrayObject(parse_ini_file(THEMEPATH . $theme_name . "/theme.info"), + ArrayObject::ARRAY_AS_PROPS); $theme = ORM::factory("theme"); $theme->name = $theme_name; $theme->version = $theme_info->version; diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php index 99c52cab..fe37f4f9 100644 --- a/modules/gallery/helpers/module.php +++ b/modules/gallery/helpers/module.php @@ -77,23 +77,15 @@ class module_Core { static function available() { if (empty(self::$available)) { $modules = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS); - foreach (array(APPPATH . "modules/", MODPATH) as $modpath) { - foreach (scandir($modpath) as $module_name) { - if ($module_name[0] == ".") { - continue; - } - $file = "{$modpath}$module_name/module.info"; - if (file_exists($file)) { - $modules->$module_name = - new ArrayObject(parse_ini_file($file), ArrayObject::ARRAY_AS_PROPS); - $m =& $modules->$module_name; - $m->installed = self::is_installed($module_name); - $m->active = self::is_active($module_name); - $m->code_version = $m->version; - $m->version = self::get_version($module_name); - $m->locked = false; - } - } + foreach (glob(MODPATH . "*/module.info") as $file) { + $module_name = basename(dirname($file)); + $modules->$module_name = new ArrayObject(parse_ini_file($file), ArrayObject::ARRAY_AS_PROPS); + $m =& $modules->$module_name; + $m->installed = self::is_installed($module_name); + $m->active = self::is_active($module_name); + $m->code_version = $m->version; + $m->version = self::get_version($module_name); + $m->locked = false; } // Lock certain modules @@ -121,7 +113,7 @@ class module_Core { */ static function install($module_name) { $kohana_modules = Kohana::config("core.modules"); - array_unshift($kohana_modules, gallery::plugin_path($module_name)); + array_unshift($kohana_modules, MODPATH . $module_name); Kohana::config_set("core.modules", $kohana_modules); $installer_class = "{$module_name}_installer"; @@ -148,7 +140,7 @@ class module_Core { */ static function upgrade($module_name) { $kohana_modules = Kohana::config("core.modules"); - array_unshift($kohana_modules, gallery::plugin_path($module_name)); + array_unshift($kohana_modules, MODPATH . $module_name); Kohana::config_set("core.modules", $kohana_modules); $version_before = module::get_version($module_name); @@ -187,7 +179,7 @@ class module_Core { */ static function activate($module_name) { $kohana_modules = Kohana::config("core.modules"); - array_unshift($kohana_modules, gallery::plugin_path($module_name)); + array_unshift($kohana_modules, MODPATH . $module_name); Kohana::config_set("core.modules", $kohana_modules); $installer_class = "{$module_name}_installer"; @@ -279,7 +271,7 @@ class module_Core { $gallery = $module; } else { self::$active[] = $module; - $kohana_modules[] = gallery::plugin_path($module->name); + $kohana_modules[] = MODPATH . $module->name; } } self::$active[] = $gallery; // put gallery last in the module list to match core.modules diff --git a/modules/gallery/helpers/theme.php b/modules/gallery/helpers/theme.php index 3ba11aa2..fb8f7ca7 100644 --- a/modules/gallery/helpers/theme.php +++ b/modules/gallery/helpers/theme.php @@ -30,8 +30,11 @@ class theme_Core { */ static function load_themes() { $modules = Kohana::config("core.modules"); - array_unshift($modules, gallery::plugin_path(module::get_var("gallery", - (Router::$controller == "admin") ? "active_admin_theme" : "active_site_theme"), "theme")); + if (Router::$controller == "admin") { + array_unshift($modules, THEMEPATH . module::get_var("gallery", "active_admin_theme")); + } else { + array_unshift($modules, THEMEPATH . module::get_var("gallery", "active_site_theme")); + } Kohana::config_set("core.modules", $modules); } -- cgit v1.2.3 From 6d5c12e13e6f1199a96180e69cac69d77ecbbcc2 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Sat, 17 Oct 2009 10:36:50 -0700 Subject: Move the default identity config into the users module and change the Identity constructor to look in module::get_var(gallery, identity_provider) for the current identity driver. In addition, don't just arbitrarily lock the use module. Only lock gallery and the module that is referenced by "user_driver_module" variable. --- modules/gallery/config/identity.php | 37 ------------------- modules/gallery/helpers/module.php | 3 +- modules/gallery/libraries/Identity.php | 66 ++++++++++++++-------------------- modules/user/config/identity.php | 37 +++++++++++++++++++ 4 files changed, 65 insertions(+), 78 deletions(-) delete mode 100644 modules/gallery/config/identity.php create mode 100644 modules/user/config/identity.php (limited to 'modules/gallery/helpers/module.php') diff --git a/modules/gallery/config/identity.php b/modules/gallery/config/identity.php deleted file mode 100644 index 0479d08b..00000000 --- a/modules/gallery/config/identity.php +++ /dev/null @@ -1,37 +0,0 @@ - "gallery", - "allow_updates" => true, - "params" => array(), -); diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php index fe37f4f9..eab94500 100644 --- a/modules/gallery/helpers/module.php +++ b/modules/gallery/helpers/module.php @@ -90,7 +90,8 @@ class module_Core { // Lock certain modules $modules->gallery->locked = true; - $modules->user->locked = true; + $identity_module = self::get_var("gallery", "identity_provider", "user"); + $modules->$identity_module->locked = true; $modules->ksort(); self::$available = $modules; } diff --git a/modules/gallery/libraries/Identity.php b/modules/gallery/libraries/Identity.php index f844cf8f..9eb4b83b 100644 --- a/modules/gallery/libraries/Identity.php +++ b/modules/gallery/libraries/Identity.php @@ -49,49 +49,35 @@ class Identity_Core { /** * Loads the configured driver and validates it. * - * @param array|string custom configuration or config group name * @return void */ - public function __construct($config="default") { - if (is_string($config)) { - $name = $config; - - // Test the config group name - if (($config = Kohana::config("identity.".$config)) === NULL) { - throw new Exception("@todo NO USER LIBRARY CONFIGURATION FOR: $name"); - } - - if (is_array($config)) { - // Append the default configuration options - $config += Kohana::config("identity.default"); - } else { - // Load the default group - $config = Kohana::config("identity.default"); - } - - // Cache the config in the object - $this->config = $config; - - // Set driver name - $driver = "Identity_".ucfirst($this->config["driver"])."_Driver"; - - // Load the driver - if ( ! Kohana::auto_load($driver)) { - throw new Kohana_Exception("core.driver_not_found", $this->config["driver"], - get_class($this)); - } - - // Initialize the driver - $this->driver = new $driver($this->config["params"]); - - // Validate the driver - if ( !($this->driver instanceof Identity_Driver)) { - throw new Kohana_Exception("core.driver_implements", $this->config["driver"], - get_class($this), "Identity_Driver"); - } - - Kohana::log("debug", "Identity Library initialized"); + public function __construct() { + $name = $config = module::get_var("gallery", "identity_provider", "user"); + + // Test the config group name + if (($this->config = Kohana::config("identity.".$config)) === NULL) { + throw new Exception("@todo NO USER LIBRARY CONFIGURATION FOR: $name"); + } + + // Set driver name + $driver = "Identity_".ucfirst($this->config["driver"])."_Driver"; + + // Load the driver + if ( ! Kohana::auto_load($driver)) { + throw new Kohana_Exception("core.driver_not_found", $this->config["driver"], + get_class($this)); } + + // Initialize the driver + $this->driver = new $driver($this->config["params"]); + + // Validate the driver + if ( !($this->driver instanceof Identity_Driver)) { + throw new Kohana_Exception("core.driver_implements", $this->config["driver"], + get_class($this), "Identity_Driver"); + } + + Kohana::log("debug", "Identity Library initialized"); } /** diff --git a/modules/user/config/identity.php b/modules/user/config/identity.php new file mode 100644 index 00000000..f9f013aa --- /dev/null +++ b/modules/user/config/identity.php @@ -0,0 +1,37 @@ + "gallery", + "allow_updates" => true, + "params" => array(), +); -- cgit v1.2.3 From 4949a2ce0b5daca7afe86a261be447440fce7eff Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Sun, 18 Oct 2009 09:23:59 -0700 Subject: Optimize the get method to retrieve the module information from the loaded modules. In addition add a method "info" to return the module information contained in the module.info file --- modules/gallery/helpers/module.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'modules/gallery/helpers/module.php') diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php index fe37f4f9..77ec6f63 100644 --- a/modules/gallery/helpers/module.php +++ b/modules/gallery/helpers/module.php @@ -50,8 +50,20 @@ class module_Core { * @param string $module_name */ static function get($module_name) { - // @todo can't easily use model_cache here because it throw an exception on missing models. - return ORM::factory("module", array("name" => $module_name)); + if (empty(self::$modules[$module_name])) { + return ORM::factory("module", array("name" => $module_name)); + } + return self::$modules[$module_name]; + } + + /** + * Get the information about a module + * @returns ArrayObject containing the module information from the module.info file or false if + * not found + */ + static function info($module_name) { + $module_list = self::available(); + return isset($module_list->$module_name) ? $module_list->$module_name : false; } /** @@ -79,7 +91,8 @@ class module_Core { $modules = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS); foreach (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 = + new ArrayObject(parse_ini_file($file), ArrayObject::ARRAY_AS_PROPS); $m =& $modules->$module_name; $m->installed = self::is_installed($module_name); $m->active = self::is_active($module_name); -- cgit v1.2.3 From 89ca1590e4435da56fc15c74fcff74b467bb8717 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Thu, 22 Oct 2009 17:05:00 -0700 Subject: When uninstalling a module call graphics:remove_rules instead of graphics remove_rule. --- modules/gallery/helpers/module.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/gallery/helpers/module.php') diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php index fb298959..1d77e63d 100644 --- a/modules/gallery/helpers/module.php +++ b/modules/gallery/helpers/module.php @@ -254,7 +254,7 @@ class module_Core { call_user_func(array($installer_class, "uninstall")); } - graphics::remove_rule($module_name); + graphics::remove_rules($module_name); $module = self::get($module_name); if ($module->loaded) { $module->delete(); -- cgit v1.2.3 From b74b131e25ca0ddb42d2545a5d0ea2d796452f1d Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Thu, 22 Oct 2009 22:29:56 -0700 Subject: Change Identity adminstration to use the uninstall/install methods when changing providers. --- modules/gallery/controllers/admin_identity.php | 19 +++-- modules/gallery/helpers/identity.php | 34 ++++----- modules/gallery/helpers/module.php | 4 +- modules/gallery/libraries/IdentityProvider.php | 26 ++----- .../gallery/libraries/drivers/IdentityProvider.php | 10 --- modules/gallery/views/admin_identity.html.php | 4 +- .../gallery/views/admin_identity_confirm.html.php | 2 +- modules/user/helpers/user.php | 85 ---------------------- modules/user/helpers/user_installer.php | 76 +++++++++++++++++-- .../libraries/drivers/IdentityProvider/Gallery.php | 16 +--- 10 files changed, 110 insertions(+), 166 deletions(-) (limited to 'modules/gallery/helpers/module.php') diff --git a/modules/gallery/controllers/admin_identity.php b/modules/gallery/controllers/admin_identity.php index d06132ff..0521a0f8 100644 --- a/modules/gallery/controllers/admin_identity.php +++ b/modules/gallery/controllers/admin_identity.php @@ -47,23 +47,26 @@ class Admin_Identity_Controller extends Admin_Controller { module::event("pre_identity_change", $active_provider, $new_provider); - identity::deactivate(); + module::deactivate($active_provider); + module::uninstall($active_provider); + + try { + Session::instance()->destroy(); + } catch (Exception $e) { + // We don't care if there was a problem destroying the session. + } // Switch authentication - module::set_var("gallery", "identity_provider", $new_provider); identity::reset(); + module::set_var("gallery", "identity_provider", $new_provider); - identity::activate(); + module::install($new_provider); + module::activate($new_provider); // @todo this type of collation is questionable from an i18n perspective message::success(t("Changed to %description", array("description" => $providers->$new_provider))); - try { - Session::instance()->destroy(); - } catch (Exception $e) { - // We don't care if there was a problem destroying the session. - } url::redirect(item::root()->abs_url()); } diff --git a/modules/gallery/helpers/identity.php b/modules/gallery/helpers/identity.php index cf84c8a9..d0cba8e7 100644 --- a/modules/gallery/helpers/identity.php +++ b/modules/gallery/helpers/identity.php @@ -39,6 +39,16 @@ class identity_Core { return self::$available; } + /** + * Frees the current instance of the identity provider so the next call to instance will reload + * + * @param string configuration + * @return Identity_Core + */ + static function reset() { + IdentityProvider::reset(); + } + /** * Make sure that we have a session and group_ids cached in the session. */ @@ -71,12 +81,12 @@ class identity_Core { $session->set("group_ids", $ids); } //} catch (Exception $e) { - //try { - //Session::instance()->destroy(); - //} catch (Exception $e) { + // try { + // Session::instance()->destroy(); + // } catch (Exception $e) { // We don't care if there was a problem destroying the session. - //} - //url::redirect(item::root()->abs_url()); + // } + // url::redirect(item::root()->abs_url()); //} } @@ -125,20 +135,6 @@ class identity_Core { return IdentityProvider::instance()->is_writable(); } - /** - * @see IdentityProvider_Driver::activate. - */ - static function activate() { - IdentityProvider::instance()->activate(); - } - - /** - * @see IdentityProvider_Driver::deactivate. - */ - static function deactivate() { - IdentityProvider::instance()->deactivate(); - } - /** * @see IdentityProvider_Driver::guest. */ diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php index 1d77e63d..9d41cd51 100644 --- a/modules/gallery/helpers/module.php +++ b/modules/gallery/helpers/module.php @@ -130,6 +130,8 @@ class module_Core { array_unshift($kohana_modules, MODPATH . $module_name); Kohana::config_set("core.modules", $kohana_modules); + // Rebuild the include path so the module installer can benefit from auto loading + Kohana::include_paths(true); $installer_class = "{$module_name}_installer"; if (method_exists($installer_class, "install")) { call_user_func_array(array($installer_class, "install"), array()); @@ -154,7 +156,7 @@ class module_Core { */ static function upgrade($module_name) { $kohana_modules = Kohana::config("core.modules"); - array_unshift($kohana_modules, MODPATH . $module_name); + $kohana_modules = array_unshift($kohana_modules, MODPATH . $module_name); Kohana::config_set("core.modules", $kohana_modules); $version_before = module::get_version($module_name); diff --git a/modules/gallery/libraries/IdentityProvider.php b/modules/gallery/libraries/IdentityProvider.php index 512f28eb..38718d4b 100644 --- a/modules/gallery/libraries/IdentityProvider.php +++ b/modules/gallery/libraries/IdentityProvider.php @@ -38,7 +38,7 @@ class IdentityProvider_Core { * @return Identity_Core */ static function & instance() { - if (!isset(self::$instance)) { + if (empty(self::$instance)) { // Create a new instance self::$instance = new IdentityProvider(); } @@ -47,14 +47,14 @@ class IdentityProvider_Core { } /** - * Returns a singleton instance of Identity. - * There can only be one Identity driver configured at a given point + * Frees the current instance of the identity provider so the next call to instance will reload * * @param string configuration * @return Identity_Core */ static function reset() { - self::$instance = new IdentityProvider(); + self::$instance = null; + Kohana::config_clear("identity"); } /** @@ -66,12 +66,12 @@ class IdentityProvider_Core { $config = module::get_var("gallery", "identity_provider", "user"); // Test the config group name - if (($this->config = Kohana::config("identity.".$config)) === NULL) { + if (($this->config = Kohana::config("identity." . $config)) === NULL) { throw new Exception("@todo NO USER LIBRARY CONFIGURATION FOR: $config"); } // Set driver name - $driver = "IdentityProvider_".ucfirst($this->config["driver"])."_Driver"; + $driver = "IdentityProvider_" . ucfirst($this->config["driver"]) ."_Driver"; // Load the driver if ( ! Kohana::auto_load($driver)) { @@ -100,20 +100,6 @@ class IdentityProvider_Core { return !empty($this->config["allow_updates"]); } - /** - * @see IdentityProvider_Driver::activate. - */ - public function activate() { - $this->driver->activate(); - } - - /** - * @see IdentityProvider_Driver::deactivate. - */ - public function deactivate() { - $this->driver->deactivate(); - } - /** * @see IdentityProvider_Driver::guest. */ diff --git a/modules/gallery/libraries/drivers/IdentityProvider.php b/modules/gallery/libraries/drivers/IdentityProvider.php index 8a578d1b..5bb41dcc 100644 --- a/modules/gallery/libraries/drivers/IdentityProvider.php +++ b/modules/gallery/libraries/drivers/IdentityProvider.php @@ -18,16 +18,6 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ interface IdentityProvider_Driver { - /** - * Initialize the provider so it is ready to use - */ - public function activate(); - - /** - * Cleanup up this provider so it is unavailable for use and won't conflict with the current driver - */ - public function deactivate(); - /** * Return the guest user. * diff --git a/modules/gallery/views/admin_identity.html.php b/modules/gallery/views/admin_identity.html.php index 1405cacb..358860cf 100644 --- a/modules/gallery/views/admin_identity.html.php +++ b/modules/gallery/views/admin_identity.html.php @@ -10,7 +10,7 @@ $("#g-dialog").html(data); $("#g-dialog").dialog({ bgiframe: true, - title: "", + title: for_js() ?>, resizable: false, height:165, modal: true, @@ -34,7 +34,7 @@
-

+

diff --git a/modules/gallery/views/admin_identity_confirm.html.php b/modules/gallery/views/admin_identity_confirm.html.php index e14525b5..54aae9c8 100644 --- a/modules/gallery/views/admin_identity_confirm.html.php +++ b/modules/gallery/views/admin_identity_confirm.html.php @@ -4,7 +4,7 @@

- +

diff --git a/modules/user/helpers/user.php b/modules/user/helpers/user.php index 5f154313..5ef2b726 100644 --- a/modules/user/helpers/user.php +++ b/modules/user/helpers/user.php @@ -24,91 +24,6 @@ * Note: by design, this class does not do any permission checking. */ class user_Core { - /** - * Initialize the provider so it is ready to use - */ - static function activate() { - $db = Database::instance(); - $db->query("CREATE TABLE IF NOT EXISTS {users} ( - `id` int(9) NOT NULL auto_increment, - `name` varchar(32) NOT NULL, - `full_name` varchar(255) NOT NULL, - `password` varchar(64) NOT NULL, - `login_count` int(10) unsigned NOT NULL DEFAULT 0, - `last_login` int(10) unsigned NOT NULL DEFAULT 0, - `email` varchar(64) default NULL, - `admin` BOOLEAN default 0, - `guest` BOOLEAN default 0, - `hash` char(32) default NULL, - `url` varchar(255) default NULL, - `locale` char(10) default NULL, - PRIMARY KEY (`id`), - UNIQUE KEY(`hash`), - UNIQUE KEY(`name`)) - DEFAULT CHARSET=utf8;"); - - $db->query("CREATE TABLE IF NOT EXISTS {groups} ( - `id` int(9) NOT NULL auto_increment, - `name` char(64) default NULL, - `special` BOOLEAN default 0, - PRIMARY KEY (`id`), - UNIQUE KEY(`name`)) - DEFAULT CHARSET=utf8;"); - - $db->query("CREATE TABLE IF NOT EXISTS {groups_users} ( - `group_id` int(9) NOT NULL, - `user_id` int(9) NOT NULL, - PRIMARY KEY (`group_id`, `user_id`), - UNIQUE KEY(`user_id`, `group_id`)) - DEFAULT CHARSET=utf8;"); - - $everybody = group::create("Everybody"); - $everybody->special = true; - $everybody->save(); - - $registered = group::create("Registered Users"); - $registered->special = true; - $registered->save(); - - $guest = user::create("guest", "Guest User", ""); - $guest->guest = true; - $guest->remove($registered); - $guest->save(); - - $admin = user::create("admin", "Gallery Administrator", "admin"); - $admin->admin = true; - $admin->save(); - - // Let the admin own everything - $db->query("update {items} set owner_id = {$admin->id}"); - - $root = ORM::factory("item", 1); - access::allow($everybody, "view", $root); - access::allow($everybody, "view_full", $root); - - access::allow($registered, "view", $root); - access::allow($registered, "view_full", $root); - } - - /** - * Cleanup up this provider so it is unavailable for use and won't conflict with the current driver - */ - static function deactivate() { - // Delete all users and groups so that we give other modules an opportunity to clean up - foreach (ORM::factory("user")->find_all() as $user) { - $user->delete(); - } - - foreach (ORM::factory("group")->find_all() as $group) { - $group->delete(); - } - - $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};"); - } - /** * Return the guest user. * diff --git a/modules/user/helpers/user_installer.php b/modules/user/helpers/user_installer.php index 1410f1ef..36c617a8 100644 --- a/modules/user/helpers/user_installer.php +++ b/modules/user/helpers/user_installer.php @@ -19,18 +19,84 @@ */ class user_installer { static function install() { + $db = Database::instance(); + $db->query("CREATE TABLE IF NOT EXISTS {users} ( + `id` int(9) NOT NULL auto_increment, + `name` varchar(32) NOT NULL, + `full_name` varchar(255) NOT NULL, + `password` varchar(64) NOT NULL, + `login_count` int(10) unsigned NOT NULL DEFAULT 0, + `last_login` int(10) unsigned NOT NULL DEFAULT 0, + `email` varchar(64) default NULL, + `admin` BOOLEAN default 0, + `guest` BOOLEAN default 0, + `hash` char(32) default NULL, + `url` varchar(255) default NULL, + `locale` char(10) default NULL, + PRIMARY KEY (`id`), + UNIQUE KEY(`hash`), + UNIQUE KEY(`name`)) + DEFAULT CHARSET=utf8;"); + + $db->query("CREATE TABLE IF NOT EXISTS {groups} ( + `id` int(9) NOT NULL auto_increment, + `name` char(64) default NULL, + `special` BOOLEAN default 0, + PRIMARY KEY (`id`), + UNIQUE KEY(`name`)) + DEFAULT CHARSET=utf8;"); + + $db->query("CREATE TABLE IF NOT EXISTS {groups_users} ( + `group_id` int(9) NOT NULL, + `user_id` int(9) NOT NULL, + PRIMARY KEY (`group_id`, `user_id`), + UNIQUE KEY(`user_id`, `group_id`)) + DEFAULT CHARSET=utf8;"); + + $everybody = group::create("Everybody"); + $everybody->special = true; + $everybody->save(); + + $registered = group::create("Registered Users"); + $registered->special = true; + $registered->save(); + + $guest = user::create("guest", "Guest User", ""); + $guest->guest = true; + $guest->remove($registered); + $guest->save(); + + $admin = user::create("admin", "Gallery Administrator", "admin"); + $admin->admin = true; + $admin->save(); + + // Let the admin own everything + $db->query("update {items} set owner_id = {$admin->id}"); + + $root = ORM::factory("item", 1); + access::allow($everybody, "view", $root); + access::allow($everybody, "view_full", $root); + + access::allow($registered, "view", $root); + access::allow($registered, "view_full", $root); user::activate(); module::set_var("gallery", "identity_provider", "user"); module::set_version("user", 1); } static function uninstall() { - user::deactivate(); + // Delete all users and groups so that we give other modules an opportunity to clean up + foreach (ORM::factory("user")->find_all() as $user) { + $user->delete(); + } - try { - Session::instance()->destroy(); - } catch (Exception $e) { - // We don't care if there was a problem destroying the session. + foreach (ORM::factory("group")->find_all() as $group) { + $group->delete(); } + + $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};"); } } \ No newline at end of file diff --git a/modules/user/libraries/drivers/IdentityProvider/Gallery.php b/modules/user/libraries/drivers/IdentityProvider/Gallery.php index 5941abb7..026f04e9 100644 --- a/modules/user/libraries/drivers/IdentityProvider/Gallery.php +++ b/modules/user/libraries/drivers/IdentityProvider/Gallery.php @@ -20,21 +20,7 @@ /* * Based on the Cache_Sqlite_Driver developed by the Kohana Team */ -class Identity_Gallery_Driver implements IdentityProvider_Driver { - /** - * @see IdentityProvider_Driver::activate. - */ - public function activate() { - user::activate(); - } - - /** - * @see IdentityProvider_Driver::deactivate. - */ - public function deactivate() { - user::deactivate(); - } - +class IdentityProvider_Gallery_Driver implements IdentityProvider_Driver { /** * @see IdentityProvider_Driver::guest. */ -- cgit v1.2.3 From e4eedbce2298535540cb651d75ba6f1bf42cf02b Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Mon, 26 Oct 2009 09:35:41 -0700 Subject: Change the upgrader so that it never deactivactes the gallery nor the current identity provider modules. Call module::deactive to truly deactivate the module. --- modules/gallery/controllers/upgrader.php | 10 +++++++--- modules/gallery/helpers/module.php | 15 +++++++-------- 2 files changed, 14 insertions(+), 11 deletions(-) (limited to 'modules/gallery/helpers/module.php') diff --git a/modules/gallery/controllers/upgrader.php b/modules/gallery/controllers/upgrader.php index 1aa607ef..a86e8af9 100644 --- a/modules/gallery/controllers/upgrader.php +++ b/modules/gallery/controllers/upgrader.php @@ -56,9 +56,13 @@ class Upgrader_Controller extends Controller { access::forbidden(); } - // Upgrade gallery and user first - module::upgrade("gallery"); - module::upgrade("user"); + $available = module::available(); + // Upgrade gallery first + $gallery = $available["gallery"]; + if ($gallery->code_version != $gallery->version) { + module::upgrade("gallery"); + module::activate("gallery"); + } // Then upgrade the rest foreach (module::available() as $id => $module) { diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php index 9d41cd51..27bc3784 100644 --- a/modules/gallery/helpers/module.php +++ b/modules/gallery/helpers/module.php @@ -155,10 +155,6 @@ class module_Core { * @param string $module_name */ static function upgrade($module_name) { - $kohana_modules = Kohana::config("core.modules"); - $kohana_modules = array_unshift($kohana_modules, MODPATH . $module_name); - Kohana::config_set("core.modules", $kohana_modules); - $version_before = module::get_version($module_name); $installer_class = "{$module_name}_installer"; if (method_exists($installer_class, "upgrade")) { @@ -171,11 +167,14 @@ class module_Core { throw new Exception("@todo UNKNOWN_MODULE"); } } - module::load_modules(); - // Now the module is upgraded but inactive, so don't leave it in the active path - array_shift($kohana_modules); - Kohana::config_set("core.modules", $kohana_modules); + // Now the module is upgraded so deactivate it, but we can'it deactivae gallery or the + // current identity provider. + $identity_provider = module::get_var("gallery", "identity_provider", "user"); + if (!in_array($module_name, array("gallery", $identity_provider)) ) { + self::deactivate($module_name); + } + module::load_modules(); $version_after = module::get_version($module_name); if ($version_before != $version_after) { -- cgit v1.2.3 From 514915438b91f44cab1682ee7495e2ef43aeeab1 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Tue, 27 Oct 2009 07:57:51 -0700 Subject: Add a flag in the module.info (no_module_admin) to indicate that this module shouldn't be managed by the default module administration screen. This module will always be locked on that screen. --- modules/gallery/helpers/module.php | 2 +- modules/user/module.info | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'modules/gallery/helpers/module.php') diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php index 27bc3784..da334370 100644 --- a/modules/gallery/helpers/module.php +++ b/modules/gallery/helpers/module.php @@ -98,7 +98,7 @@ class module_Core { $m->active = self::is_active($module_name); $m->code_version = $m->version; $m->version = self::get_version($module_name); - $m->locked = false; + $m->locked = !empty($m->no_module_admin); } // Lock certain modules diff --git a/modules/user/module.info b/modules/user/module.info index 8a9af407..36a2179a 100644 --- a/modules/user/module.info +++ b/modules/user/module.info @@ -1,3 +1,6 @@ name = "Users and Groups" -description = "Provides user and group management" +description = "Gallery 3 user and group management" version = 1 + +; Don't show this module on the module administration screen +no_module_admin = 1 -- cgit v1.2.3 From 79f700ef9f79926d5e806bd48e5a6f99b6ecc5bb Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Thu, 12 Nov 2009 09:29:17 -0800 Subject: Change the keys of the block arrays in block manager to be a md5 hash of module_name:block_id. This allows easier lookup of blocks to remove when modules are being deactivated. Change the module activation/deactivation to call (activate|deactivate)_blocks instead of just the sidebar blocks. This insures that when a module is deactivated any admin dashboard blocks are removed as well the site sideboard blocks. Fix for ticket #876. --- installer/install.sql | 31 ++++++++++++++------------- modules/gallery/helpers/block_manager.php | 18 ++++++++++++---- modules/gallery/helpers/gallery_installer.php | 14 +++++++++++- modules/gallery/helpers/module.php | 4 ++-- modules/gallery/module.info | 2 +- 5 files changed, 46 insertions(+), 23 deletions(-) (limited to 'modules/gallery/helpers/module.php') diff --git a/installer/install.sql b/installer/install.sql index 714d8ab7..617d89ff 100644 --- a/installer/install.sql +++ b/installer/install.sql @@ -228,8 +228,8 @@ CREATE TABLE {modules} ( UNIQUE KEY `name` (`name`) ) AUTO_INCREMENT=10 DEFAULT CHARSET=utf8; SET character_set_client = @saved_cs_client; -INSERT INTO {modules} VALUES (1,1,'gallery',16); -INSERT INTO {modules} VALUES (2,1,'user',1); +INSERT INTO {modules} VALUES (1,1,'gallery',17); +INSERT INTO {modules} VALUES (2,1,'user',2); INSERT INTO {modules} VALUES (3,1,'comment',2); INSERT INTO {modules} VALUES (4,1,'organize',1); INSERT INTO {modules} VALUES (5,1,'info',1); @@ -264,7 +264,7 @@ CREATE TABLE {permissions} ( ) AUTO_INCREMENT=5 DEFAULT CHARSET=utf8; SET character_set_client = @saved_cs_client; INSERT INTO {permissions} VALUES (1,'View','view'); -INSERT INTO {permissions} VALUES (2,'View Full Size','view_full'); +INSERT INTO {permissions} VALUES (2,'View full size','view_full'); INSERT INTO {permissions} VALUES (3,'Edit','edit'); INSERT INTO {permissions} VALUES (4,'Add','add'); DROP TABLE IF EXISTS {search_records}; @@ -366,7 +366,7 @@ CREATE TABLE {vars} ( `value` text, PRIMARY KEY (`id`), UNIQUE KEY `module_name` (`module_name`,`name`) -) AUTO_INCREMENT=33 DEFAULT CHARSET=utf8; +) AUTO_INCREMENT=35 DEFAULT CHARSET=utf8; SET character_set_client = @saved_cs_client; INSERT INTO {vars} VALUES (1,'gallery','active_site_theme','wind'); INSERT INTO {vars} VALUES (2,'gallery','active_admin_theme','admin_wind'); @@ -376,14 +376,15 @@ INSERT INTO {vars} VALUES (5,'gallery','resize_size','640'); INSERT INTO {vars} VALUES (6,'gallery','default_locale','en_US'); INSERT INTO {vars} VALUES (7,'gallery','image_quality','75'); INSERT INTO {vars} VALUES (8,'gallery','image_sharpen','15'); -INSERT INTO {vars} VALUES (9,'gallery','identity_provider','user'); -INSERT INTO {vars} VALUES (22,'gallery','time_format','H:i:s'); -INSERT INTO {vars} VALUES (23,'gallery','show_credits','1'); -INSERT INTO {vars} VALUES (24,'gallery','credits','Powered by Gallery %version'); -INSERT INTO {vars} VALUES (11,'gallery','blocks_dashboard_sidebar','a:4:{i:2;a:2:{i:0;s:7:\"gallery\";i:1;s:11:\"block_adder\";}i:3;a:2:{i:0;s:7:\"gallery\";i:1;s:5:\"stats\";}i:4;a:2:{i:0;s:7:\"gallery\";i:1;s:13:\"platform_info\";}i:5;a:2:{i:0;s:7:\"gallery\";i:1;s:12:\"project_news\";}}'); -INSERT INTO {vars} VALUES (21,'gallery','date_time_format','Y-M-d H:i:s'); -INSERT INTO {vars} VALUES (20,'gallery','date_format','Y-M-d'); -INSERT INTO {vars} VALUES (16,'gallery','blocks_dashboard_center','a:4:{i:6;a:2:{i:0;s:7:\"gallery\";i:1;s:7:\"welcome\";}i:7;a:2:{i:0;s:7:\"gallery\";i:1;s:12:\"photo_stream\";}i:8;a:2:{i:0;s:7:\"gallery\";i:1;s:11:\"log_entries\";}i:9;a:2:{i:0;s:7:\"comment\";i:1;s:15:\"recent_comments\";}}'); -INSERT INTO {vars} VALUES (19,'gallery','choose_default_tookit','1'); -INSERT INTO {vars} VALUES (26,'comment','spam_caught','0'); -INSERT INTO {vars} VALUES (28,'gallery','blocks_site.sidebar','a:3:{i:596516649;a:2:{i:0;s:4:\"info\";i:1;s:8:\"metadata\";}i:1189641421;a:2:{i:0;s:3:\"rss\";i:1;s:9:\"rss_feeds\";}i:1025202362;a:2:{i:0;s:3:\"tag\";i:1;s:3:\"tag\";}}'); +INSERT INTO {vars} VALUES (10,'gallery','blocks_dashboard_sidebar','a:4:{i:2;a:2:{i:0;s:7:\"gallery\";i:1;s:11:\"block_adder\";}i:3;a:2:{i:0;s:7:\"gallery\";i:1;s:5:\"stats\";}i:4;a:2:{i:0;s:7:\"gallery\";i:1;s:13:\"platform_info\";}i:5;a:2:{i:0;s:7:\"gallery\";i:1;s:12:\"project_news\";}}'); +INSERT INTO {vars} VALUES (22,'gallery','show_credits','1'); +INSERT INTO {vars} VALUES (23,'gallery','credits','Powered by Gallery %version'); +INSERT INTO {vars} VALUES (20,'gallery','date_time_format','Y-M-d H:i:s'); +INSERT INTO {vars} VALUES (21,'gallery','time_format','H:i:s'); +INSERT INTO {vars} VALUES (15,'gallery','blocks_dashboard_center','a:4:{i:6;a:2:{i:0;s:7:\"gallery\";i:1;s:7:\"welcome\";}i:7;a:2:{i:0;s:7:\"gallery\";i:1;s:12:\"photo_stream\";}i:8;a:2:{i:0;s:7:\"gallery\";i:1;s:11:\"log_entries\";}i:9;a:2:{i:0;s:7:\"comment\";i:1;s:15:\"recent_comments\";}}'); +INSERT INTO {vars} VALUES (18,'gallery','choose_default_tookit','1'); +INSERT INTO {vars} VALUES (19,'gallery','date_format','Y-M-d'); +INSERT INTO {vars} VALUES (26,'user','mininum_password_length','5'); +INSERT INTO {vars} VALUES (25,'gallery','identity_provider','user'); +INSERT INTO {vars} VALUES (28,'comment','spam_caught','0'); +INSERT INTO {vars} VALUES (30,'gallery','blocks_site.sidebar','a:3:{s:32:\"6e901fd82a43b0e07ebbd7123b5ee349\";a:2:{i:0;s:4:\"info\";i:1;s:8:\"metadata\";}s:32:\"c07f62cf746316b111a61681fe49ad39\";a:2:{i:0;s:3:\"rss\";i:1;s:9:\"rss_feeds\";}s:32:\"2eef3fd349091e4e1cee9e27072bff39\";a:2:{i:0;s:3:\"tag\";i:1;s:3:\"tag\";}}'); diff --git a/modules/gallery/helpers/block_manager.php b/modules/gallery/helpers/block_manager.php index 0e78661a..980d1db5 100644 --- a/modules/gallery/helpers/block_manager.php +++ b/modules/gallery/helpers/block_manager.php @@ -28,11 +28,12 @@ class block_manager_Core { static function add($location, $module_name, $block_id) { $blocks = self::get_active($location); - $blocks[rand()] = array($module_name, $block_id); + $blocks[md5("$module_name:$block_id")] = array($module_name, $block_id); + self::set_active($location, $blocks); } - static function activate_sidebar_blocks($module_name) { + static function activate_blocks($module_name) { $block_class = "{$module_name}_block"; if (method_exists($block_class, "get_site_list")) { $blocks = call_user_func(array($block_class, "get_site_list")); @@ -48,12 +49,21 @@ class block_manager_Core { self::set_active($location, $blocks); } - static function deactivate_sidebar_blocks($module_name) { + static function deactivate_blocks($module_name) { $block_class = "{$module_name}_block"; if (method_exists($block_class, "get_site_list")) { $blocks = call_user_func(array($block_class, "get_site_list")); foreach (array_keys($blocks) as $block_id) { - self::remove("site.sidebar", $module_name, $block_id); + self::remove("site.sidebar", md5("$module_name:$block_id")); + } + } + + if (method_exists($block_class, "get_admin_list")) { + $blocks = call_user_func(array($block_class, "get_admin_list")); + foreach (array("dashboard_sidebar", "dashboard_center") as $location) { + foreach (array_keys($blocks) as $block_id) { + self::remove($location, md5("$module_name:$block_id")); + } } } } diff --git a/modules/gallery/helpers/gallery_installer.php b/modules/gallery/helpers/gallery_installer.php index 2eb02546..26cd14f5 100644 --- a/modules/gallery/helpers/gallery_installer.php +++ b/modules/gallery/helpers/gallery_installer.php @@ -268,7 +268,7 @@ class gallery_installer { module::set_var("gallery", "show_credits", 1); // @todo this string needs to be picked up by l10n_scanner module::set_var("gallery", "credits", "Powered by Gallery %version"); - module::set_version("gallery", 16); + module::set_version("gallery", 17); } static function upgrade($version) { @@ -398,6 +398,18 @@ class gallery_installer { module::set_var("gallery", "identity_provider", "user"); module::set_version("gallery", $version = 16); } + + if ($version == 16) { + foreach (array("dashboard_sidebar", "dashboard_center", "site.sidebar") as $location) { + $blocks = block_manager::get_active($location); + $new_blocks = array(); + foreach ($blocks as $block) { + $new_blocks[md5("{$block[0]}:{$block[1]}")] = $block; + } + block_manager::set_active($location, $new_blocks); + } + module::set_version("gallery", $version = 17); + } } static function uninstall() { diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php index da334370..e6c196ce 100644 --- a/modules/gallery/helpers/module.php +++ b/modules/gallery/helpers/module.php @@ -211,7 +211,7 @@ class module_Core { graphics::activate_rules($module_name); - block_manager::activate_sidebar_blocks($module_name); + block_manager::activate_blocks($module_name); log::success( "module", t("Activated module %module_name", array("module_name" => $module_name))); @@ -238,7 +238,7 @@ class module_Core { graphics::deactivate_rules($module_name); - block_manager::deactivate_sidebar_blocks($module_name); + block_manager::deactivate_blocks($module_name); log::success( "module", t("Deactivated module %module_name", array("module_name" => $module_name))); diff --git a/modules/gallery/module.info b/modules/gallery/module.info index e21431a7..2a35b809 100644 --- a/modules/gallery/module.info +++ b/modules/gallery/module.info @@ -1,3 +1,3 @@ name = "Gallery 3" description = "Gallery core application" -version = 16 +version = 17 -- cgit v1.2.3