Refactor bulk action into reusable controller
[MAILPOET-1689]
This commit is contained in:
@ -280,11 +280,8 @@ class Forms extends APIEndpoint {
|
||||
|
||||
function bulkAction($data = array()) {
|
||||
try {
|
||||
$bulk_action = new Listing\BulkAction(
|
||||
'\MailPoet\Models\Form',
|
||||
$data
|
||||
);
|
||||
$meta = $bulk_action->apply();
|
||||
$bulk_action = new Listing\BulkActionController();
|
||||
$meta = $bulk_action->apply('\MailPoet\Models\Form', $data);
|
||||
return $this->successResponse(null, $meta);
|
||||
} catch(\Exception $e) {
|
||||
return $this->errorResponse(array(
|
||||
|
@ -438,11 +438,8 @@ class Newsletters extends APIEndpoint {
|
||||
|
||||
function bulkAction($data = array()) {
|
||||
try {
|
||||
$bulk_action = new Listing\BulkAction(
|
||||
'\MailPoet\Models\Newsletter',
|
||||
$data
|
||||
);
|
||||
$meta = $bulk_action->apply();
|
||||
$bulk_action = new Listing\BulkActionController();
|
||||
$meta = $bulk_action->apply('\MailPoet\Models\Newsletter', $data);
|
||||
return $this->successResponse(null, $meta);
|
||||
} catch(\Exception $e) {
|
||||
return $this->errorResponse(array(
|
||||
|
@ -152,11 +152,8 @@ class Segments extends APIEndpoint {
|
||||
|
||||
function bulkAction($data = array()) {
|
||||
try {
|
||||
$bulk_action = new Listing\BulkAction(
|
||||
'\MailPoet\Models\Segment',
|
||||
$data
|
||||
);
|
||||
$meta = $bulk_action->apply();
|
||||
$bulk_action = new Listing\BulkActionController();
|
||||
$meta = $bulk_action->apply('\MailPoet\Models\Segment', $data);
|
||||
return $this->successResponse(null, $meta);
|
||||
} catch(\Exception $e) {
|
||||
return $this->errorResponse(array(
|
||||
|
@ -262,11 +262,15 @@ class Subscribers extends APIEndpoint {
|
||||
function bulkAction($data = array()) {
|
||||
try {
|
||||
if(!isset($data['listing']['filter']['segment'])) {
|
||||
$bulk_action = new Listing\BulkAction('\MailPoet\Models\Subscriber', $data);
|
||||
$bulk_action = new Listing\BulkActionController();
|
||||
return $this->successResponse(
|
||||
null,
|
||||
$bulk_action->apply('\MailPoet\Models\Subscriber', $data)
|
||||
);
|
||||
} else {
|
||||
$bulk_action = new BulkAction($data);
|
||||
return $this->successResponse(null, $bulk_action->apply());
|
||||
}
|
||||
return $this->successResponse(null, $bulk_action->apply());
|
||||
} catch(\Exception $e) {
|
||||
return $this->errorResponse(array(
|
||||
$e->getCode() => $e->getMessage()
|
||||
|
Reference in New Issue
Block a user