Posts made by Tim Hunt

Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Howard, we did spend a considerable amount of time worry about the upgrade. There was one particularly messy issues that consumed a lot of our attention, particularly at the expense of other stuff: Question_Engine_Changes_in_Moodle_1.9#Random_Questions_Selecting_from_Subcategories.

So, all that infrastructure is there for doing checks before, during and after upgrade. (Look in admin/report/questions in both Moodle 1.8 and 1.9; admin/environment.php and ...xml; and question/upgrade.php.

It is, in fact, perfectly possible to compute which courses, the questions in a particular category are used in. You just need to join on quiz_question_instances.

Actually, it will be easier if you don't think about single question categories. Question categories form trees in the question bank. Let $categorylist be a comma-separated list of all the category ids under a single top-level category, then:

SELECT DISTINCT quiz.course
FROM mdl_quiz quiz
JOIN mdl_quiz_question_instances qqi ON qqi.quiz = quiz.id
JOIN mdl_question q ON q.id = qqi.question
JOIN mdl_qc ON qc.id = q.category
WHERE qc.id IN ($categorylist);

Will get you a list of the courses with quizzes that use any of the questions in that category. (I typed that off the top of my head, you may need to debug.) If there is only one course in that list, you can safely do

UPDATE mdl_question_categories SET contextid = {get_context_instance(CONTEXT_COURSE, $courseid)} WHERE id IN ($categorylist);

If you want to help, I suggest you code that up. I think the natural place would be to add it to admin/report/question.php - as an after-the-face fix-up in Moodle 1.9, and with a similar query in Moodle 1.8 that offers to un-publish categories that don't need to be published.

Also, if you feel so strongly about this, and think this whole situation is so bad, why haven't you edited the 1.9 release notes to save other admins to make the warnings about this issue clearer?

Finally, the admin/report/question.php report would be a natural place to give admins a one-click button to create the Question sharer role (if one does not already exist).

Oh, and then if the query above shows that there genuinely are questions shared between courses, you could find the people with question editing rights in those courses, and give admins a simple way to assign those people the Question sharer role.

I don't have time to implement any of these suggestions, I'm afraid, but I will try to make the time to be helpful to anyone trying to do them. Although I am about to go on holiday for a few weeks - however, I will probably still be online intermittently.
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
But Moodle is a PHP application, so if you want to customise Moodle, you are going to have to learn a bit of PHP.

Actually, there is a more fundamental than that, Moodle is a database-driven web application running on a server. ActionScript (that's Flash, right?) use used to build stand-alone applications. The way the two things work, and hence the way the code needs to be structured, is completely different.

I really think your quickest way to learn would be to take some working Moodle code, and start tinkering with it until you understand how it works, and what effect your changes will have when you change it.