Categorize (un)subscribed users of a list correctly
To evaluate whether a user is subscribed to a list or unsubscribed you need to take into account the status of the current subscription and not only the global status. To be unsubscribed you are either globally or per list unsubscribed. To be subscribed you need to be globally and per list subscribed [MAILPOET-4487]
This commit is contained in:
@ -41,6 +41,9 @@ class SubscriberListingRepository extends ListingRepository {
|
||||
/** @var SubscribersCountsController */
|
||||
private $subscribersCountsController;
|
||||
|
||||
/** @var null | ListingDefinition */
|
||||
private $definition = null;
|
||||
|
||||
public function __construct(
|
||||
EntityManager $entityManager,
|
||||
FilterHandler $dynamicSegmentsFilter,
|
||||
@ -55,6 +58,7 @@ class SubscriberListingRepository extends ListingRepository {
|
||||
}
|
||||
|
||||
public function getData(ListingDefinition $definition): array {
|
||||
$this->definition = $definition;
|
||||
$dynamicSegment = $this->getDynamicSegmentFromFilters($definition);
|
||||
if ($dynamicSegment === null) {
|
||||
return parent::getData($definition);
|
||||
@ -63,6 +67,7 @@ class SubscriberListingRepository extends ListingRepository {
|
||||
}
|
||||
|
||||
public function getCount(ListingDefinition $definition): int {
|
||||
$this->definition = $definition;
|
||||
$dynamicSegment = $this->getDynamicSegmentFromFilters($definition);
|
||||
if ($dynamicSegment === null) {
|
||||
return parent::getCount($definition);
|
||||
@ -78,6 +83,7 @@ class SubscriberListingRepository extends ListingRepository {
|
||||
}
|
||||
|
||||
public function getActionableIds(ListingDefinition $definition): array {
|
||||
$this->definition = $definition;
|
||||
$ids = $definition->getSelection();
|
||||
if (!empty($ids)) {
|
||||
return $ids;
|
||||
@ -118,8 +124,24 @@ class SubscriberListingRepository extends ListingRepository {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!in_array($group, [SubscriberEntity::STATUS_SUBSCRIBED, SubscriberEntity::STATUS_UNSUBSCRIBED])) {
|
||||
$queryBuilder
|
||||
->andWhere('s.status = :status')
|
||||
->setParameter('status', $group);
|
||||
return;
|
||||
}
|
||||
|
||||
$segment = $this->definition && array_key_exists('segment', $this->definition->getFilters()) ? $this->entityManager->find(SegmentEntity::class, (int)$this->definition->getFilters()['segment']) : null;
|
||||
if (!$segment instanceof SegmentEntity || !$segment->isStatic()) {
|
||||
$queryBuilder
|
||||
->andWhere('s.status = :status')
|
||||
->setParameter('status', $group);
|
||||
return;
|
||||
}
|
||||
|
||||
$operator = $group === SubscriberEntity::STATUS_SUBSCRIBED ? 'AND' : 'OR';
|
||||
$queryBuilder
|
||||
->andWhere('s.status = :status')
|
||||
->andWhere('(s.status = :status ' . $operator . ' ss.status = :status)')
|
||||
->setParameter('status', $group);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user