Use Doctrine for update success message in Settings
[MAILPOET-3034]
This commit is contained in:
@ -7,7 +7,6 @@ use MailPoet\API\JSON\Error as APIError;
|
||||
use MailPoet\Config\AccessControl;
|
||||
use MailPoet\Config\ServicesChecker;
|
||||
use MailPoet\Mailer\MailerLog;
|
||||
use MailPoet\Models\Form;
|
||||
use MailPoet\Services\AuthorizedEmailsController;
|
||||
use MailPoet\Services\Bridge;
|
||||
use MailPoet\Settings\SettingsController;
|
||||
@ -76,7 +75,7 @@ class Settings extends APIEndpoint {
|
||||
|
||||
$this->authorizedEmailsController->onSettingsSave($settings);
|
||||
if ($signupConfirmation !== $this->settings->get('signup_confirmation.enabled')) {
|
||||
Form::updateSuccessMessages();
|
||||
$this->settings->updateSuccessMessages();
|
||||
}
|
||||
return $this->successResponse($this->settings->getAll());
|
||||
}
|
||||
|
@ -13,7 +13,6 @@ use MailPoet\Entities\FormEntity;
|
||||
use MailPoet\Entities\UserFlagEntity;
|
||||
use MailPoet\Form\FormsRepository;
|
||||
use MailPoet\Mailer\MailerLog;
|
||||
use MailPoet\Models\Form;
|
||||
use MailPoet\Models\Newsletter;
|
||||
use MailPoet\Models\NewsletterLink;
|
||||
use MailPoet\Models\ScheduledTask;
|
||||
@ -664,7 +663,7 @@ class Populator {
|
||||
if (version_compare($this->settings->get('db_version', '3.23.2'), '3.23.1', '>')) {
|
||||
return;
|
||||
}
|
||||
Form::updateSuccessMessages();
|
||||
$this->settings->updateSuccessMessages();
|
||||
}
|
||||
|
||||
private function enableStatsNotificationsForAutomatedEmails() {
|
||||
|
@ -6,7 +6,9 @@ use MailPoet\Cron\CronTrigger;
|
||||
use MailPoet\Cron\Workers\InactiveSubscribers;
|
||||
use MailPoet\Cron\Workers\WooCommerceSync;
|
||||
use MailPoet\DI\ContainerWrapper;
|
||||
use MailPoet\Entities\FormEntity;
|
||||
use MailPoet\Entities\ScheduledTaskEntity;
|
||||
use MailPoet\Form\FormsRepository;
|
||||
use MailPoet\Newsletter\Sending\ScheduledTasksRepository;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
use MailPoetVendor\Carbon\Carbon;
|
||||
@ -31,14 +33,19 @@ class SettingsController {
|
||||
/** @var ScheduledTasksRepository */
|
||||
private $tasksRepository;
|
||||
|
||||
/** @var FormsRepository */
|
||||
private $formsRepository;
|
||||
|
||||
private static $instance;
|
||||
|
||||
public function __construct(
|
||||
SettingsRepository $settingsRepository,
|
||||
ScheduledTasksRepository $scheduledTasksRepository
|
||||
ScheduledTasksRepository $scheduledTasksRepository,
|
||||
FormsRepository $formsRepository
|
||||
) {
|
||||
$this->settingsRepository = $settingsRepository;
|
||||
$this->tasksRepository = $scheduledTasksRepository;
|
||||
$this->formsRepository = $formsRepository;
|
||||
}
|
||||
|
||||
public function get($key, $default = null) {
|
||||
@ -162,6 +169,32 @@ class SettingsController {
|
||||
$this->tasksRepository->flush();
|
||||
}
|
||||
|
||||
public function updateSuccessMessages(): void {
|
||||
$rightMessage = $this->getDefaultSuccessMessage();
|
||||
$wrongMessage = (
|
||||
$rightMessage === __('Check your inbox or spam folder to confirm your subscription.', 'mailpoet')
|
||||
? __('You’ve been successfully subscribed to our newsletter!', 'mailpoet')
|
||||
: __('Check your inbox or spam folder to confirm your subscription.', 'mailpoet')
|
||||
);
|
||||
/** @var FormEntity[] $forms */
|
||||
$forms = $this->formsRepository->findAll();
|
||||
foreach ($forms as $form) {
|
||||
$settings = $form->getSettings();
|
||||
if (isset($settings['success_message']) && $settings['success_message'] === $wrongMessage) {
|
||||
$settings['success_message'] = $rightMessage;
|
||||
$form->setSettings($settings);
|
||||
$this->settingsRepository->flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getDefaultSuccessMessage(): string {
|
||||
if ($this->get('signup_confirmation.enabled')) {
|
||||
return __('Check your inbox or spam folder to confirm your subscription.', 'mailpoet');
|
||||
}
|
||||
return __('You’ve been successfully subscribed to our newsletter!', 'mailpoet');
|
||||
}
|
||||
|
||||
private function createScheduledTask(string $type): ScheduledTaskEntity {
|
||||
$task = new ScheduledTaskEntity();
|
||||
$task->setType($type);
|
||||
|
@ -2,21 +2,27 @@
|
||||
|
||||
namespace MailPoet\Test\DataFactories;
|
||||
|
||||
use MailPoet\DI\ContainerWrapper;
|
||||
use MailPoet\Entities\SegmentEntity;
|
||||
use MailPoet\Models\Form as FormModel;
|
||||
use MailPoet\Settings\SettingsController;
|
||||
use MailPoetVendor\Carbon\Carbon;
|
||||
|
||||
class Form {
|
||||
|
||||
/** @var SettingsController */
|
||||
private $settingsController;
|
||||
|
||||
private $data;
|
||||
|
||||
public function __construct() {
|
||||
$this->settingsController = ContainerWrapper::getInstance()->get(SettingsController::class);
|
||||
$this->data = [
|
||||
'name' => 'New form',
|
||||
'body' => 'a:2:{i:0;a:5:{s:2:"id";s:5:"email";s:4:"name";s:5:"Email";s:4:"type";s:4:"text";s:6:"static";b:1;s:6:"params";a:2:{s:5:"label";s:5:"Email";s:8:"required";b:1;}}i:1;a:5:{s:2:"id";s:6:"submit";s:4:"name";s:6:"Submit";s:4:"type";s:6:"submit";s:6:"static";b:1;s:6:"params";a:1:{s:5:"label";s:10:"Subscribe!";}}}',
|
||||
'settings' => [
|
||||
'on_success' => 'message',
|
||||
'success_message' => FormModel::getDefaultSuccessMessage(),
|
||||
'success_message' => $this->settingsController->getDefaultSuccessMessage(),
|
||||
'segments' => [2],
|
||||
'segments_selected_by' => 'admin',
|
||||
],
|
||||
@ -125,7 +131,7 @@ class Form {
|
||||
}
|
||||
|
||||
public function withDefaultSuccessMessage() {
|
||||
FormModel::updateSuccessMessages();
|
||||
$this->settingsController->updateSuccessMessages();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2,7 +2,8 @@
|
||||
|
||||
use Facebook\WebDriver\Exception\UnrecognizedExceptionException;
|
||||
use Facebook\WebDriver\WebDriverKeys;
|
||||
use MailPoet\Models\Form as FormModel;
|
||||
use MailPoet\DI\ContainerWrapper;
|
||||
use MailPoet\Settings\SettingsController;
|
||||
use MailPoet\Test\DataFactories\Form;
|
||||
use MailPoet\Test\DataFactories\Segment;
|
||||
use MailPoet\Test\DataFactories\Subscriber;
|
||||
@ -164,10 +165,13 @@ class AcceptanceTester extends \Codeception\Actor {
|
||||
$i->cli(['widget', 'add', 'mailpoet_form', 'sidebar-1', '2', "--form=$form->id", '--title=Subscribe to Our Newsletter']);
|
||||
|
||||
// subscribe
|
||||
/** @var SettingsController $settingsController */
|
||||
$settingsController = ContainerWrapper::getInstance()->get(SettingsController::class);
|
||||
|
||||
$i->amOnUrl(self::WP_URL);
|
||||
$i->fillField('[data-automation-id="form_email"]', 'subscriber@example.com');
|
||||
$i->click('[data-automation-id="subscribe-submit-button"]');
|
||||
$i->waitForText(FormModel::getDefaultSuccessMessage(), 30, '.mailpoet_validate_success');
|
||||
$i->waitForText($settingsController->getDefaultSuccessMessage(), 30, '.mailpoet_validate_success');
|
||||
$i->seeNoJSErrors();
|
||||
}
|
||||
|
||||
|
@ -153,7 +153,7 @@ class FormTest extends \MailPoetTest {
|
||||
'settings' => ['success_message' => 'Thanks for joining us!'],
|
||||
]);
|
||||
$this->settings->set('signup_confirmation.enabled', '0');
|
||||
Form::updateSuccessMessages();
|
||||
$this->settings->updateSuccessMessages();
|
||||
$default = Form::findOne($default->id);
|
||||
$custom = Form::findOne($custom->id);
|
||||
assert($default instanceof Form);
|
||||
@ -174,7 +174,7 @@ class FormTest extends \MailPoetTest {
|
||||
'settings' => ['success_message' => 'Thanks for joining us!'],
|
||||
]);
|
||||
$this->settings->set('signup_confirmation.enabled', '1');
|
||||
Form::updateSuccessMessages();
|
||||
$this->settings->updateSuccessMessages();
|
||||
$default = Form::findOne($default->id);
|
||||
$custom = Form::findOne($custom->id);
|
||||
assert($default instanceof Form);
|
||||
|
Reference in New Issue
Block a user