Exclude trashed and multiple-list subscribers [MAILPOET-789]

This commit is contained in:
Alexey Stoletniy
2017-01-19 23:04:29 +03:00
parent 815461a851
commit 4d3c90ce0d
2 changed files with 17 additions and 11 deletions

View File

@@ -280,7 +280,9 @@ class Subscriber extends Model {
'value' => ''
);
$subscribers_without_segment = self::filter('withoutSegments')->count();
$subscribers_without_segment = self::filter('withoutSegments')
->whereNull('deleted_at')
->count();
$subscribers_without_segment_label = sprintf(
__('Subscribers without a list (%s)', 'mailpoet'),
number_format($subscribers_without_segment)
@@ -771,19 +773,20 @@ class Subscriber extends Model {
static function withoutSegments($orm) {
return $orm->select(MP_SUBSCRIBERS_TABLE.'.*')
->leftOuterJoin(
MP_SUBSCRIBER_SEGMENT_TABLE,
->rawJoin(
'LEFT OUTER JOIN (
SELECT `subscriber_id`
FROM '.MP_SUBSCRIBER_SEGMENT_TABLE.'
WHERE `status` = "'.self::STATUS_SUBSCRIBED.'"
)',
array(
MP_SUBSCRIBERS_TABLE.'.id',
'=',
MP_SUBSCRIBER_SEGMENT_TABLE.'.subscriber_id'
)
),
MP_SUBSCRIBER_SEGMENT_TABLE
)
->whereRaw(
MP_SUBSCRIBER_SEGMENT_TABLE . '.status != ? ' .
' OR ' . MP_SUBSCRIBER_SEGMENT_TABLE . '.subscriber_id IS NULL ',
self::STATUS_SUBSCRIBED
);
->whereNull(MP_SUBSCRIBER_SEGMENT_TABLE.'.subscriber_id');
}
static function createMultiple($columns, $values) {

View File

@@ -152,6 +152,9 @@ class SubscriberTest extends MailPoetTest {
$segment = Segment::createOrUpdate(array(
'name' => 'Test segment'
));
$segment_2 = Segment::createOrUpdate(array(
'name' => 'Test segment 2'
));
// not yet subscribed
$subscribers = Subscriber::filter('filterBy', array('segment' => 'none'))
@@ -164,7 +167,7 @@ class SubscriberTest extends MailPoetTest {
// subscribed to a segment
SubscriberSegment::subscribeToSegments(
$subscriber,
array($segment->id)
array($segment->id, $segment_2->id)
);
$subscribers = Subscriber::filter('filterBy', array('segment' => 'none'))
@@ -177,7 +180,7 @@ class SubscriberTest extends MailPoetTest {
// unsubscribed
SubscriberSegment::unsubscribeFromSegments(
$subscriber,
array($segment->id)
array($segment->id, $segment_2->id)
);
$subscribers = Subscriber::filter('filterBy', array('segment' => 'none'))