Enables subscriber email to be passed when subscribing to list(s)

List subscription methods return array with subscriber data
This commit is contained in:
Vlad
2017-05-19 09:51:29 -04:00
parent 0a512f6349
commit 766c0dfcfc
2 changed files with 8 additions and 12 deletions

View File

@ -42,7 +42,7 @@ class API {
} }
function subscribeToLists($subscriber_id, array $segments_ids) { function subscribeToLists($subscriber_id, array $segments_ids) {
$subscriber = Subscriber::findOne((int)$subscriber_id); $subscriber = Subscriber::findOne($subscriber_id);
// throw exception when subscriber does not exist // throw exception when subscriber does not exist
if(!$subscriber) { if(!$subscriber) {
throw new \Exception(__('This subscriber does not exist.', 'mailpoet')); throw new \Exception(__('This subscriber does not exist.', 'mailpoet'));
@ -69,7 +69,8 @@ class API {
throw new \Exception(__(sprintf('Lists with ID %s do not exist.', implode(', ', $missing_ids)), 'mailpoet')); throw new \Exception(__(sprintf('Lists with ID %s do not exist.', implode(', ', $missing_ids)), 'mailpoet'));
} }
return SubscriberSegment::subscribeToSegments($subscriber, $found_segments_ids); SubscriberSegment::subscribeToSegments($subscriber, $found_segments_ids);
return $subscriber->withCustomFields()->withSubscriptions()->asArray();
} }
function getLists() { function getLists() {

View File

@ -113,11 +113,8 @@ class MPAPITest extends MailPoetTest {
) )
); );
$result = API::MP(self::VERSION)->subscribeToLists($subscriber->id, array($segment->id)); $result = API::MP(self::VERSION)->subscribeToLists($subscriber->id, array($segment->id));
expect($result)->true(); expect($result['id'])->equals($subscriber->id);
$subscriber_segment = SubscriberSegment::where('subscriber_id', $subscriber->id) expect($result['subscriptions'][0]['id'])->equals($segment->id);
->where('segment_id', $segment->id)
->findOne();
expect($subscriber_segment)->notEmpty();
} }
function testItSubscribesSubscriberToSingleList() { function testItSubscribesSubscriberToSingleList() {
@ -131,11 +128,9 @@ class MPAPITest extends MailPoetTest {
) )
); );
$result = API::MP(self::VERSION)->subscribeToList($subscriber->id, $segment->id); $result = API::MP(self::VERSION)->subscribeToList($subscriber->id, $segment->id);
expect($result)->true(); expect($result['id'])->equals($subscriber->id);
$subscriber_segment = SubscriberSegment::where('subscriber_id', $subscriber->id) expect($result['subscriptions'])->notEmpty();
->where('segment_id', $segment->id) expect($result['subscriptions'][0]['id'])->equals($segment->id);
->findOne();
expect($subscriber_segment)->notEmpty();
} }
function testItGetsSegments() { function testItGetsSegments() {