Add a random string when creating a segment if the name already exists

This ensures that it is possible to create multiple segments from the
same template.

[MAILPOET-5394]
This commit is contained in:
Rodrigo Primo
2023-09-06 08:41:26 -03:00
committed by Aschepikov
parent dba4ba4dfc
commit f806b3362c
4 changed files with 14 additions and 3 deletions

View File

@ -38,6 +38,11 @@ class SegmentSaveController {
public function save(array $data = []): SegmentEntity {
$id = isset($data['id']) ? (int)$data['id'] : null;
$name = $data['name'] ?? '';
if (!$this->segmentsRepository->isNameUnique($name, null) && isset($data['force_creation']) && $data['force_creation'] === 'true') {
$name = $name . ' (' . wp_generate_password(12, false) . ')';
}
$description = $data['description'] ?? '';
$filtersData = $this->filterDataMapper->map($data);