From 442636301ff566571f00b08cfb05dd85a4874343 Mon Sep 17 00:00:00 2001 From: Dongsheng Cai Date: Wed, 28 Apr 2010 06:08:31 +0000 Subject: [PATCH] MDL-19839, rename file area for comments block, and migrating old comments in that area, thanks Eloy's migrating sql --- blocks/comments/block_comments.php | 6 +++--- lib/db/upgrade.php | 21 +++++++++++++++++++++ version.php | 2 +- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/blocks/comments/block_comments.php b/blocks/comments/block_comments.php index 16dfdfb0505..964ec88fddd 100644 --- a/blocks/comments/block_comments.php +++ b/blocks/comments/block_comments.php @@ -43,9 +43,9 @@ class block_comments extends block_base { $args = new stdclass; $args->context = $PAGE->context; $args->course = $course; - $args->area = 'block_comments'; - $args->itemid = $this->instance->id; - //XXX: this is a hack to adjust commenting UI in block_comments + $args->area = 'page_comments'; + $args->itemid = 0; + // set 'env' to tell moodle tweak ui for this block $args->env = 'block_comments'; $args->linktext = get_string('showcomments'); $comment = new comment($args); diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 862a0f71d2d..6c87f0e5a1c 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -3644,6 +3644,27 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL"); upgrade_main_savepoint($result, 2010042800); } + if ($result && $oldversion < 2010042801) { + // migrating old comments block content + $DB->execute(" +UPDATE {comments} SET contextid = ( + SELECT parentcontextid FROM {block_instances} + WHERE id = {comments}.itemid AND blockname = 'comments' + ), + commentarea = 'page_comments', + itemid = 0 +WHERE commentarea = 'block_comments' +AND itemid != 0 +AND EXISTS (SELECT 'x' + FROM {block_instances} + WHERE id = {comments}.itemid + AND blockname = 'comments')"); + + // remove all orphaned record + $DB->delete_records('comments', array('commentarea'=>'block_comments')); + upgrade_main_savepoint($result, 2010042801); + } + return $result; } diff --git a/version.php b/version.php index b9a922c853b..b21399c58f8 100644 --- a/version.php +++ b/version.php @@ -6,7 +6,7 @@ // This is compared against the values stored in the database to determine // whether upgrades should be performed (see lib/db/*.php) - $version = 2010042800; // YYYYMMDD = date of the last version bump + $version = 2010042801; // YYYYMMDD = date of the last version bump // XX = daily increments $release = '2.0 dev (Build: 20100428)'; // Human-friendly version name