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) {