Skip to content

Commit

Permalink
Following the fixes for MDL-14750 and MDL-10899, do a database upgrad…
Browse files Browse the repository at this point in the history
…e that fixes any bogus values in the parent or category columns of multianswer questions' subquestions.
  • Loading branch information
tjhunt committed May 9, 2008
1 parent 9ade28e commit e2134c5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
27 changes: 27 additions & 0 deletions question/type/multianswer/db/upgrade.php
Expand Up @@ -32,7 +32,34 @@ function xmldb_qtype_multianswer_upgrade($oldversion=0) {
/// $result = result of "/lib/ddllib.php" function calls
/// }

if ($result && $oldversion < 2008050800) {
question_multianswer_fix_subquestion_parents_and_categories();
}

return $result;
}

/**
* Due to MDL-14750, subquestions of multianswer questions restored from backup will
* have the wrong parent, and due to MDL-10899 subquestions of multianswer questions
* that have been moved between categories will be in the wrong category, This code fixes these up.
*/
function question_multianswer_fix_subquestion_parents_and_categories() {
global $CFG;

$result = true;
$rs = get_recordset_sql('SELECT q.id, q.category, qma.sequence FROM ' . $CFG->prefix .
'question q JOIN ' . $CFG->prefix . 'question_multianswer qma ON q.id = qma.question');
if ($rs) {
while ($q = rs_fetch_next_record($rs)) {
$result = $result && execute_sql('UPDATE ' . $CFG->prefix . 'question' .
' SET parent = ' . $q->id . ', category = ' . $q->category .
' WHERE id IN (' . $q->sequence . ') AND parent <> 0');
}
rs_close($rs);
} else {
$result = false;
}
return $result;
}
?>
4 changes: 2 additions & 2 deletions question/type/multianswer/version.php
@@ -1,6 +1,6 @@
<?PHP // $Id$

$plugin->version = 2006032200;
$plugin->requires = 2007101000;
$plugin->version = 2008050800;
$plugin->requires = 2007101509;

?>

0 comments on commit e2134c5

Please sign in to comment.