diff options
author | Bharat Mediratta <bharat@menalto.com> | 2010-08-06 10:41:38 -0700 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2010-08-06 10:41:38 -0700 |
commit | d3a161ca1bb388593e03bd5c57c60ea249b3fe8d (patch) | |
tree | ce7a9d08fd438d05109da1c1652702b622557894 /modules | |
parent | 0fe44fe3809041edb64b69496bcee070578483d5 (diff) |
Add a "weight" column to the module table. This allows us to specify
module ordering, which is currently being done in the moduleorder
contrib module.
By default, the weight will be the same as the id of the row which
means that new modules will get added at the end of the list. This is
covered in the upgrade case as well.
The one gotcha is that we need to make sure that we don't try to sort
by the weight column if the gallery module version is < 32, which is
something we haven't done before.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/gallery/helpers/gallery_installer.php | 13 | ||||
-rw-r--r-- | modules/gallery/helpers/module.php | 20 | ||||
-rw-r--r-- | modules/gallery/module.info | 2 |
3 files changed, 31 insertions, 4 deletions
diff --git a/modules/gallery/helpers/gallery_installer.php b/modules/gallery/helpers/gallery_installer.php index f5589618..8fc0cf96 100644 --- a/modules/gallery/helpers/gallery_installer.php +++ b/modules/gallery/helpers/gallery_installer.php @@ -144,8 +144,10 @@ class gallery_installer { `active` BOOLEAN default 0, `name` varchar(64) default NULL, `version` int(9) default NULL, + `weight` int(9) default NULL, PRIMARY KEY (`id`), - UNIQUE KEY(`name`)) + UNIQUE KEY(`name`), + KEY (`weight`)) DEFAULT CHARSET=utf8;"); $db->query("CREATE TABLE {outgoing_translations} ( @@ -296,7 +298,7 @@ class gallery_installer { module::set_var("gallery", "simultaneous_upload_limit", 5); module::set_var("gallery", "admin_area_timeout", 90 * 60); module::set_var("gallery", "maintenance_mode", 0); - module::set_version("gallery", 31); + module::set_version("gallery", 32); } static function upgrade($version) { @@ -561,6 +563,13 @@ class gallery_installer { module::set_var("gallery", "maintenance_mode", 0); module::set_version("gallery", $version = 31); } + + if ($version == 31) { + db::update("modules") + ->set("weight", "=", "id") + ->execute(); + module::set_version("gallery", $version = 32); + } } static function uninstall() { diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php index 5134c7b3..ca6651f1 100644 --- a/modules/gallery/helpers/module.php +++ b/modules/gallery/helpers/module.php @@ -166,6 +166,16 @@ class module_Core { } else { module::set_version($module_name, 1); } + + // Set the weight of the new module, which controls the order in which the modules are + // loaded. By default, new modules are installed at the end of the priority list. Since the + // id field is monotonically increasing, the easiest way to guarantee that is to set the weight + // the same as the id. We don't know that until we save it for the first time + $module = ORM::factory("module")->where("name", "=", $module_name)->find(); + if ($module->loaded()) { + $module->weight = $module->id; + $module->save(); + } module::load_modules(); // Now the module is installed but inactive, so don't leave it in the active path @@ -314,7 +324,15 @@ class module_Core { self::$modules = array(); self::$active = array(); $kohana_modules = array(); - foreach (ORM::factory("module")->find_all() as $module) { + + // In version 32 we introduced a weight column so we can specify the module order + // If we try to use that blindly, we'll break earlier versions before they can even + // run the upgrader. + $modules = module::get_version("gallery") < 32 ? + ORM::factory("module")->find_all(): + ORM::factory("module")->order_by("weight")->find_all(); + + foreach ($modules as $module) { self::$modules[$module->name] = $module; if (!$module->active) { continue; diff --git a/modules/gallery/module.info b/modules/gallery/module.info index 7d28a7c1..59db07de 100644 --- a/modules/gallery/module.info +++ b/modules/gallery/module.info @@ -1,3 +1,3 @@ name = "Gallery 3" description = "Gallery core application" -version = 31 +version = 32 |