summaryrefslogtreecommitdiff
path: root/modules/gallery/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gallery/helpers')
-rw-r--r--modules/gallery/helpers/gallery_installer.php13
-rw-r--r--modules/gallery/helpers/module.php20
2 files changed, 30 insertions, 3 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;