From 30f291fc88ccd3038a49ad67d660fea91c5aa7ab Mon Sep 17 00:00:00 2001 From: Will Rossiter Date: Sat, 11 Dec 2010 17:26:14 +1300 Subject: [PATCH] FEATURE: added migration script for existing page comments --- code/dataobjects/Comment.php | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/code/dataobjects/Comment.php b/code/dataobjects/Comment.php index 99a4255..5b3ec25 100755 --- a/code/dataobjects/Comment.php +++ b/code/dataobjects/Comment.php @@ -25,12 +25,41 @@ class Comment extends DataObject { static $many_many = array(); - static $defaults = array(); + static $defaults = array( + "Moderated" => true + ); static $casting = array( "RSSTitle" => "Varchar", ); + /** + * Migrates the old {@link PageComment} objects to {@link Comment} + */ + public function requireDefaultRecords() { + parent::requireDefaultRecords(); + + if(DB::getConn()->hasTable('PageComment')) { + $comments = DB::query("SELECT * FROM \"PageComment\""); + + if($comments) { + while($pageComment = $comments->numRecord()) { + // create a new comment from the older page comment + $comment = new Comment($pageComment); + + // set the variables which have changed + $comment->BaseClass = 'SiteTree'; + $comment->URL = (isset($pageComment['CommenterURL'])) ? $pageComment['CommenterURL'] : ""; + + $comment->write(); + } + } + + DB::alterationMessage("Migrated PageComment to Comment""changed"); + DB::getConn()->dontRequireTable('PageComment'); + } + } + /** * Return a link to this comment *