Skip to content

Commit a7fbe59

Browse files
Fix migration
1 parent af2b5cb commit a7fbe59

File tree

1 file changed

+25
-20
lines changed

1 file changed

+25
-20
lines changed

db/upgrade.php

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,9 @@ function xmldb_block_evasys_sync_upgrade ($oldversion) {
396396
$veransts[] = $record->idnumber;
397397
}
398398

399+
if (!$veransts) {
400+
continue;
401+
}
399402
// Check if any veranstaltungen already exist in the database.
400403
list($insql, $inparams) = $DB->get_in_or_equal($veransts);
401404
$evalgroups = $DB->get_fieldset_sql(
@@ -410,26 +413,28 @@ function xmldb_block_evasys_sync_upgrade ($oldversion) {
410413
} else {
411414
// If true, merge all evaluation groups with veranstaltungen of this course into the one.
412415
$evalid = array_shift($evalgroups);
413-
list($insql, $inparams) = $DB->get_in_or_equal($evalgroups, SQL_PARAMS_NAMED);
414-
$inparams['evalid'] = $evalid;
415-
$DB->execute(
416-
'UPDATE {' . dbtables::EVAL_COURSES . '} ' .
417-
'SET evalid = :evalid ' .
418-
'WHERE evalid ' . $insql,
419-
$inparams
420-
);
421-
$DB->execute(
422-
'UPDATE {' . dbtables::EVAL_VERANSTS . '} ' .
423-
'SET evalid = :evalid ' .
424-
'WHERE evalid ' . $insql,
425-
$inparams
426-
);
427-
unset($inparams['evalid']);
428-
$DB->execute(
429-
'DELETE FROM {' . dbtables::EVAL . '} ' .
430-
'WHERE id ' . $insql,
431-
$inparams
432-
);
416+
if ($evalgroups) {
417+
list($insql, $inparams) = $DB->get_in_or_equal($evalgroups, SQL_PARAMS_NAMED);
418+
$inparams['evalid'] = $evalid;
419+
$DB->execute(
420+
'UPDATE {' . dbtables::EVAL_COURSES . '} ' .
421+
'SET evalid = :evalid ' .
422+
'WHERE evalid ' . $insql,
423+
$inparams
424+
);
425+
$DB->execute(
426+
'UPDATE {' . dbtables::EVAL_VERANSTS . '} ' .
427+
'SET evalid = :evalid ' .
428+
'WHERE evalid ' . $insql,
429+
$inparams
430+
);
431+
unset($inparams['evalid']);
432+
$DB->execute(
433+
'DELETE FROM {' . dbtables::EVAL . '} ' .
434+
'WHERE id ' . $insql,
435+
$inparams
436+
);
437+
}
433438
}
434439
$DB->insert_record(dbtables::EVAL_COURSES, [
435440
'evalid' => $evalid,

0 commit comments

Comments
 (0)