]> git.mjollnir.org Git - moodle.git/commitdiff
Changes from Mad Alex to allow better error reporting when
authormoodler <moodler>
Sat, 27 Sep 2003 14:06:09 +0000 (14:06 +0000)
committermoodler <moodler>
Sat, 27 Sep 2003 14:06:09 +0000 (14:06 +0000)
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

index 86a0da95288f004e7f78b88870c524024cf898b8..6565cbd26f41c3b2122fda1701e907d86435b7fc 100644 (file)
         $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", 
                 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.