Remove default form
[MAILPOET-3238]
This commit is contained in:
committed by
Veljko V
parent
5d20056e28
commit
0bbe65fab7
@ -11,7 +11,6 @@ use MailPoet\Cron\Workers\SubscriberLinkTokens;
|
||||
use MailPoet\Cron\Workers\UnsubscribeTokens;
|
||||
use MailPoet\Entities\FormEntity;
|
||||
use MailPoet\Entities\UserFlagEntity;
|
||||
use MailPoet\Form\FormFactory;
|
||||
use MailPoet\Form\FormsRepository;
|
||||
use MailPoet\Mailer\MailerLog;
|
||||
use MailPoet\Models\Form;
|
||||
@ -48,8 +47,6 @@ class Populator {
|
||||
/** @var ReferralDetector */
|
||||
private $referralDetector;
|
||||
const TEMPLATES_NAMESPACE = '\MailPoet\Config\PopulatorData\Templates\\';
|
||||
/** @var FormFactory */
|
||||
private $formFactory;
|
||||
/** @var FormsRepository */
|
||||
private $formsRepository;
|
||||
|
||||
@ -58,14 +55,12 @@ class Populator {
|
||||
WPFunctions $wp,
|
||||
Captcha $captcha,
|
||||
ReferralDetector $referralDetector,
|
||||
FormsRepository $formsRepository,
|
||||
FormFactory $formFactory
|
||||
FormsRepository $formsRepository
|
||||
) {
|
||||
$this->settings = $settings;
|
||||
$this->wp = $wp;
|
||||
$this->captcha = $captcha;
|
||||
$this->referralDetector = $referralDetector;
|
||||
$this->formFactory = $formFactory;
|
||||
$this->prefix = Env::$dbPrefix;
|
||||
$this->models = [
|
||||
'newsletter_option_fields',
|
||||
@ -156,8 +151,7 @@ class Populator {
|
||||
|
||||
array_map([$this, 'populate'], $this->models);
|
||||
|
||||
$defaultSegment = $this->createDefaultSegment();
|
||||
$this->createDefaultForm($defaultSegment);
|
||||
$this->createDefaultSegment();
|
||||
$this->createDefaultSettings();
|
||||
$this->createDefaultUsersFlags();
|
||||
$this->createMailPoetPage();
|
||||
@ -360,10 +354,6 @@ class Populator {
|
||||
return $defaultSegment;
|
||||
}
|
||||
|
||||
private function createDefaultForm(Segment $defaultSegment) {
|
||||
$this->formFactory->ensureDefaultFormExists((int)$defaultSegment->id());
|
||||
}
|
||||
|
||||
protected function newsletterOptionFields() {
|
||||
$optionFields = [
|
||||
[
|
||||
|
@ -44,20 +44,6 @@ class FormFactory {
|
||||
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() {
|
||||
if ($this->settings->get('signup_confirmation.enabled')) {
|
||||
return __('Check your inbox or spam folder to confirm your subscription.', 'mailpoet');
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
namespace MailPoet\Form\Templates;
|
||||
|
||||
use MailPoet\Form\Templates\Templates\DefaultForm;
|
||||
use MailPoet\Form\Templates\Templates\InitialForm;
|
||||
use MailPoet\Form\Templates\Templates\Template10BelowPages;
|
||||
use MailPoet\Form\Templates\Templates\Template10FixedBar;
|
||||
@ -70,7 +69,6 @@ use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
class TemplateRepository {
|
||||
const INITIAL_FORM_TEMPLATE = InitialForm::ID;
|
||||
const DEFAULT_FORM_TEMPLATE = DefaultForm::ID;
|
||||
|
||||
/** @var CdnAssetUrl */
|
||||
private $cdnAssetUrl;
|
||||
@ -80,7 +78,6 @@ class TemplateRepository {
|
||||
|
||||
private $templates = [
|
||||
InitialForm::ID => InitialForm::class,
|
||||
DefaultForm::ID => DefaultForm::class,
|
||||
Template1BelowPages::ID => Template1BelowPages::class,
|
||||
Template1FixedBar::ID => Template1FixedBar::class,
|
||||
Template1Popup::ID => Template1Popup::class,
|
||||
|
@ -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',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
@ -8,7 +8,6 @@ use MailPoet\API\JSON\Response as APIResponse;
|
||||
use MailPoet\API\JSON\v1\Setup;
|
||||
use MailPoet\Config\Activator;
|
||||
use MailPoet\Config\Populator;
|
||||
use MailPoet\Form\FormFactory;
|
||||
use MailPoet\Form\FormsRepository;
|
||||
use MailPoet\Referrals\ReferralDetector;
|
||||
use MailPoet\Settings\SettingsController;
|
||||
@ -35,8 +34,7 @@ class SetupTest extends \MailPoetTest {
|
||||
$wp,
|
||||
new Captcha(),
|
||||
$referralDetector,
|
||||
$this->diContainer->get(FormsRepository::class),
|
||||
$this->diContainer->get(FormFactory::class)
|
||||
$this->diContainer->get(FormsRepository::class)
|
||||
);
|
||||
$router = new Setup($wp, new Activator($settings, $populator));
|
||||
$response = $router->reset();
|
||||
|
@ -457,7 +457,7 @@ class MP2MigratorTest extends \MailPoetTest {
|
||||
$this->initImport();
|
||||
$this->loadMP2Fixtures();
|
||||
$this->invokeMethod($this->MP2Migrator, 'importForms');
|
||||
expect(Form::count())->equals(3);
|
||||
expect(Form::count())->equals(2);
|
||||
|
||||
// Check a form data
|
||||
$this->initImport();
|
||||
@ -505,7 +505,7 @@ class MP2MigratorTest extends \MailPoetTest {
|
||||
]);
|
||||
$this->invokeMethod($this->MP2Migrator, 'importForms');
|
||||
$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);
|
||||
$settings = unserialize(($form->settings));
|
||||
expect($settings['on_success'])->equals('message');
|
||||
|
@ -14,7 +14,6 @@ use MailPoet\Cron\Workers\SendingQueue\Tasks\Newsletter as NewsletterTask;
|
||||
use MailPoet\Cron\Workers\StatsNotifications\Scheduler as StatsNotificationsScheduler;
|
||||
use MailPoet\DI\ContainerWrapper;
|
||||
use MailPoet\Entities\NewsletterEntity;
|
||||
use MailPoet\Form\FormFactory;
|
||||
use MailPoet\Form\FormsRepository;
|
||||
use MailPoet\Logging\LoggerFactory;
|
||||
use MailPoet\Mailer\MailerLog;
|
||||
@ -80,8 +79,7 @@ class SendingQueueTest extends \MailPoetTest {
|
||||
WPFunctions::get(),
|
||||
new Captcha,
|
||||
$referralDetector,
|
||||
$this->diContainer->get(FormsRepository::class),
|
||||
$this->diContainer->get(FormFactory::class)
|
||||
$this->diContainer->get(FormsRepository::class)
|
||||
);
|
||||
$populator->up();
|
||||
$this->subscriber = Subscriber::create();
|
||||
|
@ -6,7 +6,6 @@ use Codeception\Stub;
|
||||
use Codeception\Stub\Expected;
|
||||
use MailPoet\Config\Populator;
|
||||
use MailPoet\Cron\Workers\SendingQueue\Tasks\Mailer as MailerTask;
|
||||
use MailPoet\Form\FormFactory;
|
||||
use MailPoet\Form\FormsRepository;
|
||||
use MailPoet\Mailer\Mailer;
|
||||
use MailPoet\Models\Subscriber;
|
||||
@ -35,8 +34,7 @@ class MailerTest extends \MailPoetTest {
|
||||
WPFunctions::get(),
|
||||
new Captcha,
|
||||
$referralDetector,
|
||||
$this->diContainer->get(FormsRepository::class),
|
||||
$this->diContainer->get(FormFactory::class)
|
||||
$this->diContainer->get(FormsRepository::class)
|
||||
);
|
||||
$populator->up();
|
||||
$this->mailerTask = new MailerTask();
|
||||
|
@ -70,17 +70,6 @@ class FormFactoryTest extends \MailPoetTest {
|
||||
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() {
|
||||
parent::_after();
|
||||
$this->cleanup();
|
||||
|
@ -3,7 +3,6 @@
|
||||
namespace MailPoet\Test\Newsletter;
|
||||
|
||||
use MailPoet\Config\Populator;
|
||||
use MailPoet\Form\FormFactory;
|
||||
use MailPoet\Form\FormsRepository;
|
||||
use MailPoet\Models\CustomField;
|
||||
use MailPoet\Models\Newsletter;
|
||||
@ -46,8 +45,7 @@ class ShortcodesTest extends \MailPoetTest {
|
||||
WPFunctions::get(),
|
||||
new Captcha,
|
||||
$referralDetector,
|
||||
$this->diContainer->get(FormsRepository::class),
|
||||
$this->diContainer->get(FormFactory::class)
|
||||
$this->diContainer->get(FormsRepository::class)
|
||||
);
|
||||
$populator->up();
|
||||
$this->wPUser = $this->_createWPUser();
|
||||
|
@ -3,7 +3,6 @@
|
||||
namespace MailPoet\Test\Subscription;
|
||||
|
||||
use MailPoet\Config\Populator;
|
||||
use MailPoet\Form\FormFactory;
|
||||
use MailPoet\Form\FormsRepository;
|
||||
use MailPoet\Models\Subscriber;
|
||||
use MailPoet\Referrals\ReferralDetector;
|
||||
@ -32,8 +31,7 @@ class UrlTest extends \MailPoetTest {
|
||||
WPFunctions::get(),
|
||||
new Captcha,
|
||||
$referralDetector,
|
||||
$this->diContainer->get(FormsRepository::class),
|
||||
$this->diContainer->get(FormFactory::class)
|
||||
$this->diContainer->get(FormsRepository::class)
|
||||
);
|
||||
$populator->up();
|
||||
$this->url = new SubscriptionUrlFactory(WPFunctions::get(), $this->settings, new LinkTokens);
|
||||
|
Reference in New Issue
Block a user