From 8fd603a26ad99ba0cbc56a52963ddb5d6ea71b62 Mon Sep 17 00:00:00 2001 From: Dongsheng Cai Date: Mon, 3 May 2010 07:49:59 +0000 Subject: [PATCH] "MDL-19118, fixed data module comment migration" --- mod/data/db/upgrade.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/mod/data/db/upgrade.php b/mod/data/db/upgrade.php index c1648c36ba5..b69b3f3f10d 100644 --- a/mod/data/db/upgrade.php +++ b/mod/data/db/upgrade.php @@ -181,7 +181,6 @@ function xmldb_data_upgrade($oldversion) { } if ($result && $oldversion < 2009111701) { - require_once($CFG->dirroot . '/comment/lib.php'); upgrade_set_timeout(60*20); /// Define table data_comments to be dropped @@ -191,14 +190,14 @@ function xmldb_data_upgrade($oldversion) { if ($dbman->table_exists($table)) { $sql = 'SELECT d.id AS dataid, d.course AS courseid, + c.userid, r.id AS itemid, c.id AS commentid, c.content AS commentcontent, c.format AS format, - c.created AS timemodified + c.created AS timecreated FROM {data_comments} c, {data_records} r, {data} d WHERE c.recordid=r.id AND r.dataid=d.id ORDER BY dataid, courseid'; - /// move data comments to comments table $lastdataid = null; $lastcourseid = null; @@ -214,15 +213,16 @@ function xmldb_data_upgrade($oldversion) { $lastcourseid = $res->courseid; } $cmt = new stdclass; - $cmt->pluginname = 'data'; - $cmt->context = $modcontext; - $cmt->courseid = $res->courseid; - $cmt->area = 'database_entry'; - $cmt->itemid = $res->itemid; - $comment = new comment($cmt); + $cmt->contextid = $modcontext->id; + $cmt->commentarea = 'database_entry'; + $cmt->itemid = $res->itemid; + $cmt->content = $res->commentcontent; + $cmt->format = $res->format; + $cmt->userid = $res->userid; + $cmt->timecreated = $res->timecreated; // comments class will throw an exception if error occurs - $cmt = $comment->add($res->commentcontent, $res->format); - if (!empty($cmt)) { + $cmt_id = $DB->insert_record('comments', $cmt); + if (!empty($cmt_id)) { $DB->delete_records('data_comments', array('id'=>$res->commentid)); } }