Remove freemail override on MSS activation
[MAILPOET-2594]
This commit is contained in:
committed by
Jack Kitterhing
parent
490a72aed3
commit
c7d7d88028
@ -34,7 +34,6 @@ class Settings extends APIEndpoint {
|
|||||||
'global' => AccessControl::PERMISSION_MANAGE_SETTINGS,
|
'global' => AccessControl::PERMISSION_MANAGE_SETTINGS,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
SettingsController $settings,
|
SettingsController $settings,
|
||||||
Bridge $bridge,
|
Bridge $bridge,
|
||||||
@ -84,6 +83,12 @@ class Settings extends APIEndpoint {
|
|||||||
$this->onInactiveSubscribersIntervalChange();
|
$this->onInactiveSubscribersIntervalChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$oldSendingMethod = $oldSettings['mta_group'];
|
||||||
|
$newSendingMethod = $newSettings['mta_group'];
|
||||||
|
if (($oldSendingMethod !== $newSendingMethod) && ($newSendingMethod === 'mailpoet')) {
|
||||||
|
$this->onMSSActivate($newSettings);
|
||||||
|
}
|
||||||
|
|
||||||
// Sync WooCommerce Customers list
|
// Sync WooCommerce Customers list
|
||||||
$oldSubscribeOldWoocommerceCustomers = isset($oldSettings['mailpoet_subscribe_old_woocommerce_customers']['enabled'])
|
$oldSubscribeOldWoocommerceCustomers = isset($oldSettings['mailpoet_subscribe_old_woocommerce_customers']['enabled'])
|
||||||
? $oldSettings['mailpoet_subscribe_old_woocommerce_customers']['enabled']
|
? $oldSettings['mailpoet_subscribe_old_woocommerce_customers']['enabled']
|
||||||
@ -127,4 +132,21 @@ class Settings extends APIEndpoint {
|
|||||||
$task->scheduledAt = $datetime->subMinute();
|
$task->scheduledAt = $datetime->subMinute();
|
||||||
$task->save();
|
$task->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function onMSSActivate($newSettings) {
|
||||||
|
// see mailpoet/assets/js/src/wizard/create_sender_settings.jsx:freeAddress
|
||||||
|
$domain = str_replace('www.', '', $_SERVER['HTTP_HOST']);
|
||||||
|
if (
|
||||||
|
isset($newSettings['sender']['address'])
|
||||||
|
&& !empty($newSettings['reply_to']['address'])
|
||||||
|
&& ($newSettings['sender']['address'] === ('wordpress@' . $domain))
|
||||||
|
) {
|
||||||
|
$sender = [
|
||||||
|
'name' => $newSettings['reply_to']['name'] ?? '',
|
||||||
|
'address' => $newSettings['reply_to']['address'],
|
||||||
|
];
|
||||||
|
$this->settings->set('sender', $sender);
|
||||||
|
$this->settings->set('reply_to', null);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -99,6 +99,22 @@ class SettingsTest extends \MailPoetTest {
|
|||||||
expect($task->scheduledAt)->lessThan(Carbon::now());
|
expect($task->scheduledAt)->lessThan(Carbon::now());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testItRemovesFreeAddressOverrideOnMSSActivation() {
|
||||||
|
$_SERVER['HTTP_HOST'] = 'www.mailpoet.com';
|
||||||
|
|
||||||
|
$this->settings->set('sender', ['address' => 'wordpress@mailpoet.com']);
|
||||||
|
$this->settings->set('reply_to', ['address' => 'johndoeexampletestnonexistinghopefullyfreemail@gmail.com']);
|
||||||
|
$this->settings->set('mta_group', 'non-mss-sending-method');
|
||||||
|
|
||||||
|
|
||||||
|
$newSettings = ['mta_group' => 'mailpoet'];
|
||||||
|
$this->endpoint->set($newSettings);
|
||||||
|
|
||||||
|
$this->settings->resetCache();
|
||||||
|
expect($this->settings->get('sender')['address'])->equals('johndoeexampletestnonexistinghopefullyfreemail@gmail.com');
|
||||||
|
expect($this->settings->get('reply_to'))->isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
public function _after() {
|
public function _after() {
|
||||||
$this->diContainer->get(SettingsRepository::class)->truncate();
|
$this->diContainer->get(SettingsRepository::class)->truncate();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user