Merge pull request #280 from creative-commoners/pulls/master/improve-compat-with-bulk-editing-tools

Adjust the output of CommentHandler to use HTTPBulkToolsResponse
This commit is contained in:
Dylan Wagstaff 2019-03-24 13:34:21 +13:00 committed by GitHub
commit 8b178b63ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 7 deletions

View File

@ -14,7 +14,7 @@
],
"require": {
"silverstripe/framework": "^4.2",
"colymba/gridfield-bulk-editing-tools": "^3.0"
"colymba/gridfield-bulk-editing-tools": "^3.0.0-beta4"
},
"suggest": {
"ezyang/htmlpurifier": "Standards compliant HTML filter written in PHP",

View File

@ -3,6 +3,7 @@
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;
@ -22,17 +23,19 @@ abstract class CommentHandler extends Handler
{
$ids = [];
$response = new HTTPBulkToolsResponse(
true,
$this->gridField,
200
);
foreach ($this->getRecords() as $comment) {
array_push($ids, $comment->ID);
$this->updateComment($comment);
$response->addSuccessRecord($comment);
}
$response = new HTTPResponse(json_encode([
'done' => true,
'records' => $ids,
]));
$response->addHeader('Content-Type', 'application/json');
$response->setMessage(_t(__CLASS__ . '.CHANGES_APPLIED', 'Changes applied'));
return $response;
}