From e02eea80e9e6a6cafe38bc24650ee6bffd152694 Mon Sep 17 00:00:00 2001 From: moodler Date: Sat, 27 Sep 2003 14:06:09 +0000 Subject: [PATCH] Changes from Mad Alex to allow better error reporting when adding or updating modules. See: http://moodle.org/mod/forum/discuss.php?d=2738 If a moderr.html file exists in the module, it is shown. If a string is returned, it's shown. Otherwise it works as before. --- course/mod.php | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/course/mod.php b/course/mod.php index 86a0da95288..6565cbd26f4 100644 --- a/course/mod.php +++ b/course/mod.php @@ -40,11 +40,21 @@ $addinstancefunction = $mod->modulename."_add_instance"; $updateinstancefunction = $mod->modulename."_update_instance"; $deleteinstancefunction = $mod->modulename."_delete_instance"; + $moderr = "$CFG->dirroot/mod/$mod->modulename/moderr.html"; switch ($mod->mode) { case "update": - if (! $updateinstancefunction($mod)) { - error("Could not update the $mod->modulename"); + $return = $updateinstancefunction($mod); + if (!$return) { + if (file_exists($moderr)) { + $form = $mod; + include_once($moderr); + die; + } + error("Could not update the $mod->modulename", "view.php?id=$mod->course"); + } + if (is_string($return)) { + error($return, "view.php?id=$mod->course"); } add_to_log($mod->course, "course", "update mod", "../mod/$mod->modulename/view.php?id=$mod->coursemodule", @@ -52,9 +62,19 @@ break; case "add": - if (! $mod->instance = $addinstancefunction($mod)) { - error("Could not add a new instance of $mod->modulename"); + $return = $addinstancefunction($mod); + if (!$return) { + if (file_exists($moderr)) { + $form = $mod; + include_once($moderr); + die; + } + error("Could not add a new instance of $mod->modulename", "view.php?id=$mod->course"); } + if (is_string($return)) { + error($return, "view.php?id=$mod->course"); + } + $mod->instance = $return; // course_modules and course_sections each contain a reference // to each other, so we have to update one of them twice.