mirror of
https://github.com/silverstripe/silverstripe-comments
synced 2024-10-22 11:05:49 +02:00
FEATURE: added migration script for existing page comments
This commit is contained in:
parent
f539a97d07
commit
30f291fc88
@ -25,12 +25,41 @@ class Comment extends DataObject {
|
|||||||
|
|
||||||
static $many_many = array();
|
static $many_many = array();
|
||||||
|
|
||||||
static $defaults = array();
|
static $defaults = array(
|
||||||
|
"Moderated" => true
|
||||||
|
);
|
||||||
|
|
||||||
static $casting = array(
|
static $casting = array(
|
||||||
"RSSTitle" => "Varchar",
|
"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
|
* Return a link to this comment
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user