Merge branch 'MDL-55720' of https://github.com/ak4t0sh/moodle
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Tue, 13 Dec 2016 10:41:35 +0000 (11:41 +0100)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Tue, 13 Dec 2016 10:41:35 +0000 (11:41 +0100)
course/modlib.php

index 24385b8..d45966d 100644 (file)
@@ -125,12 +125,11 @@ function add_moduleinfo($moduleinfo, $course, $mform = null) {
     if (!$returnfromfunc or !is_number($returnfromfunc)) {
         // Undo everything we can. This is not necessary for databases which
         // support transactions, but improves consistency for other databases.
-        $modcontext = context_module::instance($moduleinfo->coursemodule);
         context_helper::delete_instance(CONTEXT_MODULE, $moduleinfo->coursemodule);
         $DB->delete_records('course_modules', array('id'=>$moduleinfo->coursemodule));
 
-        if ($e instanceof moodle_exception) {
-            throw $e;
+        if ($returnfromfunc instanceof moodle_exception) {
+            throw $returnfromfunc;
         } else if (!is_number($returnfromfunc)) {
             print_error('invalidfunction', '', course_get_url($course, $moduleinfo->section));
         } else {