Playing with Technology

Any sufficiently advanced technology is indistinguishable from magic. ~Arthur C. Clarke

Fun with Moodle, Not!

Breathe. Take a long breath. That’s what you do when you’re faced with a Moodle issue that has your phone ringing off the hook with confused faculty on the other end. Let’s spell out what the issue was and how it got fixed.

A few weeks ago a faculty member noticed that there were extra people displaying in the Participants list of all their courses. Seems like not a big deal maybe the automatic course creation scripts had a minor issue and when rosters got updated things would be alright. Well, it turns out that the role assignments for the course were correct and didn’t match what was displaying in the Participants block. OK, so turn of the Participants block and stop displaying students and faculty on the course descriptions. Search Moodle.org for the issue and find nothing relevant. Make some posts on Moodle.org and the CLAMP Moodle Exchange and wait.

The Moodle.org thread got no action. Maybe the title wasn’t clear enough or maybe nobody had any more clue how to fix it than we did. The CLAMP folks make some suggestions to check for system-wide role assignments and a couple other things. Check everything that the CLAMP people suggest and everything looks fine. Bob Puffer suggests some queries to run against the database. We run:


SELECT a.*, u.username FROM mdl_role_assignments a
JOIN mdl_context con on con.id = a.contextid
JOIN mdl_user u on u.id = a.userid
WHERE con.contextlevel = 50
AND con.instanceid = yourcourseid

and it doesn’t return any of these phantom users. It just returns the people that should be enrolled.

We notice that the 63 (yeah 63 phantom users) all have some connection to the Music courses in the system. Some Music faculty are displaying as Faculty participants in all classes and some students enrolled in Music courses are displaying as student participants in all courses. Our systems admin looks at the code that generates the code to display participants, students in the gradebook, and users in the course description. He notes that all the code does something with contexts but we don’t know what that could have to do with anything.

Our system admin tries deleting all the Music course from our test clone of the production box. We check a few courses and the Participant lists and gradebook look fine. We don’t think to check anything else and decide to contact the chair of the Music department to ask if any Music faculty are actually using Moodle. Only one Music faculty member has put any content into a course and so we help her backup and export everything and then proceed to delete all the Music courses.

Since there isn’t an easy way to remove a bunch of courses at once, or because we don’t really know all the ins and outs of Moodle, we move all the Music courses into their own category and then delete the category. Do this deletes all the courses and the Participants lists look fine. The phone continues to ring but now faculty are saying that they see all courses in the system in their My Moodle list. What? We check a few user and sure enough all courses now show for all users in their My Moodle page. We scratch our heads (we should have tried logging in as one of the phantoms on the test).

At this point a member of the Math department drops by my office and says she is getting a strange error when she tries to update a quiz that had previously been working. I login and take a look and sure enough I get the same error “context () in print_context_name!”. This is the first error we have ever gotten while working on this issue (going on a month). So now we head over to Moodle.org with the error in hand and do a search and what do you know http://moodle.org/mod/forum/discuss.php?d=93656 pops up. Hey, this talks about paths (something else the system admin was mumbling about) and the quiz issue. They suggest trying to create a fixcontexts.php that contains:


require_once('config.php');
require_login();
build_context_path(true, true);
echo 'Done';

We try this on the test box and things look to be normal. We check the Participant lists, gradebook, and login as some of the phantom users. Everything looks fine and so we run the fix on the production server and everything is as it should be. The phone is silent.

I’m not sure how anyone is supposed to have realized that all the strange issues we were seeing were related to contexts. In hindsight it is easy to see that having contexts messed up could affect all the areas where we were seeing problems, but we never got any error messages and wouldn’t have if we hadn’t moved the Music courses to their own category (creating a new context) and then deleted them, which caused the context of the Math professors quiz to get screwed up.

TL;DR
If you see strange issues and no errors then rebuild the contexts!