mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
FEATURE: added delete all link to page comments. Patch via #4427. Thanks walec51
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/branches/2.4@95418 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
a578804987
commit
19670e7b27
@ -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']);
|
||||
|
@ -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 {
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
@ -53,6 +53,9 @@
|
||||
<p id="NoComments"><% _t('NOCOMMENTSYET','No one has commented on this page yet.') %></p>
|
||||
<% end_if %>
|
||||
</div>
|
||||
<% if DeleteAllLink %>
|
||||
<p id="DeleteComments"><a href="$DeleteAllLink">Delete all comments on this page</a></p>
|
||||
<% end_if %>
|
||||
<p id="CommentsRSSFeed">
|
||||
<a class="commentrss" href="$CommentRssLink"><% _t('RSSFEEDCOMMENTS', 'RSS feed for comments on this page') %></a> |
|
||||
<a href="PageComment/rss" class="commentrss" title="<% _t('RSSVIEWALLCOMMENTS', 'View all Comments') %>"><% _t('RSSFEEDALLCOMMENTS', 'RSS feed for all comments') %></a>
|
||||
|
31
tests/PageCommentsTest.php
Normal file
31
tests/PageCommentsTest.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
class PageCommentsTest extends FunctionalTest {
|
||||
|
||||
static $fixture_file = 'cms/tests/PageCommentsTest.yml';
|
||||
|
||||
|
||||
function testDeleteAllCommentsOnPage() {
|
||||
|
||||
|
||||
$second = $this->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);
|
||||
}
|
||||
}
|
||||
?>
|
50
tests/PageCommentsTest.yml
Normal file
50
tests/PageCommentsTest.yml
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user