From d9580ed600148cfdb1444423306314c3734b0d95 Mon Sep 17 00:00:00 2001 From: Will Rossiter Date: Sat, 11 Dec 2010 18:01:19 +1300 Subject: [PATCH] FEATURE: added delete comment functionality. MINOR: added documentation --- code/controllers/CommentingController.php | 29 +++++++++++++++++++++++ code/dataobjects/Comment.php | 4 +++- docs/en/Configuration.md | 1 + docs/en/Installing.md | 19 +++++++++++++++ docs/en/Upgrading.md | 0 javascript/CommentsInterface.js | 15 ++++++++++-- 6 files changed, 65 insertions(+), 3 deletions(-) delete mode 100644 docs/en/Upgrading.md diff --git a/code/controllers/CommentingController.php b/code/controllers/CommentingController.php index cbb1161..0839c52 100644 --- a/code/controllers/CommentingController.php +++ b/code/controllers/CommentingController.php @@ -6,6 +6,12 @@ class CommentingController extends Controller { + static $allowed_actions = array( + 'delete', + 'CommentsForm', + 'doPostCommentz' + ); + private $baseClass = ""; private $ownerRecord = ""; private $ownerController = ""; @@ -42,6 +48,29 @@ class CommentingController extends Controller { } /** + * Performs the delete task for deleting {@link Comment}. + * + * /delete/$ID deletes the $ID comment + */ + public function delete() { + $id = isset($this->urlParams['ID']) ? $this->urlParams['ID'] : false; + + if($id) { + $comment = DataObject::get_by_id('Comment', $id); + + if($comment && $comment->canDelete()) { + $comment->delete(); + + return ($this->isAjax()) ? true : $this->redirectBack(); + } + } + + return ($this->isAjax()) ? false : $this->httpError('404'); + } + + /** + * Post a comment form + * * @return Form */ function CommentsForm() { diff --git a/code/dataobjects/Comment.php b/code/dataobjects/Comment.php index 5b3ec25..66d5df1 100755 --- a/code/dataobjects/Comment.php +++ b/code/dataobjects/Comment.php @@ -55,7 +55,7 @@ class Comment extends DataObject { } } - DB::alterationMessage("Migrated PageComment to Comment""changed"); + DB::alterationMessage("Migrated PageComment to Comment","changed"); DB::getConn()->dontRequireTable('PageComment'); } } @@ -100,6 +100,8 @@ class Comment extends DataObject { * @return DataObject */ public function getParent() { + if(!$this->BaseClass) $this->BaseClass = "SiteTree"; + return DataObject::get_by_id($this->BaseClass, $this->ParentID); } diff --git a/docs/en/Configuration.md b/docs/en/Configuration.md index e69de29..902e54f 100644 --- a/docs/en/Configuration.md +++ b/docs/en/Configuration.md @@ -0,0 +1 @@ +## Configuration \ No newline at end of file diff --git a/docs/en/Installing.md b/docs/en/Installing.md index e69de29..02650d8 100644 --- a/docs/en/Installing.md +++ b/docs/en/Installing.md @@ -0,0 +1,19 @@ +# 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. + +After you have finished downloading the file, extract the downloaded file to your sites root +folder and ensure the name of the module is `comments`. + +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 + +## Migrating old comments + +This module replaces the built in commenting system available in versions up to SilverStripe 2.4. To migrate from +that you need to run the `InitialCommentMigration` task. You can do this via sake or via a web browser by visiting +*http://yoursite.com/dev/tasks/InitialCommentMigration* \ No newline at end of file diff --git a/docs/en/Upgrading.md b/docs/en/Upgrading.md deleted file mode 100644 index e69de29..0000000 diff --git a/javascript/CommentsInterface.js b/javascript/CommentsInterface.js index fe1561b..a0dcdff 100755 --- a/javascript/CommentsInterface.js +++ b/javascript/CommentsInterface.js @@ -5,11 +5,22 @@ (function($) { $(document).ready(function () { - - // @todo finish + /** + * Please note this functionality has not been finished + * this file is not loaded on your site. It is simply here + * to provide a starting point for someone to take it over + * + * @todo finish + */ return false; + + + + + + $('.comments-holder-container form').submit(function (e) { if($('.comment-holder form [name=Name]').val() && $('.comment-holder form [name=Comment]').val()) {