Permalink
Browse files

question bank MDL-24312 problem when deleting a course with orphaned …

…categories.

When there was a question category whose parent had somehow been deleted from the question bank, while the child category was still there, then that gave an error because a DB query was still referring to the question_categories.courese coloumn, that was changed to contextid in moodle 1.9.

Backported to from HEAD. Fix thanks to Mahmoud Kassaei.
  • Loading branch information...
timhunt committed Nov 8, 2010
1 parent 15a18ac commit 54c489cb739d25f64f23268cfd61814c45419404
Showing with 3 additions and 3 deletions.
  1. +3 −3 lib/questionlib.php
View
@@ -517,7 +517,7 @@ function question_delete_course($course, $feedback=true) {
//Cache some strings
$strcatdeleted = get_string('unusedcategorydeleted', 'quiz');
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
- $categoriescourse = get_records('question_categories', 'contextid', $coursecontext->id, 'parent', 'id, parent, name');
+ $categoriescourse = get_records('question_categories', 'contextid', $coursecontext->id, 'parent', 'id, parent, name, contextid');
if ($categoriescourse) {
@@ -676,7 +676,7 @@ function question_delete_activity($cm, $feedback=true) {
//Cache some strings
$strcatdeleted = get_string('unusedcategorydeleted', 'quiz');
$modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
- if ($categoriesmods = get_records('question_categories', 'contextid', $modcontext->id, 'parent', 'id, parent, name')){
+ if ($categoriesmods = get_records('question_categories', 'contextid', $modcontext->id, 'parent', 'id, parent, name, contextid')){
//Sort categories following their tree (parent-child) relationships
//this will make the feedback more readable
$categoriesmods = sort_categories_by_tree($categoriesmods);
@@ -1796,7 +1796,7 @@ function sort_categories_by_tree(&$categories, $id = 0, $level = 1) {
if ($level == 1) {
foreach ($keys as $key) {
//If not processed and it's a good candidate to start (because its parent doesn't exist in the course)
- if (!isset($categories[$key]->processed) && !record_exists('question_categories', 'course', $categories[$key]->course, 'id', $categories[$key]->parent)) {
+ if (!isset($categories[$key]->processed) && !record_exists('question_categories', 'contextid', $categories[$key]->contextid, 'id', $categories[$key]->parent)) {
$children[$key] = $categories[$key];
$categories[$key]->processed = true;
$children = $children + sort_categories_by_tree($categories, $children[$key]->id, $level+1);

0 comments on commit 54c489c

Please sign in to comment.