Fix formatting
[MAILPOET-5555]
This commit is contained in:
@@ -82,27 +82,40 @@ class SubscriberSegmentRepository extends Repository {
|
|||||||
|
|
||||||
public function resetSubscriptions(SubscriberEntity $subscriber, array $segments): void {
|
public function resetSubscriptions(SubscriberEntity $subscriber, array $segments): void {
|
||||||
$existingSegments = array_values(array_filter(array_map(
|
$existingSegments = array_values(array_filter(array_map(
|
||||||
function(SubscriberSegmentEntity $subscriberSegmentEntity): ?SegmentEntity { return $subscriberSegmentEntity->getSegment();
|
function(SubscriberSegmentEntity $subscriberSegmentEntity): ?SegmentEntity {
|
||||||
|
return $subscriberSegmentEntity->getSegment();
|
||||||
},
|
},
|
||||||
$this->findBy(['subscriber' => $subscriber, 'status' => SubscriberEntity::STATUS_SUBSCRIBED])
|
$this->findBy(['subscriber' => $subscriber, 'status' => SubscriberEntity::STATUS_SUBSCRIBED])
|
||||||
)));
|
)));
|
||||||
$existingSegmentIds = array_map(function(SegmentEntity $segment): int { return $segment->getId() ?? 0;
|
$existingSegmentIds = array_map(
|
||||||
|
function(SegmentEntity $segment): int {
|
||||||
}, $existingSegments);
|
return $segment->getId() ?? 0;
|
||||||
$segmentIds = array_map(function(SegmentEntity $segment): int { return $segment->getId() ?? 0;
|
},
|
||||||
|
$existingSegments
|
||||||
}, $segments);
|
);
|
||||||
|
$segmentIds = array_map(
|
||||||
|
function(SegmentEntity $segment): int {
|
||||||
|
return $segment->getId() ?? 0;
|
||||||
|
},
|
||||||
|
$segments
|
||||||
|
);
|
||||||
$unsubscribedSegments = array_diff($existingSegmentIds, $segmentIds);
|
$unsubscribedSegments = array_diff($existingSegmentIds, $segmentIds);
|
||||||
$newlySubscribedSegments = array_diff($segmentIds, $existingSegmentIds);
|
$newlySubscribedSegments = array_diff($segmentIds, $existingSegmentIds);
|
||||||
if (!$newlySubscribedSegments && !$unsubscribedSegments) {
|
if (!$newlySubscribedSegments && !$unsubscribedSegments) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$unsubscribe = array_filter($existingSegments, function(SegmentEntity $segment) use ($unsubscribedSegments): bool {
|
$unsubscribe = array_filter(
|
||||||
return in_array($segment->getId(), $unsubscribedSegments);
|
$existingSegments,
|
||||||
});
|
function(SegmentEntity $segment) use ($unsubscribedSegments): bool {
|
||||||
$subscribe = array_filter($segments, function(SegmentEntity $segment) use ($newlySubscribedSegments): bool {
|
return in_array($segment->getId(), $unsubscribedSegments);
|
||||||
return in_array($segment->getId(), $newlySubscribedSegments);
|
}
|
||||||
});
|
);
|
||||||
|
$subscribe = array_filter(
|
||||||
|
$segments,
|
||||||
|
function(SegmentEntity $segment) use ($newlySubscribedSegments): bool {
|
||||||
|
return in_array($segment->getId(), $newlySubscribedSegments);
|
||||||
|
}
|
||||||
|
);
|
||||||
if ($unsubscribe) {
|
if ($unsubscribe) {
|
||||||
$this->unsubscribeFromSegments($subscriber, $unsubscribe);
|
$this->unsubscribeFromSegments($subscriber, $unsubscribe);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user