diff --git a/modules/moduleorder/controllers/admin_moduleorder.php b/modules/moduleorder/controllers/admin_moduleorder.php index 92cf2a54..c99d068c 100644 --- a/modules/moduleorder/controllers/admin_moduleorder.php +++ b/modules/moduleorder/controllers/admin_moduleorder.php @@ -54,44 +54,19 @@ class Admin_Moduleorder_Controller extends Admin_Controller { } ksort($modulelist); - //Get the highest used index - $highestindex = 0; - foreach ($modulelist as $row) { - $currentry = explode(":", $row); - if ($currentry[1] > $highestindex) { - $highestindex = $currentry[1]; - } - } - - $highestindex++; //Have a safety margin just in case - //To avoid conflicts on the index we now rewrite all indices of all modules - foreach ($modulelist as $row) { - $highestindex++; - $currentry = explode("=", $row); - $currentry = explode(":", $currentry[1]); - db::build() - ->update("modules") - ->set("id", $highestindex) - ->where("name", "=", $currentry[0]) - ->execute(); - } - //Now we are ready to write the correct id values - $highestindex = 0; + $current_weight = 0; foreach ($modulelist as $row) { - $highestindex++; + $current_weight++; $currentry = explode("=", $row); $currentry = explode(":", $currentry[1]); db::build() ->update("modules") - ->set("id", $highestindex) + ->set("weight", $current_weight) ->where("name", "=", $currentry[0]) ->execute(); } - //As last step we optimize the table - db::query("OPTIMIZE TABLE `modules`") - ->execute(); message::success(t("Your settings have been saved.")); url::redirect("admin/moduleorder"); print $this->_get_view(); diff --git a/modules/moduleorder/helpers/module_manager.php b/modules/moduleorder/helpers/module_manager.php index 632cf7b7..b26d5f76 100644 --- a/modules/moduleorder/helpers/module_manager.php +++ b/modules/moduleorder/helpers/module_manager.php @@ -24,7 +24,7 @@ class module_manager_Core { private static function _get_modules() { $modules = array(); - foreach (db::build()->select("*")->from("modules")->order_by("id")->execute() as $row) { + foreach (db::build()->select("*")->from("modules")->order_by("weight")->execute() as $row) { $modules["{$row->name}:$row->id"] = $row->name; } return $modules;