mirror of
https://github.com/moodle/moodle.git
synced 2025-08-11 20:06:46 +02:00
MDL-79332 Question stats: make loading robust to bad data
We were experiencing problems caused by old stats analysis in our database, computed when there was a bug, causing fatal errors when they were displayed. Therefore, this code needs to be robust to that.
This commit is contained in:
parent
b4c6ed3650
commit
a047d2f8b4
1 changed files with 20 additions and 5 deletions
|
@ -215,17 +215,21 @@ class all_calculated_for_qubaid_condition {
|
||||||
foreach ($questionstatrecs as $fromdb) {
|
foreach ($questionstatrecs as $fromdb) {
|
||||||
if (is_null($fromdb->variant)) {
|
if (is_null($fromdb->variant)) {
|
||||||
if ($fromdb->slot) {
|
if ($fromdb->slot) {
|
||||||
|
if (!isset($this->questionstats[$fromdb->slot])) {
|
||||||
|
debugging('Statistics found for slot ' . $fromdb->slot .
|
||||||
|
' in stats ' . json_encode($qubaids->from_where_params()) .
|
||||||
|
' which is not an analysable question.', DEBUG_DEVELOPER);
|
||||||
|
}
|
||||||
$this->questionstats[$fromdb->slot]->populate_from_record($fromdb);
|
$this->questionstats[$fromdb->slot]->populate_from_record($fromdb);
|
||||||
// Array created in constructor and populated from question.
|
|
||||||
} else {
|
} else {
|
||||||
$this->subquestionstats[$fromdb->questionid] = new calculated_for_subquestion();
|
$this->subquestionstats[$fromdb->questionid] = new calculated_for_subquestion();
|
||||||
$this->subquestionstats[$fromdb->questionid]->populate_from_record($fromdb);
|
$this->subquestionstats[$fromdb->questionid]->populate_from_record($fromdb);
|
||||||
if (isset($this->subquestions[$fromdb->questionid])) {
|
if (isset($this->subquestions[$fromdb->questionid])) {
|
||||||
$this->subquestionstats[$fromdb->questionid]->question =
|
$this->subquestionstats[$fromdb->questionid]->question =
|
||||||
$this->subquestions[$fromdb->questionid];
|
$this->subquestions[$fromdb->questionid];
|
||||||
} else {
|
} else {
|
||||||
$this->subquestionstats[$fromdb->questionid]->question =
|
$this->subquestionstats[$fromdb->questionid]->question = question_bank::get_qtype(
|
||||||
question_bank::get_qtype('missingtype', false)->make_deleted_instance($fromdb->questionid, 1);
|
'missingtype', false)->make_deleted_instance($fromdb->questionid, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -234,13 +238,24 @@ class all_calculated_for_qubaid_condition {
|
||||||
foreach ($questionstatrecs as $fromdb) {
|
foreach ($questionstatrecs as $fromdb) {
|
||||||
if (!is_null($fromdb->variant)) {
|
if (!is_null($fromdb->variant)) {
|
||||||
if ($fromdb->slot) {
|
if ($fromdb->slot) {
|
||||||
|
if (!isset($this->questionstats[$fromdb->slot])) {
|
||||||
|
debugging('Statistics found for slot ' . $fromdb->slot .
|
||||||
|
' in stats ' . json_encode($qubaids->from_where_params()) .
|
||||||
|
' which is not an analysable question.', DEBUG_DEVELOPER);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
$newcalcinstance = new calculated();
|
$newcalcinstance = new calculated();
|
||||||
$this->questionstats[$fromdb->slot]->variantstats[$fromdb->variant] = $newcalcinstance;
|
$this->questionstats[$fromdb->slot]->variantstats[$fromdb->variant] = $newcalcinstance;
|
||||||
$newcalcinstance->question = $this->questionstats[$fromdb->slot]->question;
|
$newcalcinstance->question = $this->questionstats[$fromdb->slot]->question;
|
||||||
} else {
|
} else {
|
||||||
$newcalcinstance = new calculated_for_subquestion();
|
$newcalcinstance = new calculated_for_subquestion();
|
||||||
$this->subquestionstats[$fromdb->questionid]->variantstats[$fromdb->variant] = $newcalcinstance;
|
$this->subquestionstats[$fromdb->questionid]->variantstats[$fromdb->variant] = $newcalcinstance;
|
||||||
$newcalcinstance->question = $this->subquestions[$fromdb->questionid];
|
if (isset($this->subquestions[$fromdb->questionid])) {
|
||||||
|
$newcalcinstance->question = $this->subquestions[$fromdb->questionid];
|
||||||
|
} else {
|
||||||
|
$newcalcinstance->question = question_bank::get_qtype(
|
||||||
|
'missingtype', false)->make_deleted_instance($fromdb->questionid, 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$newcalcinstance->populate_from_record($fromdb);
|
$newcalcinstance->populate_from_record($fromdb);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue