diff --git a/code/sitefeatures/PageComment.php b/code/sitefeatures/PageComment.php index c80aa4c4..e0981c3e 100755 --- a/code/sitefeatures/PageComment.php +++ b/code/sitefeatures/PageComment.php @@ -176,6 +176,27 @@ class PageComment_Controller extends Controller { $rss->outputToBrowser(); } + /** + * Deletes all comments on the page referenced by the url param pageid + */ + function deleteallcomments() { + if(Permission::check('CMS_ACCESS_CMSMain')) { + $pageId = $_REQUEST['pageid']; + if(preg_match('/^\d+$/', $pageId)) { + $comments = DataObject::get("PageComment", "ParentID = $pageId"); + if($comments) foreach($comments as $c) { + $c->delete(); + } + } + } + + if(Director::is_ajax()) { + echo ""; + } else { + Director::redirectBack(); + } + } + function deletecomment() { if(Permission::check('CMS_ACCESS_CMSMain')) { $comment = DataObject::get_by_id("PageComment", $this->urlParams['ID']); diff --git a/code/sitefeatures/PageCommentInterface.php b/code/sitefeatures/PageCommentInterface.php index 9b5772fb..b4ed69e0 100755 --- a/code/sitefeatures/PageCommentInterface.php +++ b/code/sitefeatures/PageCommentInterface.php @@ -228,6 +228,16 @@ class PageCommentInterface extends RequestHandler { return Director::absoluteBaseURL() . "PageComment/rss?pageid=" . $this->page->ID; } + /** + * A link to PageComment_Controller.deleteallcomments() which deletes all + * comments on a page referenced by the url param pageid + */ + function DeleteAllLink() { + if(Permission::check('CMS_ACCESS_CMSMain')) { + return Director::absoluteBaseURL() . "PageComment/deleteallcomments?pageid=" . $this->page->ID; + } + } + } /** @@ -337,4 +347,4 @@ class PageCommentInterface_Controller extends ContentController { } } -?> \ No newline at end of file +?> diff --git a/templates/PageCommentInterface.ss b/templates/PageCommentInterface.ss index 90a91e70..b0f9509a 100755 --- a/templates/PageCommentInterface.ss +++ b/templates/PageCommentInterface.ss @@ -53,6 +53,9 @@

<% _t('NOCOMMENTSYET','No one has commented on this page yet.') %>

<% end_if %> + <% if DeleteAllLink %> +

Delete all comments on this page

+ <% end_if %>

<% _t('RSSFEEDCOMMENTS', 'RSS feed for comments on this page') %> | <% _t('RSSFEEDALLCOMMENTS', 'RSS feed for all comments') %> diff --git a/tests/PageCommentsTest.php b/tests/PageCommentsTest.php new file mode 100644 index 00000000..b4c08976 --- /dev/null +++ b/tests/PageCommentsTest.php @@ -0,0 +1,31 @@ +objFromFixture('Page', 'second'); + $this->autoFollowRedirection = false; + $this->logInAs('admin'); + Director::test('second-page', null, $this->session()); + Director::test('PageComment/deleteallcomments?pageid='.$second->ID, + null, $this->session()); + Director::test('second-page', null, $this->session()); + + $secondComments = DataObject::get('PageComment', 'ParentID = '.$second->ID); + $this->assertNull($secondComments); + + $first = $this->objFromFixture('Page', 'first'); + $firstComments = DataObject::get('PageComment', 'ParentID = '.$first->ID); + $this->assertNotNull($firstComments); + + $third = $this->objFromFixture('Page', 'third'); + $thirdComments = DataObject::get('PageComment', 'ParentID = '.$third->ID); + $this->assertEquals($thirdComments->Count(), 3); + } +} +?> diff --git a/tests/PageCommentsTest.yml b/tests/PageCommentsTest.yml new file mode 100644 index 00000000..b70d5c0f --- /dev/null +++ b/tests/PageCommentsTest.yml @@ -0,0 +1,50 @@ +Member: + admin: + FirstName: admin + +Group: + admin: + Title: Admin + Members: =>Member.admin + +Permission: + admin: + Code: ADMIN + Group: =>Group.admin + +Page: + first: + Title: First page + URLSegment: first-page + second: + Title: Second page + URLSegment: second-page + third: + Title: Third page + URLSegment:third-page + +PageComment: + firstComA: + ParentID: =>Page.first + Name: FA + Comment: textFA + secondComA: + ParentID: =>Page.second + Name: SA + Comment: textSA + secondComB: + ParentID: =>Page.second + Name: SB + Comment: textSB + thirdComA: + ParentID: =>Page.third + Name: TA + Comment: textTA + thirdComB: + ParentID: =>Page.third + Name: TB + Comment: textTB + thirdComC: + ParentID: =>Page.third + Name: TC + Comment: textTC