diff --git a/src/Admin/CommentsGridFieldAction.php b/src/Admin/CommentsGridFieldAction.php deleted file mode 100644 index cd54d12..0000000 --- a/src/Admin/CommentsGridFieldAction.php +++ /dev/null @@ -1,138 +0,0 @@ - 'col-buttons']; - } - - /** - * {@inheritdoc} - */ - public function getColumnMetadata($gridField, $columnName) - { - if ($columnName === 'Actions') { - return ['title' => '']; - } - } - - /** - * {@inheritdoc} - */ - public function getColumnsHandled($gridField) - { - return ['Actions']; - } - - /** - * {@inheritdoc} - */ - public function getColumnContent($gridField, $record, $columnName) - { - if (!$record->canEdit()) { - return; - } - - $field = ''; - - if (!$record->IsSpam || !$record->Moderated) { - $field .= GridField_FormAction::create( - $gridField, - 'CustomAction' . $record->ID . 'Spam', - _t(__CLASS__ . '.SPAM', 'Spam'), - 'spam', - ['RecordID' => $record->ID] - ) - ->addExtraClass('btn btn-secondary grid-field__icon-action') - ->Field(); - } - - if ($record->IsSpam || !$record->Moderated) { - $field .= GridField_FormAction::create( - $gridField, - 'CustomAction' . $record->ID . 'Approve', - _t(__CLASS__ . '.APPROVE', 'Approve'), - 'approve', - ['RecordID' => $record->ID] - ) - ->addExtraClass('btn btn-secondary grid-field__icon-action') - ->Field(); - } - - return $field; - } - - /** - * {@inheritdoc} - */ - public function getActions($gridField) - { - return ['spam', 'approve']; - } - - /** - * {@inheritdoc} - */ - public function handleAction(GridField $gridField, $actionName, $arguments, $data) - { - if ($actionName === 'spam') { - /** @var Comment $comment */ - $comment = Comment::get()->byID($arguments['RecordID']); - $comment->markSpam(); - - // output a success message to the user - Controller::curr()->getResponse()->setStatusCode( - 200, - _t(__CLASS__ . '.COMMENTMARKEDSPAM', 'Comment marked as spam.') - ); - } - - if ($actionName === 'approve') { - /** @var Comment $comment */ - $comment = Comment::get()->byID($arguments['RecordID']); - $comment->markApproved(); - - // output a success message to the user - Controller::curr()->getResponse()->setStatusCode( - 200, - _t(__CLASS__ . '.COMMENTAPPROVED', 'Comment approved.') - ); - } - } -} diff --git a/src/Admin/CommentsGridFieldBulkAction/CommentHandler.php b/src/Admin/CommentsGridFieldBulkAction/CommentHandler.php index fd66019..25298b8 100644 --- a/src/Admin/CommentsGridFieldBulkAction/CommentHandler.php +++ b/src/Admin/CommentsGridFieldBulkAction/CommentHandler.php @@ -5,7 +5,6 @@ namespace SilverStripe\Comments\Admin\CommentsGridFieldBulkAction; use Colymba\BulkManager\BulkAction\Handler; use Colymba\BulkTools\HTTPBulkToolsResponse; use SilverStripe\Comments\Model\Comment; -use SilverStripe\Core\Convert; use SilverStripe\Control\HTTPRequest; use SilverStripe\Control\HTTPResponse; diff --git a/src/Admin/CommentsGridFieldBulkAction/Handler.php b/src/Admin/CommentsGridFieldBulkAction/Handler.php deleted file mode 100644 index e215fa8..0000000 --- a/src/Admin/CommentsGridFieldBulkAction/Handler.php +++ /dev/null @@ -1,78 +0,0 @@ - 'spam', - 'approve' => 'approve', - ); - - /** - * @param HTTPRequest $request - * @return HTTPResponse - */ - public function __construct() - { - Deprecation::notice('3.1.0', 'Use concrete Spam or Approve handlers instead', Deprecation::SCOPE_CLASS); - } - - public function spam(HTTPRequest $request) - { - $ids = array(); - - foreach ($this->getRecords() as $record) { - array_push($ids, $record->ID); - $record->markSpam(); - } - - $response = new HTTPResponse(json_encode(array( - 'done' => true, - 'records' => $ids - ))); - - $response->addHeader('Content-Type', 'text/json'); - - return $response; - } - - /** - * @param HTTPRequest $request - * @return HTTPResponse - */ - public function approve(HTTPRequest $request) - { - $ids = array(); - - foreach ($this->getRecords() as $record) { - array_push($ids, $record->ID); - $record->markApproved(); - } - - $response = new HTTPResponse(json_encode(array( - 'done' => true, - 'records' => $ids - ))); - - $response->addHeader('Content-Type', 'text/json'); - - return $response; - } -} diff --git a/src/Model/Comment.php b/src/Model/Comment.php index 61f4a51..a9d1391 100755 --- a/src/Model/Comment.php +++ b/src/Model/Comment.php @@ -2,7 +2,6 @@ namespace SilverStripe\Comments\Model; -use SilverStripe\Dev\Deprecation; use HTMLPurifier; use HTMLPurifier_Config; use SilverStripe\Comments\Controllers\CommentingController; @@ -23,7 +22,6 @@ use SilverStripe\Forms\TextareaField; use SilverStripe\Forms\TextField; use SilverStripe\ORM\ArrayList; use SilverStripe\ORM\DataObject; -use SilverStripe\ORM\FieldType\DBDatetime; use SilverStripe\ORM\PaginatedList; use SilverStripe\ORM\SS_List; use SilverStripe\Security\Member; @@ -258,26 +256,6 @@ class Comment extends DataObject : null; } - /** - * Returns the parent {@link DataObject} this comment is attached too - * - * @deprecated 4.0.0 Use $this->Parent() instead - * @return DataObject - */ - public function getParent() - { - // this is wrapped in withNoReplacement() because it's called by ViewableData::__get() - // which looks for a `"get$property"` method, which itself is called by - // AssetControllExtension::findAssets() - Deprecation::withNoReplacement(function () { - Deprecation::notice('4.0.0', 'Use $this->Parent() instead'); - }); - return $this->BaseClass && $this->ParentID - ? DataObject::get_by_id($this->BaseClass, $this->ParentID, true) - : null; - } - - /** * Returns a string to help identify the parent of the comment * diff --git a/tests/CommentsGridFieldActionTest.php b/tests/CommentsGridFieldActionTest.php deleted file mode 100644 index 059e3df..0000000 --- a/tests/CommentsGridFieldActionTest.php +++ /dev/null @@ -1,171 +0,0 @@ -markTestSkipped('Test calls deprecated code'); - } - $this->list = new DataList(Team::class); - $config = CommentsGridFieldConfig::create()->addComponent(new GridFieldDeleteAction()); - $this->gridField = new CommentsGridField('testfield', 'testfield', $this->list, $config); - $this->form = new Form(new CommentAdmin(), 'mockform', new FieldList(array($this->gridField)), new FieldList()); - } - - public function testAugmentColumns() - { - $action = new CommentsGridFieldAction(); - - // an entry called 'Actions' is added to the columns array - $columns = array(); - $action->augmentColumns($this->gridField, $columns); - $expected = array('Actions'); - $this->assertEquals($expected, $columns); - - $columns = array('Actions'); - $action->augmentColumns($this->gridField, $columns); - $expected = array('Actions'); - $this->assertEquals($expected, $columns); - } - - public function testGetColumnAttributes() - { - $action = new CommentsGridFieldAction(); - $record = new Comment(); - $attrs = $action->getColumnAttributes($this->gridField, $record, Comment::class); - $this->assertEquals(array('class' => 'col-buttons'), $attrs); - } - - public function testGetColumnMetadata() - { - $action = new CommentsGridFieldAction(); - $result = $action->getColumnMetadata($this->gridField, 'Actions'); - $this->assertEquals(array('title' => ''), $result); - $result = $action->getColumnMetadata($this->gridField, 'SomethingElse'); - $this->assertNull($result); - } - - public function testGetColumnsHandled() - { - $action = new CommentsGridFieldAction(); - $result = $action->getColumnsHandled($this->gridField); - $this->assertEquals(array('Actions'), $result); - } - - public function testGetColumnContent() - { - $this->logInWithPermission('CMS_ACCESS_CommentAdmin'); - $action = new CommentsGridFieldAction(); - $record = new Comment(); - $record->Name = 'Name of commeter'; - $record->Comment = 'This is a comment'; - $record->write(); - $recordID = $record->ID; - $html = $action->getColumnContent($this->gridField, $record, Comment::class); - $this->assertStringContainsString('data-url="admin/comments/mockform/field/testfield', $html); - - $this->assertStringContainsString('value="Spam"', $html); - $this->assertStringContainsString('id="action_CustomAction' . $recordID . 'Spam"', $html); - - $this->assertStringContainsString('value="Approve"', $html); - $this->assertStringContainsString('id="action_CustomAction' . $recordID . 'Approve"', $html); - - // If marked as spam, only the approve button should be available - $record->markSpam(); - $record->write(); - $html = $action->getColumnContent($this->gridField, $record, Comment::class); - $this->assertStringContainsString('value="Approve"', $html); - $this->assertStringNotContainsString('value="Spam"', $html); - - // If marked as spam, only the approve button should be available - $record->markApproved(); - $record->write(); - $html = $action->getColumnContent($this->gridField, $record, Comment::class); - $this->assertStringNotContainsString('value="Approve"', $html); - $this->assertStringContainsString('value="Spam"', $html); - } - - public function testGetActions() - { - $action = new CommentsGridFieldAction(); - $result = $action->getActions($this->gridField); - $this->assertEquals(array('spam', 'approve'), $result); - } - - public function testHandleAction() - { - $this->logInWithPermission('CMS_ACCESS_CommentAdmin'); - $item = new CommentableItem; - $item->write(); - - $action = new CommentsGridFieldAction(); - $record = new Comment(); - $record->Name = 'Name of commenter'; - $record->Comment = 'This is a comment'; - $record->ParentID = $item->ID; - $record->ParentClass = $item->class; - $record->write(); - $recordID = $record->ID; - $arguments = array('RecordID' => $recordID); - $data = array(); - $result = $action->handleAction($this->gridField, 'spam', $arguments, $data); - $this->assertEquals(200, Controller::curr()->getResponse()->getStatusCode()); - $this->assertEquals( - 'Comment marked as spam.', - Controller::curr()->getResponse()->getStatusDescription() - ); - $record = DataObject::get_by_id(Comment::class, $recordID); - $this->assertEquals(1, $record->Moderated); - $this->assertEquals(1, $record->IsSpam); - - //getStatusDescription - $result = $action->handleAction($this->gridField, 'approve', $arguments, $data); - $this->assertEquals(200, Controller::curr()->getResponse()->getStatusCode()); - $this->assertEquals( - 'Comment approved.', - Controller::curr()->getResponse()->getStatusDescription() - ); - - $record = DataObject::get_by_id(Comment::class, $recordID); - $this->assertEquals(1, $record->Moderated); - $this->assertEquals(0, $record->IsSpam); - } -}