NOMDL workshop more referential integrity checks

As reported by Trudy Koedooder at http://moodle.org/mod/forum/discuss.php?d=161322
there can be some orphaned grade records without the referenced
assessment. It threw upgrade error. Such grades are now just ignored
during the upgrade.
This commit is contained in:
David Mudrak 2010-11-10 16:02:07 +00:00
parent f4a2817ac5
commit cdff9eead3
4 changed files with 16 additions and 0 deletions

View File

@ -73,6 +73,10 @@ function workshopform_accumulative_upgrade_legacy() {
$rs = $DB->get_recordset_sql($sql, $params);
$newassessmentids = workshop_upgrade_assessment_id_mappings();
foreach ($rs as $old) {
if (!isset($newassessmentids[$old->assessmentid])) {
// orphaned grade - the assessment was removed but the grade remained
continue;
}
if (!isset($newelementids[$old->workshopid]) or !isset($newelementids[$old->workshopid][$old->elementno])) {
// orphaned grade - the assessment form element has been removed after the grade was recorded
continue;

View File

@ -70,6 +70,10 @@ function workshopform_comments_upgrade_legacy() {
$rs = $DB->get_recordset_sql($sql, $params);
$newassessmentids = workshop_upgrade_assessment_id_mappings();
foreach ($rs as $old) {
if (!isset($newassessmentids[$old->assessmentid])) {
// orphaned comment - the assessment was removed but the grade remained
continue;
}
if (!isset($newelementids[$old->workshopid]) or !isset($newelementids[$old->workshopid][$old->elementno])) {
// orphaned comment - the assessment form element has been removed after the grade was recorded
continue;

View File

@ -93,6 +93,10 @@ function workshopform_numerrors_upgrade_legacy() {
$rs = $DB->get_recordset_sql($sql, $params);
$newassessmentids = workshop_upgrade_assessment_id_mappings();
foreach ($rs as $old) {
if (!isset($newassessmentids[$old->assessmentid])) {
// orphaned grade - the assessment was removed but the grade remained
continue;
}
if (!isset($newelementids[$old->workshopid]) or !isset($newelementids[$old->workshopid][$old->elementno])) {
// orphaned grade - the assessment form element has been removed after the grade was recorded
continue;

View File

@ -104,6 +104,10 @@ function workshopform_rubric_upgrade_legacy_criterion() {
$newassessmentids = workshop_upgrade_assessment_id_mappings();
$newdimensionids = $DB->get_records('workshopform_rubric_levels', array(), '', 'id,dimensionid');
foreach ($rs as $old) {
if (!isset($newassessmentids[$old->assessmentid])) {
// orphaned grade - the assessment was removed but the grade remained
continue;
}
if (!isset($newelementids[$old->workshopid]) or !isset($newelementids[$old->workshopid][$old->elementno])) {
// orphaned grade - the assessment form element has been removed after the grade was recorded
continue;