Remove default form

[MAILPOET-3238]
This commit is contained in:
Rostislav Wolny
2020-10-26 12:34:32 +01:00
committed by Veljko V
parent 5d20056e28
commit 0bbe65fab7
11 changed files with 9 additions and 109 deletions

View File

@ -11,7 +11,6 @@ use MailPoet\Cron\Workers\SubscriberLinkTokens;
use MailPoet\Cron\Workers\UnsubscribeTokens; use MailPoet\Cron\Workers\UnsubscribeTokens;
use MailPoet\Entities\FormEntity; use MailPoet\Entities\FormEntity;
use MailPoet\Entities\UserFlagEntity; use MailPoet\Entities\UserFlagEntity;
use MailPoet\Form\FormFactory;
use MailPoet\Form\FormsRepository; use MailPoet\Form\FormsRepository;
use MailPoet\Mailer\MailerLog; use MailPoet\Mailer\MailerLog;
use MailPoet\Models\Form; use MailPoet\Models\Form;
@ -48,8 +47,6 @@ class Populator {
/** @var ReferralDetector */ /** @var ReferralDetector */
private $referralDetector; private $referralDetector;
const TEMPLATES_NAMESPACE = '\MailPoet\Config\PopulatorData\Templates\\'; const TEMPLATES_NAMESPACE = '\MailPoet\Config\PopulatorData\Templates\\';
/** @var FormFactory */
private $formFactory;
/** @var FormsRepository */ /** @var FormsRepository */
private $formsRepository; private $formsRepository;
@ -58,14 +55,12 @@ class Populator {
WPFunctions $wp, WPFunctions $wp,
Captcha $captcha, Captcha $captcha,
ReferralDetector $referralDetector, ReferralDetector $referralDetector,
FormsRepository $formsRepository, FormsRepository $formsRepository
FormFactory $formFactory
) { ) {
$this->settings = $settings; $this->settings = $settings;
$this->wp = $wp; $this->wp = $wp;
$this->captcha = $captcha; $this->captcha = $captcha;
$this->referralDetector = $referralDetector; $this->referralDetector = $referralDetector;
$this->formFactory = $formFactory;
$this->prefix = Env::$dbPrefix; $this->prefix = Env::$dbPrefix;
$this->models = [ $this->models = [
'newsletter_option_fields', 'newsletter_option_fields',
@ -156,8 +151,7 @@ class Populator {
array_map([$this, 'populate'], $this->models); array_map([$this, 'populate'], $this->models);
$defaultSegment = $this->createDefaultSegment(); $this->createDefaultSegment();
$this->createDefaultForm($defaultSegment);
$this->createDefaultSettings(); $this->createDefaultSettings();
$this->createDefaultUsersFlags(); $this->createDefaultUsersFlags();
$this->createMailPoetPage(); $this->createMailPoetPage();
@ -360,10 +354,6 @@ class Populator {
return $defaultSegment; return $defaultSegment;
} }
private function createDefaultForm(Segment $defaultSegment) {
$this->formFactory->ensureDefaultFormExists((int)$defaultSegment->id());
}
protected function newsletterOptionFields() { protected function newsletterOptionFields() {
$optionFields = [ $optionFields = [
[ [

View File

@ -44,20 +44,6 @@ class FormFactory {
return $this->createFormFromTemplate(TemplateRepository::INITIAL_FORM_TEMPLATE); return $this->createFormFromTemplate(TemplateRepository::INITIAL_FORM_TEMPLATE);
} }
/**
* @param int $defaultSegmentId
* @return FormEntity|null
*/
public function ensureDefaultFormExists(int $defaultSegmentId) {
if ($this->formRepository->count()) {
return null;
}
return $this->createFormFromTemplate(
TemplateRepository::DEFAULT_FORM_TEMPLATE,
['segments' => [(string)$defaultSegmentId]]
);
}
private function getDefaultSuccessMessage() { private function getDefaultSuccessMessage() {
if ($this->settings->get('signup_confirmation.enabled')) { if ($this->settings->get('signup_confirmation.enabled')) {
return __('Check your inbox or spam folder to confirm your subscription.', 'mailpoet'); return __('Check your inbox or spam folder to confirm your subscription.', 'mailpoet');

View File

@ -2,7 +2,6 @@
namespace MailPoet\Form\Templates; namespace MailPoet\Form\Templates;
use MailPoet\Form\Templates\Templates\DefaultForm;
use MailPoet\Form\Templates\Templates\InitialForm; use MailPoet\Form\Templates\Templates\InitialForm;
use MailPoet\Form\Templates\Templates\Template10BelowPages; use MailPoet\Form\Templates\Templates\Template10BelowPages;
use MailPoet\Form\Templates\Templates\Template10FixedBar; use MailPoet\Form\Templates\Templates\Template10FixedBar;
@ -70,7 +69,6 @@ use MailPoet\WP\Functions as WPFunctions;
class TemplateRepository { class TemplateRepository {
const INITIAL_FORM_TEMPLATE = InitialForm::ID; const INITIAL_FORM_TEMPLATE = InitialForm::ID;
const DEFAULT_FORM_TEMPLATE = DefaultForm::ID;
/** @var CdnAssetUrl */ /** @var CdnAssetUrl */
private $cdnAssetUrl; private $cdnAssetUrl;
@ -80,7 +78,6 @@ class TemplateRepository {
private $templates = [ private $templates = [
InitialForm::ID => InitialForm::class, InitialForm::ID => InitialForm::class,
DefaultForm::ID => DefaultForm::class,
Template1BelowPages::ID => Template1BelowPages::class, Template1BelowPages::ID => Template1BelowPages::class,
Template1FixedBar::ID => Template1FixedBar::class, Template1FixedBar::ID => Template1FixedBar::class,
Template1Popup::ID => Template1Popup::class, Template1Popup::ID => Template1Popup::class,

View File

@ -1,52 +0,0 @@
<?php
namespace MailPoet\Form\Templates\Templates;
use MailPoet\Form\Templates\FormTemplate;
/**
* Template for default form created on plugin activation
*/
class DefaultForm extends FormTemplate {
const ID = 'default_form';
public function getName(): string {
return _x('My First Form', 'default name of form (GDPR friendly) to capture emails', 'mailpoet');
}
public function getThumbnailUrl(): string {
return '';
}
public function getBody(): array {
return [
[
'type' => 'text',
'name' => _x('First name', 'Form label', 'mailpoet'),
'id' => 'first_name',
'unique' => '1',
'static' => '0',
'params' => ['label' => _x('First name', 'Form label', 'mailpoet')],
'position' => '1',
],
[
'type' => 'text',
'name' => _x('Email', 'Form label', 'mailpoet'),
'id' => 'email',
'unique' => '0',
'static' => '1',
'params' => ['label' => _x('Email', 'Form label', 'mailpoet'), 'required' => 'true'],
'position' => '2',
],
[
'type' => 'submit',
'name' => _x('Submit', 'Form label', 'mailpoet'),
'id' => 'submit',
'unique' => '0',
'static' => '1',
'params' => ['label' => _x('Subscribe!', 'Form label', 'mailpoet')],
'position' => '3',
],
];
}
}

View File

@ -8,7 +8,6 @@ use MailPoet\API\JSON\Response as APIResponse;
use MailPoet\API\JSON\v1\Setup; use MailPoet\API\JSON\v1\Setup;
use MailPoet\Config\Activator; use MailPoet\Config\Activator;
use MailPoet\Config\Populator; use MailPoet\Config\Populator;
use MailPoet\Form\FormFactory;
use MailPoet\Form\FormsRepository; use MailPoet\Form\FormsRepository;
use MailPoet\Referrals\ReferralDetector; use MailPoet\Referrals\ReferralDetector;
use MailPoet\Settings\SettingsController; use MailPoet\Settings\SettingsController;
@ -35,8 +34,7 @@ class SetupTest extends \MailPoetTest {
$wp, $wp,
new Captcha(), new Captcha(),
$referralDetector, $referralDetector,
$this->diContainer->get(FormsRepository::class), $this->diContainer->get(FormsRepository::class)
$this->diContainer->get(FormFactory::class)
); );
$router = new Setup($wp, new Activator($settings, $populator)); $router = new Setup($wp, new Activator($settings, $populator));
$response = $router->reset(); $response = $router->reset();

View File

@ -457,7 +457,7 @@ class MP2MigratorTest extends \MailPoetTest {
$this->initImport(); $this->initImport();
$this->loadMP2Fixtures(); $this->loadMP2Fixtures();
$this->invokeMethod($this->MP2Migrator, 'importForms'); $this->invokeMethod($this->MP2Migrator, 'importForms');
expect(Form::count())->equals(3); expect(Form::count())->equals(2);
// Check a form data // Check a form data
$this->initImport(); $this->initImport();
@ -505,7 +505,7 @@ class MP2MigratorTest extends \MailPoetTest {
]); ]);
$this->invokeMethod($this->MP2Migrator, 'importForms'); $this->invokeMethod($this->MP2Migrator, 'importForms');
$table = MP_FORMS_TABLE; $table = MP_FORMS_TABLE;
$form = $wpdb->get_row("SELECT * FROM $table WHERE id=" . 2); $form = $wpdb->get_row("SELECT * FROM $table WHERE id=" . 1);
expect($form->name)->equals($name); expect($form->name)->equals($name);
$settings = unserialize(($form->settings)); $settings = unserialize(($form->settings));
expect($settings['on_success'])->equals('message'); expect($settings['on_success'])->equals('message');

View File

@ -14,7 +14,6 @@ use MailPoet\Cron\Workers\SendingQueue\Tasks\Newsletter as NewsletterTask;
use MailPoet\Cron\Workers\StatsNotifications\Scheduler as StatsNotificationsScheduler; use MailPoet\Cron\Workers\StatsNotifications\Scheduler as StatsNotificationsScheduler;
use MailPoet\DI\ContainerWrapper; use MailPoet\DI\ContainerWrapper;
use MailPoet\Entities\NewsletterEntity; use MailPoet\Entities\NewsletterEntity;
use MailPoet\Form\FormFactory;
use MailPoet\Form\FormsRepository; use MailPoet\Form\FormsRepository;
use MailPoet\Logging\LoggerFactory; use MailPoet\Logging\LoggerFactory;
use MailPoet\Mailer\MailerLog; use MailPoet\Mailer\MailerLog;
@ -80,8 +79,7 @@ class SendingQueueTest extends \MailPoetTest {
WPFunctions::get(), WPFunctions::get(),
new Captcha, new Captcha,
$referralDetector, $referralDetector,
$this->diContainer->get(FormsRepository::class), $this->diContainer->get(FormsRepository::class)
$this->diContainer->get(FormFactory::class)
); );
$populator->up(); $populator->up();
$this->subscriber = Subscriber::create(); $this->subscriber = Subscriber::create();

View File

@ -6,7 +6,6 @@ use Codeception\Stub;
use Codeception\Stub\Expected; use Codeception\Stub\Expected;
use MailPoet\Config\Populator; use MailPoet\Config\Populator;
use MailPoet\Cron\Workers\SendingQueue\Tasks\Mailer as MailerTask; use MailPoet\Cron\Workers\SendingQueue\Tasks\Mailer as MailerTask;
use MailPoet\Form\FormFactory;
use MailPoet\Form\FormsRepository; use MailPoet\Form\FormsRepository;
use MailPoet\Mailer\Mailer; use MailPoet\Mailer\Mailer;
use MailPoet\Models\Subscriber; use MailPoet\Models\Subscriber;
@ -35,8 +34,7 @@ class MailerTest extends \MailPoetTest {
WPFunctions::get(), WPFunctions::get(),
new Captcha, new Captcha,
$referralDetector, $referralDetector,
$this->diContainer->get(FormsRepository::class), $this->diContainer->get(FormsRepository::class)
$this->diContainer->get(FormFactory::class)
); );
$populator->up(); $populator->up();
$this->mailerTask = new MailerTask(); $this->mailerTask = new MailerTask();

View File

@ -70,17 +70,6 @@ class FormFactoryTest extends \MailPoetTest {
expect($formSettings['segments'])->equals([1, 2, 3]); expect($formSettings['segments'])->equals([1, 2, 3]);
} }
public function testItCanEnsureDefaultFormExists() {
$this->cleanup();
$formEntity = $this->formFactory->ensureDefaultFormExists(2);
assert($formEntity instanceof FormEntity);
$formSettings = $formEntity->getSettings() ?? [];
expect($formSettings['segments'])->equals(['2']);
// Doesn't create any form if some exists
$formEntity = $this->formFactory->ensureDefaultFormExists(2);
expect($formEntity)->null();
}
public function _after() { public function _after() {
parent::_after(); parent::_after();
$this->cleanup(); $this->cleanup();

View File

@ -3,7 +3,6 @@
namespace MailPoet\Test\Newsletter; namespace MailPoet\Test\Newsletter;
use MailPoet\Config\Populator; use MailPoet\Config\Populator;
use MailPoet\Form\FormFactory;
use MailPoet\Form\FormsRepository; use MailPoet\Form\FormsRepository;
use MailPoet\Models\CustomField; use MailPoet\Models\CustomField;
use MailPoet\Models\Newsletter; use MailPoet\Models\Newsletter;
@ -46,8 +45,7 @@ class ShortcodesTest extends \MailPoetTest {
WPFunctions::get(), WPFunctions::get(),
new Captcha, new Captcha,
$referralDetector, $referralDetector,
$this->diContainer->get(FormsRepository::class), $this->diContainer->get(FormsRepository::class)
$this->diContainer->get(FormFactory::class)
); );
$populator->up(); $populator->up();
$this->wPUser = $this->_createWPUser(); $this->wPUser = $this->_createWPUser();

View File

@ -3,7 +3,6 @@
namespace MailPoet\Test\Subscription; namespace MailPoet\Test\Subscription;
use MailPoet\Config\Populator; use MailPoet\Config\Populator;
use MailPoet\Form\FormFactory;
use MailPoet\Form\FormsRepository; use MailPoet\Form\FormsRepository;
use MailPoet\Models\Subscriber; use MailPoet\Models\Subscriber;
use MailPoet\Referrals\ReferralDetector; use MailPoet\Referrals\ReferralDetector;
@ -32,8 +31,7 @@ class UrlTest extends \MailPoetTest {
WPFunctions::get(), WPFunctions::get(),
new Captcha, new Captcha,
$referralDetector, $referralDetector,
$this->diContainer->get(FormsRepository::class), $this->diContainer->get(FormsRepository::class)
$this->diContainer->get(FormFactory::class)
); );
$populator->up(); $populator->up();
$this->url = new SubscriptionUrlFactory(WPFunctions::get(), $this->settings, new LinkTokens); $this->url = new SubscriptionUrlFactory(WPFunctions::get(), $this->settings, new LinkTokens);