MDL-20852: Condition system - problems if you delete a module that another one had...
authorSam Marshall <s.marshall@open.ac.uk>
Mon, 16 Nov 2009 15:14:47 +0000 (15:14 +0000)
committerSam Marshall <s.marshall@open.ac.uk>
Mon, 16 Nov 2009 15:14:47 +0000 (15:14 +0000)
lib/conditionlib.php

index b9af5f2..3d7fb58 100644 (file)
@@ -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).' ';