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
1 changed files with 9 additions and 6 deletions

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('Changes applied');
return $response;
}