diff --git a/lib/Config/Populator.php b/lib/Config/Populator.php index 992ef87b68..4b2b7d751c 100644 --- a/lib/Config/Populator.php +++ b/lib/Config/Populator.php @@ -1,12 +1,12 @@ models); $this->createDefaultSegments(); + $this->createDefaultForm(); $this->createDefaultSettings(); $this->createMailPoetPage(); $this->createSourceForSubscribers(); @@ -195,13 +197,28 @@ class Populator { // Default segment if(Segment::where('type', 'default')->count() === 0) { - $default_segment = Segment::create(); - $default_segment->hydrate(array( + $this->default_segment = Segment::create(); + $this->default_segment->hydrate([ 'name' => __('My First List', 'mailpoet'), 'description' => __('This list is automatically created when you install MailPoet.', 'mailpoet') - )); - $default_segment->save(); + ]); + $this->default_segment->save(); + } + } + + private function createDefaultForm() { + if(Form::count() === 0) { + $factory = new DefaultForm(); + if(!$this->default_segment) { + $this->default_segment = Segment::where('type', 'default')->orderByAsc('id')->limit(1)->findOne(); + } + Form::createOrUpdate([ + 'name' => $factory->getName(), + 'body' => serialize($factory->getBody()), + 'settings' => serialize($factory->getSettings($this->default_segment)), + 'styles' => $factory->getStyles(), + ]); } } diff --git a/lib/Config/PopulatorData/DefaultForm.php b/lib/Config/PopulatorData/DefaultForm.php new file mode 100644 index 0000000000..120f8ca12f --- /dev/null +++ b/lib/Config/PopulatorData/DefaultForm.php @@ -0,0 +1,72 @@ + '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' => 'html', + 'name' => _x('Custom text or HTML', 'Form label', 'mailpoet'), + 'id' => 'html', + 'unique' => '0', + 'static' => '0', + 'params' => [ + 'text' => __('We keep your data private and share your data only with third parties that make this service possible. Read our Privacy Policy.', 'mailpoet'), + 'nl2br' => '0', + ], + 'position' => '3', + ], + [ + 'type' => 'submit', + 'name' => _x('Submit', 'Form label', 'mailpoet'), + 'id' => 'submit', + 'unique' => '0', + 'static' => '1', + 'params' => ['label' => __('Subscribe!', 'Form label', 'mailpoet')], + 'position' => '4', + ], + ]; + } + + public function getSettings(Segment $default_segment) { + return [ + 'segments' => [$default_segment->id()], + 'on_success' => 'message', + 'success_message' => __('Check your inbox or spam folder to confirm your subscription.', 'mailpoet'), + 'success_page' => '5', + 'segments_selected_by' => 'admin', + ]; + } + + public function getStyles() { + return Styles::$default_styles; + } + +} diff --git a/tests/integration/Config/MP2MigratorTest.php b/tests/integration/Config/MP2MigratorTest.php index 0f0029a56e..71c2e0cedb 100644 --- a/tests/integration/Config/MP2MigratorTest.php +++ b/tests/integration/Config/MP2MigratorTest.php @@ -447,7 +447,7 @@ class MP2MigratorTest extends \MailPoetTest { $this->initImport(); $this->loadMP2Fixtures(); $this->invokeMethod($this->MP2Migrator, 'importForms'); - expect(Form::count())->equals(2); + expect(Form::count())->equals(3); // Check a form data $this->initImport(); @@ -495,7 +495,7 @@ class MP2MigratorTest extends \MailPoetTest { )); $this->invokeMethod($this->MP2Migrator, 'importForms'); $table = MP_FORMS_TABLE; - $form = $wpdb->get_row("SELECT * FROM $table WHERE id=" . 1); + $form = $wpdb->get_row("SELECT * FROM $table WHERE id=" . 2); expect($form->name)->equals($name); $settings = unserialize(($form->settings)); expect($settings['on_success'])->equals('message');