Add new API method updateList
[MAILPOET-4752]
This commit is contained in:
@@ -80,6 +80,10 @@ class API {
|
|||||||
return $this->segments->addList($list);
|
return $this->segments->addList($list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function updateList(array $list): array {
|
||||||
|
return $this->segments->updateList($list);
|
||||||
|
}
|
||||||
|
|
||||||
public function getSubscriber($subscriberEmail) {
|
public function getSubscriber($subscriberEmail) {
|
||||||
return $this->subscribers->getSubscriber($subscriberEmail);
|
return $this->subscribers->getSubscriber($subscriberEmail);
|
||||||
}
|
}
|
||||||
|
@@ -18,4 +18,6 @@ class APIException extends \Exception {
|
|||||||
const LIST_EXISTS = 15;
|
const LIST_EXISTS = 15;
|
||||||
const FAILED_TO_SAVE_LIST = 16;
|
const FAILED_TO_SAVE_LIST = 16;
|
||||||
const WELCOME_FAILED_TO_SEND = 17;
|
const WELCOME_FAILED_TO_SEND = 17;
|
||||||
|
const LIST_ID_REQUIRED = 18;
|
||||||
|
const FAILED_TO_UPDATE_LIST = 19;
|
||||||
}
|
}
|
||||||
|
@@ -41,6 +41,43 @@ class Segments {
|
|||||||
return $this->buildItem($segment);
|
return $this->buildItem($segment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function updateList(array $data): array {
|
||||||
|
// firstly validation on list id
|
||||||
|
if (empty($data['id'])) {
|
||||||
|
throw new APIException(
|
||||||
|
__('List id is required.', 'mailpoet'),
|
||||||
|
APIException::LIST_ID_REQUIRED
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->segmentsRepository->findOneById((string)$data['id'])) {
|
||||||
|
throw new APIException(
|
||||||
|
__('The list does not exist.', 'mailpoet'),
|
||||||
|
APIException::LIST_NOT_EXISTS
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// secondly validation on list name
|
||||||
|
$this->validateSegmentName($data);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$segment = $this->segmentsRepository->createOrUpdate(
|
||||||
|
$data['name'],
|
||||||
|
$data['description'] ?? '',
|
||||||
|
SegmentEntity::TYPE_DEFAULT,
|
||||||
|
[],
|
||||||
|
$data['id']
|
||||||
|
);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
throw new APIException(
|
||||||
|
__('The list couldn’t be updated in the database', 'mailpoet'),
|
||||||
|
APIException::FAILED_TO_UPDATE_LIST
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->buildItem($segment);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Throws an exception when the segment's name is invalid
|
* Throws an exception when the segment's name is invalid
|
||||||
* @return void
|
* @return void
|
||||||
|
Reference in New Issue
Block a user