Refactor WP Users segment controller to injectable service
[MAILPOET-3141]
This commit is contained in:
committed by
Veljko V
parent
75e7012fb6
commit
645f888186
@@ -6,6 +6,7 @@ use MailPoet\Form\DisplayFormInWPContent;
|
||||
use MailPoet\Mailer\WordPress\WordpressMailerReplacer;
|
||||
use MailPoet\Newsletter\Scheduler\PostNotificationScheduler;
|
||||
use MailPoet\Segments\WooCommerce as WooCommerceSegment;
|
||||
use MailPoet\Segments\WP;
|
||||
use MailPoet\Settings\SettingsController;
|
||||
use MailPoet\Statistics\Track\WooCommercePurchases;
|
||||
use MailPoet\Subscription\Comment;
|
||||
@@ -57,6 +58,9 @@ class Hooks {
|
||||
/** @var DisplayFormInWPContent */
|
||||
private $displayFormInWPContent;
|
||||
|
||||
/** @var WP */
|
||||
private $wpSegment;
|
||||
|
||||
public function __construct(
|
||||
Form $subscriptionForm,
|
||||
Comment $subscriptionComment,
|
||||
@@ -70,7 +74,8 @@ class Hooks {
|
||||
WooCommercePurchases $woocommercePurchases,
|
||||
PostNotificationScheduler $postNotificationScheduler,
|
||||
WordpressMailerReplacer $wordpressMailerReplacer,
|
||||
DisplayFormInWPContent $displayFormInWPContent
|
||||
DisplayFormInWPContent $displayFormInWPContent,
|
||||
WP $wpSegment
|
||||
) {
|
||||
$this->subscriptionForm = $subscriptionForm;
|
||||
$this->subscriptionComment = $subscriptionComment;
|
||||
@@ -85,6 +90,7 @@ class Hooks {
|
||||
$this->postNotificationScheduler = $postNotificationScheduler;
|
||||
$this->wordpressMailerReplacer = $wordpressMailerReplacer;
|
||||
$this->displayFormInWPContent = $displayFormInWPContent;
|
||||
$this->wpSegment = $wpSegment;
|
||||
}
|
||||
|
||||
public function init() {
|
||||
@@ -237,33 +243,33 @@ class Hooks {
|
||||
// WP Users synchronization
|
||||
$this->wp->addAction(
|
||||
'user_register',
|
||||
'\MailPoet\Segments\WP::synchronizeUser',
|
||||
[$this->wpSegment, 'synchronizeUser'],
|
||||
6
|
||||
);
|
||||
$this->wp->addAction(
|
||||
'added_existing_user',
|
||||
'\MailPoet\Segments\WP::synchronizeUser',
|
||||
[$this->wpSegment, 'synchronizeUser'],
|
||||
6
|
||||
);
|
||||
$this->wp->addAction(
|
||||
'profile_update',
|
||||
'\MailPoet\Segments\WP::synchronizeUser',
|
||||
[$this->wpSegment, 'synchronizeUser'],
|
||||
6, 2
|
||||
);
|
||||
$this->wp->addAction(
|
||||
'delete_user',
|
||||
'\MailPoet\Segments\WP::synchronizeUser',
|
||||
[$this->wpSegment, 'synchronizeUser'],
|
||||
1
|
||||
);
|
||||
// multisite
|
||||
$this->wp->addAction(
|
||||
'deleted_user',
|
||||
'\MailPoet\Segments\WP::synchronizeUser',
|
||||
[$this->wpSegment, 'synchronizeUser'],
|
||||
1
|
||||
);
|
||||
$this->wp->addAction(
|
||||
'remove_user_from_blog',
|
||||
'\MailPoet\Segments\WP::synchronizeUser',
|
||||
[$this->wpSegment, 'synchronizeUser'],
|
||||
1
|
||||
);
|
||||
}
|
||||
|
@@ -49,17 +49,21 @@ class Populator {
|
||||
const TEMPLATES_NAMESPACE = '\MailPoet\Config\PopulatorData\Templates\\';
|
||||
/** @var FormsRepository */
|
||||
private $formsRepository;
|
||||
/** @var WP */
|
||||
private $wpSegment;
|
||||
|
||||
public function __construct(
|
||||
SettingsController $settings,
|
||||
WPFunctions $wp,
|
||||
Captcha $captcha,
|
||||
ReferralDetector $referralDetector,
|
||||
FormsRepository $formsRepository
|
||||
FormsRepository $formsRepository,
|
||||
WP $wpSegment
|
||||
) {
|
||||
$this->settings = $settings;
|
||||
$this->wp = $wp;
|
||||
$this->captcha = $captcha;
|
||||
$this->wpSegment = $wpSegment;
|
||||
$this->referralDetector = $referralDetector;
|
||||
$this->prefix = Env::$dbPrefix;
|
||||
$this->models = [
|
||||
@@ -337,7 +341,7 @@ class Populator {
|
||||
Segment::getWooCommerceSegment();
|
||||
|
||||
// Synchronize WP Users
|
||||
WP::synchronizeUsers();
|
||||
$this->wpSegment->synchronizeUsers();
|
||||
|
||||
// Default segment
|
||||
$defaultSegment = Segment::where('type', 'default')->orderByAsc('id')->limit(1)->findOne();
|
||||
|
Reference in New Issue
Block a user