Add check on list type
[MAILPOET-4752]
This commit is contained in:
@@ -23,4 +23,5 @@ class APIException extends \Exception {
|
||||
const LIST_USED_IN_EMAIL = 20;
|
||||
const LIST_USED_IN_FORM = 21;
|
||||
const FAILED_TO_DELETE_LIST = 22;
|
||||
const LIST_TYPE_IS_NOT_SUPPORTED = 23;
|
||||
}
|
||||
|
@@ -60,6 +60,9 @@ class Segments {
|
||||
// secondly validation on list name
|
||||
$this->validateSegmentName($data);
|
||||
|
||||
// update is supported only for default segment type
|
||||
$this->validateSegmentType((string)$data['id']);
|
||||
|
||||
try {
|
||||
$segment = $this->segmentsRepository->createOrUpdate(
|
||||
$data['name'],
|
||||
@@ -160,6 +163,21 @@ class Segments {
|
||||
}
|
||||
}
|
||||
|
||||
private function validateSegmentType(string $segmentId): void {
|
||||
$segment = $this->segmentsRepository->findOneById($segmentId);
|
||||
if ($segment && $segment->getType() !== SegmentEntity::TYPE_DEFAULT) {
|
||||
throw new APIException(
|
||||
str_replace(
|
||||
'%1$s',
|
||||
"'" . $segment->getType() . "'",
|
||||
// translators: %1$s is an invalid segment type.
|
||||
__('List of the type %1$s is not supported for this action.', 'mailpoet')
|
||||
),
|
||||
APIException::LIST_TYPE_IS_NOT_SUPPORTED
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SegmentEntity $segment
|
||||
* @return array
|
||||
|
Reference in New Issue
Block a user