From c0a059260faf90ab1ffff9f6ff2e533f43138c1e Mon Sep 17 00:00:00 2001 From: Adrian Greeve Date: Mon, 8 Oct 2012 09:03:49 +0800 Subject: [PATCH] MDL-35265 - blog - Update code for removing orphaned blog association data. --- lib/db/upgrade.php | 16 ++++++++++++++++ version.php | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index eb260de9a99..0f7f4fd545c 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -1244,5 +1244,21 @@ function xmldb_main_upgrade($oldversion) { upgrade_main_savepoint(true, 2012092600.00); } + if ($oldversion < 2012100500.01) { + // 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, 2012100500.01); + } + return true; } diff --git a/version.php b/version.php index d56d10fbf5f..e2f731f3191 100644 --- a/version.php +++ b/version.php @@ -30,7 +30,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2012100500.00; // YYYYMMDD = weekly release date of this DEV branch +$version = 2012100500.01; // YYYYMMDD = weekly release date of this DEV branch // RR = release increments - 00 in DEV branches // .XX = incremental changes