Prevent duplication of data in factories

[MAILPOET-3627]
This commit is contained in:
Pavel Dohnal
2021-06-04 11:21:02 +02:00
committed by Veljko V
parent 7bf6c44ea0
commit c8964b88a3
2 changed files with 5 additions and 3 deletions

View File

@@ -253,7 +253,7 @@ class Newsletter {
*/ */
public function withSegments(array $segments) { public function withSegments(array $segments) {
foreach ($segments as $segment) { foreach ($segments as $segment) {
$this->segments[] = $segment; $this->segments[$segment->getId()] = $segment;
} }
return $this; return $this;
} }
@@ -279,7 +279,7 @@ class Newsletter {
} }
public function withSubscriber(SubscriberEntity $subscriber, array $data = []) { public function withSubscriber(SubscriberEntity $subscriber, array $data = []) {
$this->taskSubscribers[] = array_merge([ $this->taskSubscribers[$subscriber->getId()] = array_merge([
'subscriber' => $subscriber, 'subscriber' => $subscriber,
'processed' => 1, 'processed' => 1,
'failed' => 0, 'failed' => 0,

View File

@@ -74,7 +74,9 @@ class Subscriber {
* @return $this * @return $this
*/ */
public function withSegments(array $segments) { public function withSegments(array $segments) {
$this->segments = array_merge($this->segments, $segments); foreach ($segments as $segment) {
$this->segments[$segment->getId()] = $segment;
}
return $this; return $this;
} }