Adjust the output of CommentHandler to use HTTPBulkToolsResponse

GridFieldBulkEditingTools has introduced a common output schema
in the form of HTTPBulkToolsResponse. This commit adopts that API.
This commit is contained in:
Garion Herman 2019-03-22 15:00:19 +13:00
parent 9ff1db403e
commit 74afde6d9b

View File

@ -3,6 +3,7 @@
namespace SilverStripe\Comments\Admin\CommentsGridFieldBulkAction; namespace SilverStripe\Comments\Admin\CommentsGridFieldBulkAction;
use Colymba\BulkManager\BulkAction\Handler; use Colymba\BulkManager\BulkAction\Handler;
use Colymba\BulkTools\HTTPBulkToolsResponse;
use SilverStripe\Comments\Model\Comment; use SilverStripe\Comments\Model\Comment;
use SilverStripe\Core\Convert; use SilverStripe\Core\Convert;
use SilverStripe\Control\HTTPRequest; use SilverStripe\Control\HTTPRequest;
@ -22,17 +23,19 @@ abstract class CommentHandler extends Handler
{ {
$ids = []; $ids = [];
$response = new HTTPBulkToolsResponse(
true,
$this->gridField,
200
);
foreach ($this->getRecords() as $comment) { foreach ($this->getRecords() as $comment) {
array_push($ids, $comment->ID); array_push($ids, $comment->ID);
$this->updateComment($comment); $this->updateComment($comment);
$response->addSuccessRecord($comment);
} }
$response = new HTTPResponse(json_encode([ $response->setMessage('Changes applied');
'done' => true,
'records' => $ids,
]));
$response->addHeader('Content-Type', 'application/json');
return $response; return $response;
} }