diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index e617e1b4908..91263db71eb 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -969,5 +969,21 @@ function xmldb_main_upgrade($oldversion) { upgrade_main_savepoint(true, 2012062502.03); } + if ($oldversion < 2012062502.07) { + // Find all orphaned blog associations that might exist. + $sql = "SELECT ba.id + FROM {blog_association} ba + LEFT JOIN {post} p + ON p.id = ba.blogid + WHERE p.id IS NULL"; + $orphanedrecordids = $DB->get_records_sql($sql); + // Now delete these associations. + foreach ($orphanedrecordids as $orphanedrecord) { + $DB->delete_records('blog_association', array('id' => $orphanedrecord->id)); + } + + upgrade_main_savepoint(true, 2012062502.07); + } + return true; } diff --git a/version.php b/version.php index 4fc7f149e90..e835adf048a 100644 --- a/version.php +++ b/version.php @@ -30,7 +30,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2012062502.06; // YYYYMMDD = weekly release date of this DEV branch +$version = 2012062502.07; // YYYYMMDD = weekly release date of this DEV branch // RR = release increments - 00 in DEV branches // .XX = incremental changes