Skip to content

Commit

Permalink
MDL-61615 Questions: Only move question categories if there is any
Browse files Browse the repository at this point in the history
  • Loading branch information
rezaies committed Mar 20, 2018
1 parent bd94e16 commit ae9f5a0
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lib/questionlib.php
Expand Up @@ -464,13 +464,16 @@ function question_delete_course_category($category, $newcategory, $feedback=true
if (!$newcontext = context_coursecat::instance($newcategory->id)) {
return false;
}
$topcategory = question_get_top_category($context->id, true);
$newtopcategory = question_get_top_category($newcontext->id, true);

question_move_category_to_context($topcategory->id, $context->id, $newcontext->id);
$DB->set_field('question_categories', 'parent', $newtopcategory->id, array('parent' => $topcategory->id));
// Now delete the top category.
$DB->delete_records('question_categories', array('id' => $topcategory->id));
// Only move question categories if there is any question category at all!
if ($topcategory = question_get_top_category($context->id)) {
$newtopcategory = question_get_top_category($newcontext->id, true);

question_move_category_to_context($topcategory->id, $context->id, $newcontext->id);
$DB->set_field('question_categories', 'parent', $newtopcategory->id, array('parent' => $topcategory->id));
// Now delete the top category.
$DB->delete_records('question_categories', array('id' => $topcategory->id));
}

if ($feedback) {
$a = new stdClass();
Expand Down

0 comments on commit ae9f5a0

Please sign in to comment.