MDL-36091 added debugging() calls in blocks of code marked as "should never happen"
authorAndrew Davis <andrew@moodle.com>
Fri, 26 Oct 2012 02:43:39 +0000 (10:43 +0800)
committerDan Poltawski <dan@moodle.com>
Mon, 11 Feb 2013 05:24:52 +0000 (13:24 +0800)
admin/tool/uploaduser/index.php
enrol/manual/locallib.php
grade/edit/outcome/index.php
lib/accesslib.php
lib/datalib.php

index f249f1d..afbc370 100644 (file)
@@ -535,6 +535,7 @@ if ($formdata = $mform2->is_cancelled()) {
                     }
                     if (!property_exists($user, $column) or !property_exists($existinguser, $column)) {
                         // this should never happen
+                        debugging("Could not find $column on the user objects", DEBUG_DEVELOPER);
                         continue;
                     }
                     if ($updatetype == UU_UPDATE_MISSING) {
index a969354..16ad4a2 100644 (file)
@@ -406,6 +406,7 @@ function enrol_manual_migrate_plugin_enrolments($enrol) {
 
         if (!$minstance) {
             // This should never happen unless adding of default instance fails unexpectedly.
+            debugging('Failed to find manual enrolment instance', DEBUG_DEVELOPER);
             continue;
         }
 
index c1d9b5b..658d5ce 100644 (file)
@@ -132,6 +132,7 @@ if ($courseid and $outcomes = grade_outcome::fetch_all_local($courseid)) {
         $scale = $outcome->load_scale();
         if (empty($scale->id)) {   // hopefully never happens
             $line[] = $scale->get_name();
+            debugging("Found a scale with no ID ({$scale->get_name()}) while outputting course outcomes", DEBUG_DEVELOPER);
         } else {
             if (empty($scale->courseid)) {
                 $caneditthisscale = $caneditsystemscales;
@@ -181,6 +182,7 @@ if ($outcomes = grade_outcome::fetch_all_global()) {
         $scale = $outcome->load_scale();
         if (empty($scale->id)) {   // hopefully never happens
             $line[] = $scale->get_name();
+            debugging("Found a scale with no ID ({$scale->get_name()}) while outputting global outcomes", DEBUG_DEVELOPER);
         } else {
             if (empty($scale->courseid)) {
                 $caneditthisscale = $caneditsystemscales;
index c6d7f2c..5a59ea6 100644 (file)
@@ -393,6 +393,7 @@ function has_capability($capability, context $context, $user = null, $doanything
     if (!isset($USER->id)) {
         // should never happen
         $USER->id = 0;
+        debugging('Capability check being performed on a user with no ID.', DEBUG_DEVELOPER);
     }
 
     // make sure there is a real user specified
@@ -2062,6 +2063,7 @@ function can_access_course(stdClass $course, $user = null, $withcapability = '',
     if (!isset($USER->id)) {
         // should never happen
         $USER->id = 0;
+        debugging('Course access check being performed on a user with no ID.', DEBUG_DEVELOPER);
     }
 
     // make sure there is a user specified
index a1e5ab9..f54eae6 100644 (file)
@@ -57,7 +57,9 @@ function get_admin() {
     static $mainadmin = null;
     static $prevadmins = null;
 
-    if (empty($CFG->siteadmins)) {  // Should not happen on an ordinary site.
+    if (empty($CFG->siteadmins)) {
+        // Should not happen on an ordinary site.
+        // It does however happen during unit tests.
         return false;
     }