Handle bulk operations on subscribers filtered by dynamic segments

[PREMIUM-69]
This commit is contained in:
Pavel Dohnal
2018-02-28 17:12:56 +00:00
parent 8837c9e14c
commit 99edc35b08
5 changed files with 181 additions and 7 deletions

View File

@ -12,6 +12,7 @@ use MailPoet\Models\Setting;
use MailPoet\Models\StatisticsForms;
use MailPoet\Models\Subscriber;
use MailPoet\Newsletter\Scheduler\Scheduler;
use MailPoet\Segments\BulkAction;
use MailPoet\Segments\SubscribersListings;
use MailPoet\Subscription\Throttling as SubscriptionThrottling;
use MailPoet\WP\Hooks;
@ -246,12 +247,12 @@ class Subscribers extends APIEndpoint {
function bulkAction($data = array()) {
try {
$bulk_action = new Listing\BulkAction(
'\MailPoet\Models\Subscriber',
$data
);
$meta = $bulk_action->apply();
return $this->successResponse(null, $meta);
if(!isset($data['listing']['filter']['segment'])) {
$bulk_action = new Listing\BulkAction('\MailPoet\Models\Subscriber', $data);
} else {
$bulk_action = new BulkAction($data);
}
return $this->successResponse(null, $bulk_action->apply());
} catch(\Exception $e) {
return $this->errorResponse(array(
$e->getCode() => $e->getMessage()