diff options
author | Tim Almdal <tnalmdal@shaw.ca> | 2009-11-12 09:29:17 -0800 |
---|---|---|
committer | Tim Almdal <tnalmdal@shaw.ca> | 2009-11-12 13:13:34 -0800 |
commit | 79f700ef9f79926d5e806bd48e5a6f99b6ecc5bb (patch) | |
tree | 53c7100e69da76a31e9ac8519f5ea5bc55488921 | |
parent | 3d8d2f71be68ce5bb267a54a36d6ab495c22e6b1 (diff) |
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.
-rw-r--r-- | installer/install.sql | 31 | ||||
-rw-r--r-- | modules/gallery/helpers/block_manager.php | 18 | ||||
-rw-r--r-- | modules/gallery/helpers/gallery_installer.php | 14 | ||||
-rw-r--r-- | modules/gallery/helpers/module.php | 4 | ||||
-rw-r--r-- | modules/gallery/module.info | 2 |
5 files changed, 46 insertions, 23 deletions
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 <a href=\"%url\">Gallery %version</a>'); -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 <a href=\"%url\">Gallery %version</a>'); +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 <a href=\"%url\">Gallery %version</a>"); - 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 |