From: Sam Marshall Date: Mon, 16 Nov 2009 15:14:47 +0000 (+0000) Subject: MDL-20852: Condition system - problems if you delete a module that another one had... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=bfeaa89501422fcc9c43681ed66038c41da4cc0f;p=moodle.git MDL-20852: Condition system - problems if you delete a module that another one had a condition on --- diff --git a/lib/conditionlib.php b/lib/conditionlib.php index b9af5f21a6..3d7fb58577 100644 --- a/lib/conditionlib.php +++ b/lib/conditionlib.php @@ -298,6 +298,9 @@ WHERE if (!$modinfo) { $modinfo = get_fast_modinfo($course); } + if (empty($modinfo->cms[$cmid])) { + continue; + } $information .= get_string( 'requires_completion_'.$expectedcompletion, 'condition', $modinfo->cms[$cmid]->name).' '; @@ -384,6 +387,19 @@ WHERE $completion = new completion_info($course); foreach ($this->cm->conditionscompletion as $cmid=>$expectedcompletion) { + // If this depends on a deleted module, handle that situation + // gracefully. + if (!$modinfo) { + $modinfo = get_fast_modinfo($course); + } + if (empty($modinfo->cms[$cmid])) { + global $PAGE; + if (isset($PAGE) && strpos($PAGE->pagetype, 'course-view-')===0) { + debugging("Warning: activity {$this->cm->id} '{$this->cm->name}' has condition on deleted activity $cmid (to get rid of this message, edit the named activity)"); + } + continue; + } + // The completion system caches its own data $completiondata = $completion->get_data((object)array('id'=>$cmid), $grabthelot, $userid, $modinfo); @@ -407,9 +423,6 @@ WHERE } if (!$thisisok) { $available = false; - if (!$modinfo) { - $modinfo = get_fast_modinfo($course); - } $information .= get_string( 'requires_completion_'.$expectedcompletion, 'condition',$modinfo->cms[$cmid]->name).' ';