From 70a557db24a84d59b997082528013822b72af3c9 Mon Sep 17 00:00:00 2001 From: ak4t0sh Date: Wed, 2 Nov 2016 23:15:45 +0100 Subject: [PATCH] MDL-55720 course: fix potential undefined variable and cleaning This commit replace $e usage by $returnfromfunc. Indeed $returnfromfunc always exists in the scope and take $e value in case of moodle_exception. This commit also remove useless $modcontext affectation. --- course/modlib.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/course/modlib.php b/course/modlib.php index 1eaa8f9d107..18e5caadbe9 100644 --- a/course/modlib.php +++ b/course/modlib.php @@ -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 {