Remove old unused class for read subscribers

[MAILPOET-3376]
This commit is contained in:
Jan Lysý
2021-03-02 17:26:11 +01:00
committed by Veljko V
parent 9c961757e7
commit a3224e9286
5 changed files with 0 additions and 806 deletions

View File

@ -1,80 +0,0 @@
<?php
namespace MailPoet\Subscribers\ImportExport\Export;
use MailPoet\Models\Segment;
use MailPoet\Models\Subscriber;
use MailPoet\Models\SubscriberSegment;
use MailPoet\WP\Functions as WPFunctions;
/**
* Gets batches of subscribers from default segments.
*/
class DefaultSubscribersGetter extends SubscribersGetter {
/**
* @var bool
*/
protected $getSubscribersWithoutSegment;
public function __construct($segmentsIds, $batchSize) {
parent::__construct($segmentsIds, $batchSize);
$this->getSubscribersWithoutSegment = (array_search(0, $segmentsIds) !== false);
}
protected function filter($subscribers) {
$subscribers = $subscribers
->selectMany(
[
'list_status' => SubscriberSegment::$_table . '.status',
]
)
->left_outer_join(
SubscriberSegment::$_table,
[
Subscriber::$_table . '.id',
'=',
SubscriberSegment::$_table . '.subscriber_id',
]
)
->left_outer_join(
Segment::$_table,
[
Segment::$_table . '.id',
'=',
SubscriberSegment::$_table . '.segment_id',
]
)
->groupBy(Segment::$_table . '.id');
if ($this->getSubscribersWithoutSegment !== false) {
// if there are subscribers who do not belong to any segment, use
// a CASE function to group them under "Not In Segment"
$subscribers = $subscribers
->selectExpr(
'MAX(CASE WHEN ' . Segment::$_table . '.name IS NOT NULL ' .
'THEN ' . Segment::$_table . '.name ' .
'ELSE "' . WPFunctions::get()->__('Not In Segment', 'mailpoet') . '" END) as segment_name'
)
->whereRaw(
SubscriberSegment::$_table . '.segment_id IN (' .
rtrim(str_repeat('?,', count($this->segmentsIds)), ',') . ') ' .
'OR ' . SubscriberSegment::$_table . '.segment_id IS NULL ',
$this->segmentsIds
);
} else {
// if all subscribers belong to at least one segment, select the segment name
$subscribers = $subscribers
->selectExpr('MAX(' . Segment::$_table . '.name) as segment_name')
->whereIn(SubscriberSegment::$_table . '.segment_id', $this->segmentsIds);
}
$subscribers = $subscribers
->offset($this->offset)
->limit($this->batchSize)
->findArray();
return $subscribers;
}
}

View File

@ -1,77 +0,0 @@
<?php
namespace MailPoet\Subscribers\ImportExport\Export;
use MailPoet\DI\ContainerWrapper;
use MailPoet\DynamicSegments\Persistence\Loading\SingleSegmentLoader;
use MailPoet\Models\Segment;
use MailPoet\Models\Subscriber;
/**
* Gets batches of subscribers from dynamic segments.
*/
class DynamicSubscribersGetter extends SubscribersGetter {
protected $segmentIndex = 0;
/** @var SingleSegmentLoader */
private $dynamicSegmentsLoader;
public function __construct($segmentsIds, $batchSize, SingleSegmentLoader $dynamicSegmentsLoader = null) {
parent::__construct($segmentsIds, $batchSize);
if ($dynamicSegmentsLoader === null) {
$dynamicSegmentsLoader = ContainerWrapper::getInstance()->get(SingleSegmentLoader::class);
}
$this->dynamicSegmentsLoader = $dynamicSegmentsLoader;
}
public function reset() {
parent::reset();
$this->segmentIndex = 0;
}
protected function filter($subscribers) {
$segmentId = $this->segmentsIds[$this->segmentIndex];
$filters = $this->dynamicSegmentsLoader->load($segmentId)->getFilters();
if (!is_array($filters) || empty($filters)) {
return [];
}
$segment = Segment::findOne($segmentId);
if (!$segment instanceof Segment) {
return [];
}
$name = $segment->name;
foreach ($filters as $filter) {
$subscribers = $filter->toSql($subscribers);
}
return $subscribers
->selectMany([
'list_status' => Subscriber::$_table . '.status',
])
->selectExpr("'" . $name . "' AS segment_name")
->offset($this->offset)
->limit($this->batchSize)
->findArray();
}
public function get() {
if ($this->segmentIndex >= count($this->segmentsIds)) {
$this->finished = true;
}
$subscribers = parent::get();
if ($subscribers !== false && count($subscribers) < $this->batchSize) {
$this->segmentIndex ++;
$this->offset = 0;
$this->finished = false;
}
return $subscribers;
}
}

View File

@ -1,76 +0,0 @@
<?php
namespace MailPoet\Subscribers\ImportExport\Export;
use MailPoet\Models\Subscriber;
use MailPoetVendor\Idiorm\ORM;
/**
* Gets batches of subscribers for export.
*/
abstract class SubscribersGetter {
protected $segmentsIds;
protected $batchSize;
protected $offset;
protected $finished;
public function __construct($segmentsIds, $batchSize) {
$this->segmentsIds = $segmentsIds;
$this->batchSize = $batchSize;
$this->reset();
}
public function reset() {
$this->offset = 0;
$this->finished = false;
}
/**
* Initialize the query by selecting fields and ignoring trashed subscribers.
*
* @return ORM
*/
protected function select() {
return Subscriber::selectMany(
'first_name',
'last_name',
'email',
'subscribed_ip',
[
'global_status' => Subscriber::$_table . '.status',
]
)
->filter('filterWithCustomFieldsForExport')
->groupBy(Subscriber::$_table . '.id')
->whereNull(Subscriber::$_table . '.deleted_at');
}
/**
* Filters the subscribers query based on the segments, offset and batch size.
*
* @param ORM $subscribers
* @return array
*/
abstract protected function filter($subscribers);
/**
* Gets the next batch of subscribers or `false` if no more!
*/
public function get() {
if ($this->finished) {
return false;
}
$subscribers = $this->select();
$subscribers = $this->filter($subscribers);
$this->offset += $this->batchSize;
if (count($subscribers) < $this->batchSize) {
$this->finished = true;
}
return $subscribers;
}
}