From ce3af93a507ccf2d11afa26e5b16fa9cfd73e5cc Mon Sep 17 00:00:00 2001 From: Russell Michell Date: Tue, 18 Dec 2012 08:53:16 +1300 Subject: [PATCH 1/3] BUGFIX: Fixed calls to Comment::get() to be compatible with PostGres MINOR: Modified docs with basic composer info, typos, grammar etc ENHANCEMENT: Hid the existing 'BaseClass' textfield making a hidden field. There should be no need to manually change this. --- code/CommentAdmin.php | 4 ++-- code/dataobjects/Comment.php | 24 +++++++++++++++++++++ docs/en/Installing.md | 42 ++++++++++++++++++++++++------------ 3 files changed, 54 insertions(+), 16 deletions(-) diff --git a/code/CommentAdmin.php b/code/CommentAdmin.php index 5a31b94..755c0b5 100644 --- a/code/CommentAdmin.php +++ b/code/CommentAdmin.php @@ -52,14 +52,14 @@ class CommentAdmin extends LeftAndMain { $needs = new GridField( 'Comments', _t('CommentsAdmin.NeedsModeration', 'Needs Moderation'), - Comment::get()->where('Moderated = 0'), + Comment::get()->filter('Moderated',0), $commentsConfig ); $moderated = new GridField( 'CommentsModerated', _t('CommentsAdmin.CommentsModerated'), - Comment::get()->where('Moderated = 1'), + Comment::get()->filter('Moderated',1), $commentsConfig ); diff --git a/code/dataobjects/Comment.php b/code/dataobjects/Comment.php index c5dfe1f..b3e6ea5 100755 --- a/code/dataobjects/Comment.php +++ b/code/dataobjects/Comment.php @@ -144,6 +144,15 @@ class Comment extends DataObject { return ($parent->Title) ? $parent->Title : $parent->ClassName . " #" . $parent->ID; } + + /** + * Comment-parent classnames obviousely vary, return the parent classname + * + * @return string + */ + public function getParentClassName() { + return $this->BaseClass; + } /** * @todo needs to compare to the new {@link Commenting} configuration API @@ -302,4 +311,19 @@ class Comment extends DataObject { return $title; } + + /* + * Modify the default fields shown to the user + */ + public function getCMSFields() { + $fields = parent::getCMSFields(); + $parentClass = $this->getParentClassName(); + $parentIDField = new DropDownField('ParentID', 'Parent', $parentClass::get()->map()); + $authorIDField = new HiddenField('AuthorID'); + $baseClassField = new HiddenField('BaseClass'); + $fields->replaceField('ParentID', $parentIDField); + $fields->replaceField('AuthorID', $authorIDField); + $fields->replaceField('BaseClass', $baseClassField); + return $fields; + } } diff --git a/docs/en/Installing.md b/docs/en/Installing.md index 6da2ffd..f1631eb 100644 --- a/docs/en/Installing.md +++ b/docs/en/Installing.md @@ -1,32 +1,46 @@ # Installation -To begin the installation first download the module from online. You can find what version -you require for your SilverStripe installation on the silverstripe.org website. +## Composer -After you have finished downloading the file, extract the downloaded file to your sites root +Edit your project-wide composer.json file as follows; in the "require" block add: + + "silverstripe/comments": "*" + +Then in the root of your project run: + + #> composer update silverstripe/comments + +## Web + +To begin the installation first download the module online. You can find the version +you require for your SilverStripe installation on the [silverstripe.org](http://www.silverstripe.org) website. + +After you have finished downloading the file, extract the downloaded file to your site's root folder and ensure the name of the module is `comments`. +## All + Run a database rebuild by visiting *http://yoursite.com/dev/build*. This will add the required database columns and tables for the module to function. -If you previously had SilverStripe 2.4 installed then you will also need to run the migration script -provided. More information on this is in the next section +If you previously had SilverStripe version 2.4 installed then you'll also need to run the migration script +provided. More information on this is provided in the next section. -## Enabling Commenting +## Enabling Commenting Out of the box the module adds commenting support to all pages on your site. This functionality can be turned on and off on a per page basis in the CMS under the `Behaviour` tab for a given page. Once the `Allow Comments` -checkbox is ticked republish the page and view the webpage. +checkbox is ticked, republish and view the webpage. Ensure that your template file (usually themes/yourtheme/templates/Layout/Page.ss) has the `$CommentsForm` variable where you want comments to appear. -To enable commenting on other objects (such as your own subclasses of DataObject) add the following +To enable commenting on other objects (such as your own subclasses of `DataObject`) add the following to your `mysite/_config.php` file. // Adds commenting to the class SiteTree (all Pages) Commenting::add('SiteTree'); - + You can also pass configuration options to the add function to customize commenting on that object. Again in your `mysite/_config.php` file replace the previous line with the following @@ -36,14 +50,14 @@ in your `mysite/_config.php` file replace the previous line with the following 'require_moderation' => true, 'require_login' => true )); - + For more configuration options see [Configuration](Configuration.md). ## Upgrading -### Migrating from 2.* SilverStripe installations +### Migrating from version 2.* SilverStripe installations -This module replaces the built in commenting system available in versions up to SilverStripe 2.4. To migrate from -that you need to run `dev/build` after installing the module. +This module replaces the built-in commenting system available in versions up to SilverStripe 2.4. To migrate from +that you'll need to run `dev/build` after installing the module. -You can do this via sake (`sake dev/build`) or via a web browser by visiting http://yoursite.com/dev/build \ No newline at end of file +You can do this via sake (`sake dev/build`) or via a web browser by visiting `http://yoursite.com/dev/build` \ No newline at end of file From c89a8d02ce73ad27b347e686b0236a4f55ebae11 Mon Sep 17 00:00:00 2001 From: Russell Michell Date: Wed, 19 Dec 2012 15:07:18 +1300 Subject: [PATCH 2/3] BUGFIX: Modded getParentClassName() for when $this->BaseClass is not set --- code/dataobjects/Comment.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/code/dataobjects/Comment.php b/code/dataobjects/Comment.php index b3e6ea5..15f3d58 100755 --- a/code/dataobjects/Comment.php +++ b/code/dataobjects/Comment.php @@ -151,6 +151,10 @@ class Comment extends DataObject { * @return string */ public function getParentClassName() { + $default = 'SiteTree'; + if(!$this->BaseClass) { + return $default; + } return $this->BaseClass; } From c38ca52ab728177286e3101576e75379ac953730 Mon Sep 17 00:00:00 2001 From: Russell Michell Date: Wed, 16 Jan 2013 09:51:34 +1300 Subject: [PATCH 3/3] MINOR: Removed ability to select parent and replaced with hidden-field --- code/dataobjects/Comment.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/dataobjects/Comment.php b/code/dataobjects/Comment.php index 15f3d58..14e3aee 100755 --- a/code/dataobjects/Comment.php +++ b/code/dataobjects/Comment.php @@ -321,8 +321,8 @@ class Comment extends DataObject { */ public function getCMSFields() { $fields = parent::getCMSFields(); - $parentClass = $this->getParentClassName(); - $parentIDField = new DropDownField('ParentID', 'Parent', $parentClass::get()->map()); + $parent = $this->getParent()->ID; + $parentIDField = new HiddenField('ParentID', 'Parent', $parent); $authorIDField = new HiddenField('AuthorID'); $baseClassField = new HiddenField('BaseClass'); $fields->replaceField('ParentID', $parentIDField);