diff --git a/lib/API/JSON/v1/Settings.php b/lib/API/JSON/v1/Settings.php index 3b57e96487..64f9fa4ac1 100644 --- a/lib/API/JSON/v1/Settings.php +++ b/lib/API/JSON/v1/Settings.php @@ -52,7 +52,7 @@ class Settings extends APIEndpoint { } $bridge = new Bridge(); $bridge->onSettingsSave($settings); - if ($signup_confirmation != $this->settings->get('signup_confirmation.enabled')) { + if ($signup_confirmation !== $this->settings->get('signup_confirmation.enabled')) { Form::updateSuccessMessages(); } return $this->successResponse($this->settings->getAll()); diff --git a/lib/Config/Populator.php b/lib/Config/Populator.php index 66293529ac..44af17c038 100644 --- a/lib/Config/Populator.php +++ b/lib/Config/Populator.php @@ -134,7 +134,7 @@ class Populator { $this->createSourceForSubscribers(); $this->updateNewsletterCategories(); $this->scheduleInitialInactiveSubscribersCheck(); - Form::updateSuccessMessages(); + $this->updateFormsSuccessMessages(); } private function createMailPoetPage() { @@ -526,4 +526,11 @@ class Populator { $task->scheduled_at = $datetime->addHour(); $task->save(); } + + private function updateFormsSuccessMessages() { + if (version_compare($this->settings->get('db_version', '3.23.2'), '3.23.1', '>')) { + return; + } + Form::updateSuccessMessages(); + } } diff --git a/lib/Models/Form.php b/lib/Models/Form.php index 6ee06be739..486e08f05b 100644 --- a/lib/Models/Form.php +++ b/lib/Models/Form.php @@ -16,13 +16,13 @@ class Form extends Model { public static $_table = MP_FORMS_TABLE; const MESSAGE_WHEN_CONFIRMATION_ENABLED = 'Check your inbox or spam folder to confirm your subscription.'; - const MESSAGE_WHEN_CONFIRMATION_DISABLED = "You've been successfully subscribed to our newsletter!"; + const MESSAGE_WHEN_CONFIRMATION_DISABLED = "You’ve been successfully subscribed to our newsletter!"; function __construct() { parent::__construct(); $this->addValidations('name', array( - 'required' => WPFunctions::get()->__('Please specify a name.', 'mailpoet') + 'required' => __('Please specify a name.', 'mailpoet') )); } @@ -106,12 +106,12 @@ class Form extends Model { return array( array( 'name' => 'all', - 'label' => WPFunctions::get()->__('All', 'mailpoet'), + 'label' => __('All', 'mailpoet'), 'count' => Form::getPublished()->count() ), array( 'name' => 'trash', - 'label' => WPFunctions::get()->__('Trash', 'mailpoet'), + 'label' => __('Trash', 'mailpoet'), 'count' => Form::getTrashed()->count() ) ); @@ -127,9 +127,9 @@ class Form extends Model { static function getDefaultSuccessMessage() { $settings = new SettingsController; if ($settings->get('signup_confirmation.enabled')) { - return WPFunctions::get()->__(self::MESSAGE_WHEN_CONFIRMATION_ENABLED, 'mailpoet'); + return __(self::MESSAGE_WHEN_CONFIRMATION_ENABLED, 'mailpoet'); } - return WPFunctions::get()->__(self::MESSAGE_WHEN_CONFIRMATION_DISABLED, 'mailpoet'); + return __(self::MESSAGE_WHEN_CONFIRMATION_DISABLED, 'mailpoet'); } static function updateSuccessMessages() { @@ -141,10 +141,11 @@ class Form extends Model { ); $forms = self::findMany(); foreach ($forms as $form) { - $data = $form->asArray(); - if (isset($data['settings']['success_message']) && $data['settings']['success_message'] === $wrong_message) { - $data['settings']['success_message'] = $right_message; - self::createOrUpdate($data); + $settings = $form->getSettings(); + if (isset($settings['success_message']) && $settings['success_message'] === $wrong_message) { + $settings['success_message'] = $right_message; + $form->set('settings', serialize($settings)); + $form->save(); } } } diff --git a/tests/DataFactories/Form.php b/tests/DataFactories/Form.php index b7e857e483..5531e89495 100644 --- a/tests/DataFactories/Form.php +++ b/tests/DataFactories/Form.php @@ -59,4 +59,7 @@ class Form { return FormModel::createOrUpdate($this->data); } + public function withDefaultSuccessMessage() { + FormModel::updateSuccessMessages(); + } } diff --git a/tests/DataFactories/Settings.php b/tests/DataFactories/Settings.php index bca0dcf5a3..1f71a29d71 100644 --- a/tests/DataFactories/Settings.php +++ b/tests/DataFactories/Settings.php @@ -4,7 +4,6 @@ namespace MailPoet\Test\DataFactories; use MailPoet\Mailer\Mailer; use MailPoet\Settings\SettingsController; -use MailPoet\Models\Form as FormModel; class Settings { /** @var SettingsController */ @@ -33,7 +32,6 @@ class Settings { function withConfirmationEmailEnabled() { $this->settings->set('signup_confirmation.enabled', '1'); - FormModel::updateSuccessMessages(); return $this; } @@ -44,7 +42,6 @@ class Settings { function withConfirmationEmailDisabled() { $this->settings->set('signup_confirmation.enabled', ''); - FormModel::updateSuccessMessages(); return $this; } diff --git a/tests/acceptance/EditSignUpConfirmationEmailCest.php b/tests/acceptance/EditSignUpConfirmationEmailCest.php index 8d1db49909..03ccc718b2 100644 --- a/tests/acceptance/EditSignUpConfirmationEmailCest.php +++ b/tests/acceptance/EditSignUpConfirmationEmailCest.php @@ -4,8 +4,10 @@ namespace MailPoet\Test\Acceptance; use Codeception\Util\Locator; use MailPoet\Test\DataFactories\Settings; +use MailPoet\Test\DataFactories\Form; require_once __DIR__ . '/../DataFactories/Settings.php'; +require_once __DIR__ . '/../DataFactories/Form.php'; class EditSignUpConfirmationEmailCest { @@ -14,8 +16,10 @@ class EditSignUpConfirmationEmailCest { // make sure sign up confirmation is enabled $settings = new Settings(); - $settings - ->withConfirmationEmailEnabled(); + $settings->withConfirmationEmailEnabled(); + + $forms = new Form(); + $forms->withDefaultSuccessMessage(); $I->login(); $I->amOnMailPoetPage('Settings'); diff --git a/tests/acceptance/SubscribeToMultipleListsCest.php b/tests/acceptance/SubscribeToMultipleListsCest.php index 5fcf692d85..94d9363266 100644 --- a/tests/acceptance/SubscribeToMultipleListsCest.php +++ b/tests/acceptance/SubscribeToMultipleListsCest.php @@ -37,6 +37,8 @@ class SubscribeToMultipleListsCest { ->withConfirmationEmailBody() ->withConfirmationEmailSubject('Subscribe to multiple test subject'); + $form_factory->withDefaultSuccessMessage(); + //Add this form to a widget $I->createFormAndSubscribe($form); //Subscribe via that form diff --git a/tests/acceptance/SubscriptionFormCest.php b/tests/acceptance/SubscriptionFormCest.php index a6219a71c9..6589a5b20d 100644 --- a/tests/acceptance/SubscriptionFormCest.php +++ b/tests/acceptance/SubscriptionFormCest.php @@ -5,7 +5,6 @@ namespace MailPoet\Test\Acceptance; use Codeception\Util\Locator; use MailPoet\Test\DataFactories\Form; use MailPoet\Test\DataFactories\Settings; -use MailPoet\Models\Form as FormModel; require_once __DIR__ . '/../DataFactories/Settings.php'; require_once __DIR__ . '/../DataFactories/Form.php'; @@ -41,7 +40,7 @@ class SubscriptionFormCest { $I->amOnPage('/'); $I->fillField('[data-automation-id="form_email"]', $this->subscriber_email); $I->click('.mailpoet_submit'); - $I->waitForText(FormModel::MESSAGE_WHEN_CONFIRMATION_ENABLED, self::CONFIRMATION_MESSAGE_TIMEOUT, '.mailpoet_validate_success'); + $I->waitForText('Check your inbox or spam folder to confirm your subscription.', self::CONFIRMATION_MESSAGE_TIMEOUT, '.mailpoet_validate_success'); $I->seeNoJSErrors(); $I->cli('widget reset sidebar-1 --allow-root'); @@ -54,7 +53,7 @@ class SubscriptionFormCest { $I->fillField('[data-automation-id="form_email"]', $this->subscriber_email); $I->scrollTo('.mailpoet_submit'); $I->click('.mailpoet_submit'); - $I->waitForText(FormModel::MESSAGE_WHEN_CONFIRMATION_ENABLED, self::CONFIRMATION_MESSAGE_TIMEOUT, '.mailpoet_validate_success'); + $I->waitForText('Check your inbox or spam folder to confirm your subscription.', self::CONFIRMATION_MESSAGE_TIMEOUT, '.mailpoet_validate_success'); $I->seeNoJSErrors(); $I->seeCurrentUrlEquals('/form-test/'); } @@ -66,7 +65,7 @@ class SubscriptionFormCest { $I->switchToIframe('mailpoet_form_iframe'); $I->fillField('[data-automation-id="form_email"]', $this->subscriber_email); $I->click('.mailpoet_submit'); - $I->waitForText(FormModel::MESSAGE_WHEN_CONFIRMATION_ENABLED, self::CONFIRMATION_MESSAGE_TIMEOUT, '.mailpoet_validate_success'); + $I->waitForText('Check your inbox or spam folder to confirm your subscription.', self::CONFIRMATION_MESSAGE_TIMEOUT, '.mailpoet_validate_success'); $I->seeNoJSErrors(); } @@ -104,7 +103,7 @@ class SubscriptionFormCest { $I->switchToIframe('mailpoet_form_iframe'); $I->fillField('[data-automation-id="form_email"]', $this->subscriber_email); $I->click('.mailpoet_submit'); - $I->waitForText(FormModel::MESSAGE_WHEN_CONFIRMATION_DISABLED, self::CONFIRMATION_MESSAGE_TIMEOUT, '.mailpoet_validate_success'); + $I->waitForText("You’ve been successfully subscribed to our newsletter!", self::CONFIRMATION_MESSAGE_TIMEOUT, '.mailpoet_validate_success'); $I->seeNoJSErrors(); }