Fix subscriber status resetting on WP user creation
Fixes:#2960 [MAILPOET-3016]
This commit is contained in:
@ -43,6 +43,11 @@ class WP {
|
|||||||
$wpSegment = Segment::getWPSegment();
|
$wpSegment = Segment::getWPSegment();
|
||||||
if (!$wpSegment) return;
|
if (!$wpSegment) return;
|
||||||
|
|
||||||
|
// find subscriber by email when is false
|
||||||
|
if (!$subscriber) {
|
||||||
|
$subscriber = Subscriber::where('email', $wpUser->user_email)->findOne(); // phpcs:ignore Squiz.NamingConventions.ValidVariableName.NotCamelCaps
|
||||||
|
}
|
||||||
|
|
||||||
$scheduleWelcomeNewsletter = false;
|
$scheduleWelcomeNewsletter = false;
|
||||||
if (in_array($currentFilter, ['profile_update', 'user_register'])) {
|
if (in_array($currentFilter, ['profile_update', 'user_register'])) {
|
||||||
$scheduleWelcomeNewsletter = true;
|
$scheduleWelcomeNewsletter = true;
|
||||||
|
@ -32,6 +32,19 @@ class WPTest extends \MailPoetTest {
|
|||||||
expect($dbSubscriber->status)->equals(Subscriber::STATUS_SUBSCRIBED);
|
expect($dbSubscriber->status)->equals(Subscriber::STATUS_SUBSCRIBED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSynchronizeUserKeepsStatusOfOldSubscriber() {
|
||||||
|
$randomNumber = rand();
|
||||||
|
$subscriber = Subscriber::createOrUpdate([
|
||||||
|
'email' => 'user-sync-test' . $randomNumber . '@example.com',
|
||||||
|
'status' => Subscriber::STATUS_SUBSCRIBED,
|
||||||
|
'wp_user_id' => null,
|
||||||
|
]);
|
||||||
|
$id = $this->insertUser($randomNumber);
|
||||||
|
WP::synchronizeUser($id);
|
||||||
|
$dbSubscriber = Subscriber::where('wp_user_id', $id)->findOne();
|
||||||
|
expect($dbSubscriber->status)->equals($subscriber->status);
|
||||||
|
}
|
||||||
|
|
||||||
public function testSynchronizeUserStatusIsSubscribedForNewUserWithSignUpConfirmationDisabled() {
|
public function testSynchronizeUserStatusIsSubscribedForNewUserWithSignUpConfirmationDisabled() {
|
||||||
$this->settings->set('signup_confirmation', ['enabled' => '0']);
|
$this->settings->set('signup_confirmation', ['enabled' => '0']);
|
||||||
$randomNumber = rand();
|
$randomNumber = rand();
|
||||||
|
Reference in New Issue
Block a user