Refactor WP Users segment controller to injectable service

[MAILPOET-3141]
This commit is contained in:
Rostislav Wolny
2020-10-29 13:50:49 +01:00
committed by Veljko V
parent 75e7012fb6
commit 645f888186
13 changed files with 131 additions and 139 deletions

View File

@@ -34,18 +34,23 @@ class Segments extends APIEndpoint {
/** @var WooCommerce */
private $wooCommerceSync;
/** @var WP */
private $wpSegment;
public function __construct(
Listing\BulkActionController $bulkAction,
Listing\Handler $listingHandler,
SegmentsRepository $segmentsRepository,
SegmentsResponseBuilder $segmentsResponseBuilder,
WooCommerce $wooCommerce
WooCommerce $wooCommerce,
WP $wpSegment
) {
$this->bulkAction = $bulkAction;
$this->listingHandler = $listingHandler;
$this->wooCommerceSync = $wooCommerce;
$this->segmentsRepository = $segmentsRepository;
$this->segmentsResponseBuilder = $segmentsResponseBuilder;
$this->wpSegment = $wpSegment;
}
public function get($data = []) {
@@ -179,7 +184,7 @@ class Segments extends APIEndpoint {
if ($data['type'] === Segment::TYPE_WC_USERS) {
$this->wooCommerceSync->synchronizeCustomers();
} else {
WP::synchronizeUsers();
$this->wpSegment->synchronizeUsers();
}
} catch (\Exception $e) {
return $this->errorResponse([