Skip to content
Browse files

MDL-26352 ignore invalid course_meta entries during upgrade

This fixes upgrade problems when course_meta points to deleted course or somebody hacked the table contents manually.
  • Loading branch information...
1 parent d911c72 commit d21feffdd76ebc96c1987fbfc57450538e7016b8 @skodak skodak committed Feb 12, 2011
Showing with 5 additions and 3 deletions.
  1. +5 −3 lib/db/upgrade.php
View
8 lib/db/upgrade.php
@@ -4091,10 +4091,12 @@ function xmldb_main_upgrade($oldversion) {
}
if ($oldversion < 2010061900.10) {
- // migrate existing setup of meta courses
+ // migrate existing setup of meta courses, ignore records referencing invalid courses
$sql = "INSERT INTO {enrol} (enrol, status, courseid, sortorder, customint1)
- SELECT 'meta', 0, parent_course, 5, child_course
- FROM {course_meta}";
+ SELECT 'meta', 0, cm.parent_course, 5, cm.child_course
+ FROM {course_meta} cm
+ JOIN {course} p ON p.id = cm.parent_course
+ JOIN {course} c ON c.id = cm.child_course";
$DB->execute($sql);
upgrade_main_savepoint(true, 2010061900.10);

0 comments on commit d21feff

Please sign in to comment.
Something went wrong with that request. Please try again.