- Moves Import and Export under ImportExport namespace
- Cretes a single BootStrapMenu class for Import and Export - Updates tests - Adds 2 new methods to Segments model
This commit is contained in:
@ -66,8 +66,7 @@ class RoboFile extends \Robo\Tasks {
|
||||
'assets/css/src/newsletter_editor/newsletter_editor.styl',
|
||||
'assets/css/src/public.styl',
|
||||
'assets/css/src/rtl.styl',
|
||||
'assets/css/src/import.styl',
|
||||
'assets/css/src/export.styl'
|
||||
'assets/css/src/importExport.styl'
|
||||
);
|
||||
|
||||
$this->_exec(join(' ', array(
|
||||
@ -126,4 +125,4 @@ class RoboFile extends \Robo\Tasks {
|
||||
$dotenv = new Dotenv\Dotenv(__DIR__);
|
||||
$dotenv->load();
|
||||
}
|
||||
}
|
||||
}
|
@ -16,7 +16,122 @@ define(
|
||||
return;
|
||||
}
|
||||
jQuery(document).ready(function () {
|
||||
// halt operation if there are no lists with subscribers found
|
||||
if (!exportData.lists) return;
|
||||
|
||||
var subscribers_export_template = Handlebars.compile($('#mailpoet_subscribers_export_template').html());
|
||||
|
||||
//render template
|
||||
jQuery('#mailpoet_subscribers_export > div.inside').html(subscribers_export_template(exportData));
|
||||
|
||||
// define reusable variables
|
||||
var segmentsContainerElement = jQuery("#export_lists"),
|
||||
subscriberFieldsContainerElement = jQuery("#export_columns"),
|
||||
exportConfirmedOptionElement = jQuery(':radio[name="option_confirmed"]'),
|
||||
groupBySegmentOptionElement = jQuery(':checkbox[name="option_group_by_list"]'),
|
||||
nextStepElement = jQuery("a.mailpoet_export_process"),
|
||||
renderSegmentsAndFields = function (container, data) {
|
||||
if (container.data('select2')) {
|
||||
container
|
||||
.html('')
|
||||
.select2('destroy');
|
||||
}
|
||||
container
|
||||
.select2({
|
||||
data: data,
|
||||
width: '20em',
|
||||
templateResult: function (item) {
|
||||
return (item.subscriberCount > 0)
|
||||
? item.name + ' (' + item.subscriberCount + ')'
|
||||
: item.name;
|
||||
},
|
||||
templateSelection: function (item) {
|
||||
return (item.subscriberCount > 0)
|
||||
? item.name + ' (' + item.subscriberCount + ')'
|
||||
: item.name;
|
||||
}
|
||||
})
|
||||
.on('select2:selecting', function (selectEvent) {
|
||||
var selectElement = this,
|
||||
selectedOptionId = selectEvent.params.args.data.id;
|
||||
|
||||
});
|
||||
/* .change(function (event) {
|
||||
var trigger_element = this;
|
||||
|
||||
if (event.added && event.added.id === 'deselect_all') jQuery(trigger_element).select2('val', '');
|
||||
if (event.added && event.added.id === 'select_all') jQuery(trigger_element).select2('val', columns_ids);
|
||||
|
||||
if ((exportData.lists && segmentsContainerElement.select2('data').length && subscriberFieldsContainerElement.select2('data').length)
|
||||
||
|
||||
(!exportData.lists && subscriberFieldsContainerElement.select2('data').length)
|
||||
) {
|
||||
jQuery(nextStepElement).removeClass('button-disabled');
|
||||
}
|
||||
else {
|
||||
jQuery(nextStepElement).addClass('button-disabled');
|
||||
}
|
||||
|
||||
if (segmentsContainerElement.select2('data').length > 1 && exportData.group_by_list) {
|
||||
jQuery('.mailpoet_group_by_list').show();
|
||||
}
|
||||
else if (exportData.group_by_list) jQuery('.mailpoet_group_by_list').hide();
|
||||
})*/
|
||||
};
|
||||
|
||||
// render lists and columns
|
||||
renderSegmentsAndFields(subscriberFieldsContainerElement, columns);
|
||||
renderSegmentsAndFields(segmentsContainerElement, lists);
|
||||
|
||||
// pre-select columns
|
||||
// subscriberFieldsContainerElement.select2('val', ['subscriber_state', 'subscriber_email', 'subscriber_firstname', 'subscriber_lastname']);
|
||||
|
||||
// handle confirmed/unconfirmed behavior
|
||||
exportConfirmedOptionElement.change(function () {
|
||||
if (this.value == 1) {
|
||||
exportData.confirmed_option = true;
|
||||
renderSegmentsAndFields(segmentsContainerElement, lists_confirmed);
|
||||
}
|
||||
else {
|
||||
exportData.confirmed_option = false;
|
||||
renderSegmentsAndFields(segmentsContainerElement, lists);
|
||||
}
|
||||
});
|
||||
/*
|
||||
// process export
|
||||
nextStepElement.click(function () {
|
||||
if (jQuery(this).hasClass('button-disabled')) return;
|
||||
MailPoet.Modal.loading(true);
|
||||
mailpoet_post_json(
|
||||
'subscribers_export.php',
|
||||
{
|
||||
'option_confirmed': exportData.confirmed_option,
|
||||
'option_format': jQuery(':radio[name="option_format"]:checked').val(),
|
||||
'option_group_by_list': (groupBySegmentOptionElement.is(":visible")) ? groupBySegmentOptionElement.prop('checked') : false,
|
||||
'lists': (exportData.lists) ? segmentsContainerElement.select2('val') : false,
|
||||
'columns': subscriberFieldsContainerElement.select2('data'),
|
||||
'export_directory': export_directory
|
||||
},
|
||||
function (response) {
|
||||
if (response.result === true) {
|
||||
response.message = "<?php _e('%1$s subscribers were exported. Get the exported file [link]here[/link].'); ?>"
|
||||
.replace('%1$s', '<strong>' + response.total + '</strong>')
|
||||
.replace('[link]', '<a href="' + export_url + response.filename + '" target="_blank" >')
|
||||
.replace('[/link]', '</a>')
|
||||
jQuery('#export_result_notice > ul > li').html(response.message)
|
||||
jQuery('#export_result_notice').show();
|
||||
window.location.href = export_url + response.filename;
|
||||
}
|
||||
else {
|
||||
MailPoet.Notice.error(response.message);
|
||||
}
|
||||
MailPoet.Modal.loading(false);
|
||||
},
|
||||
function (response) {
|
||||
MailPoet.Modal.loading(false);
|
||||
MailPoet.Notice.error('<?php _e("Server error:"); ?> ' + response.statusText.toLowerCase() + '.', {scroll: true});
|
||||
}
|
||||
)
|
||||
})*/
|
||||
});
|
||||
});
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace MailPoet\Config;
|
||||
|
||||
use MailPoet\ImportExport\BootStrapMenu;
|
||||
use \MailPoet\Models\Segment;
|
||||
use \MailPoet\Models\Setting;
|
||||
use \MailPoet\Models\Form;
|
||||
@ -236,13 +237,15 @@ class Menu {
|
||||
}
|
||||
|
||||
function import() {
|
||||
$import = new \MailPoet\Import\BootstrapMenu();
|
||||
$import = new BootStrapMenu('import');
|
||||
$data = $import->bootstrap();
|
||||
echo $this->renderer->render('import.html', $data);
|
||||
}
|
||||
|
||||
function export() {
|
||||
echo $this->renderer->render('export.html');
|
||||
$export = new BootStrapMenu('export');
|
||||
$data = $export->bootstrap();
|
||||
echo $this->renderer->render('export.html', $data);
|
||||
}
|
||||
|
||||
function formEditor() {
|
||||
|
@ -1,11 +0,0 @@
|
||||
<?php
|
||||
namespace MailPoet\Export;
|
||||
|
||||
class BootstrapMenu {
|
||||
|
||||
function __construct() {
|
||||
}
|
||||
|
||||
function bootstrap() {
|
||||
}
|
||||
}
|
@ -1,112 +0,0 @@
|
||||
<?php
|
||||
namespace MailPoet\Import;
|
||||
|
||||
use MailPoet\Models\CustomField;
|
||||
use MailPoet\Models\Segment;
|
||||
use MailPoet\Util\Helpers;
|
||||
|
||||
class BootstrapMenu {
|
||||
|
||||
function __construct() {
|
||||
$this->subscriberFields = $this->getSubscriberFields();
|
||||
$this->subscriberCustomFields = $this->getSubscriberCustomFields();
|
||||
$this->segments = $this->getSegments();
|
||||
}
|
||||
|
||||
function getSubscriberFields() {
|
||||
return array(
|
||||
'email' => __('Email'),
|
||||
'first_name' => __('First name'),
|
||||
'last_name' => __('Last name'),
|
||||
'status' => __('Status')
|
||||
/* 'confirmed_ip' => __('IP address')
|
||||
'confirmed_at' => __('Subscription date')*/
|
||||
);
|
||||
}
|
||||
|
||||
function getSegments() {
|
||||
return array_map(function ($segment) {
|
||||
return array(
|
||||
'id' => $segment['id'],
|
||||
'name' => $segment['name'],
|
||||
'subscriberCount' => $segment['subscribers']
|
||||
);
|
||||
}, Segment::filter('filterWithSubscriberCount')
|
||||
->findArray());
|
||||
}
|
||||
|
||||
function getSubscriberCustomFields() {
|
||||
return CustomField::findArray();
|
||||
}
|
||||
|
||||
function formatSubscriberFields($subscriberFields) {
|
||||
return array_map(function ($fieldId, $fieldName) {
|
||||
return array(
|
||||
'id' => $fieldId,
|
||||
'name' => $fieldName,
|
||||
'type' => ($fieldId === 'confirmed_at') ? 'date' : null,
|
||||
'custom' => false
|
||||
);
|
||||
}, array_keys($subscriberFields), $subscriberFields);
|
||||
}
|
||||
|
||||
function formatSubscriberCustomFields($subscriberCustomFields) {
|
||||
return array_map(function ($field) {
|
||||
return array(
|
||||
'id' => $field['id'],
|
||||
'name' => $field['name'],
|
||||
'type' => $field['type'],
|
||||
'custom' => true
|
||||
);
|
||||
}, $subscriberCustomFields);
|
||||
}
|
||||
|
||||
function formatFieldsForSelect2(
|
||||
$subscriberFields,
|
||||
$subscriberCustomFields) {
|
||||
$select2Fields = array(
|
||||
array(
|
||||
'name' => __('Actions'),
|
||||
'children' => array(
|
||||
array(
|
||||
'id' => 'ignore',
|
||||
'name' => __('Ignore column...'),
|
||||
),
|
||||
array(
|
||||
'id' => 'create',
|
||||
'name' => __('Create new column...')
|
||||
),
|
||||
)
|
||||
),
|
||||
array(
|
||||
'name' => __('System columns'),
|
||||
'children' => $this->formatSubscriberFields($subscriberFields)
|
||||
)
|
||||
);
|
||||
if($this->subscriberCustomFields) {
|
||||
array_push($select2Fields, array(
|
||||
'name' => __('User columns'),
|
||||
'children' => $this->formatSubscriberCustomFields(
|
||||
$subscriberCustomFields
|
||||
)
|
||||
));
|
||||
}
|
||||
return $select2Fields;
|
||||
}
|
||||
|
||||
function bootstrap() {
|
||||
$data['segments'] = $this->segments;
|
||||
$data['subscriberFields'] = array_merge(
|
||||
$this->formatSubscriberFields($this->subscriberFields),
|
||||
$this->formatSubscriberCustomFields($this->subscriberCustomFields)
|
||||
);
|
||||
$data['subscriberFieldsSelect2'] = $this->formatFieldsForSelect2(
|
||||
$this->subscriberFields,
|
||||
$this->subscriberCustomFields
|
||||
);
|
||||
$data = array_map('json_encode', $data);
|
||||
$data['maxPostSizeBytes'] = Helpers::getMaxPostSize('bytes');
|
||||
$data['maxPostSize'] = Helpers::getMaxPostSize();
|
||||
return $data;
|
||||
}
|
||||
}
|
135
lib/ImportExport/BootstrapMenu.php
Normal file
135
lib/ImportExport/BootstrapMenu.php
Normal file
@ -0,0 +1,135 @@
|
||||
<?php
|
||||
namespace MailPoet\ImportExport;
|
||||
|
||||
use MailPoet\Models\CustomField;
|
||||
use MailPoet\Models\Segment;
|
||||
use MailPoet\Util\Helpers;
|
||||
|
||||
class BootStrapMenu {
|
||||
function __construct($action) {
|
||||
$this->action = $action;
|
||||
}
|
||||
|
||||
function getSegments($withConfirmedSubscribers = false) {
|
||||
$segments = ($this->action === 'import') ?
|
||||
Segment::getSegmentsForImport() :
|
||||
Segment::getSegmentsForExport($withConfirmedSubscribers);
|
||||
return array_map(function ($segment) {
|
||||
return array(
|
||||
'id' => $segment['id'],
|
||||
'name' => $segment['name'],
|
||||
'subscriberCount' => $segment['subscribers']
|
||||
);
|
||||
}, $segments);
|
||||
}
|
||||
|
||||
function getSubscriberFields() {
|
||||
return array(
|
||||
'email' => __('Email'),
|
||||
'first_name' => __('First name'),
|
||||
'last_name' => __('Last name'),
|
||||
'status' => __('Status')
|
||||
/*
|
||||
'confirmed_ip' => __('IP address')
|
||||
'confirmed_at' => __('Subscription date')
|
||||
*/
|
||||
);
|
||||
}
|
||||
|
||||
function formatSubscriberFields($subscriberFields) {
|
||||
return array_map(function ($fieldId, $fieldName) {
|
||||
return array(
|
||||
'id' => $fieldId,
|
||||
'name' => $fieldName,
|
||||
'type' => ($fieldId === 'confirmed_at') ? 'date' : null,
|
||||
'custom' => false
|
||||
);
|
||||
}, array_keys($subscriberFields), $subscriberFields);
|
||||
}
|
||||
|
||||
function getSubscriberCustomFields() {
|
||||
return CustomField::findArray();
|
||||
}
|
||||
|
||||
function formatSubscriberCustomFields($subscriberCustomFields) {
|
||||
return array_map(function ($field) {
|
||||
return array(
|
||||
'id' => $field['id'],
|
||||
'name' => $field['name'],
|
||||
'type' => $field['type'],
|
||||
'custom' => true
|
||||
);
|
||||
}, $subscriberCustomFields);
|
||||
}
|
||||
|
||||
function formatFieldsForSelect2(
|
||||
$subscriberFields,
|
||||
$subscriberCustomFields) {
|
||||
$actions = ($this->action === 'import') ?
|
||||
array(
|
||||
array(
|
||||
'id' => 'ignore',
|
||||
'name' => __('Ignore column...'),
|
||||
),
|
||||
array(
|
||||
'id' => 'create',
|
||||
'name' => __('Create new column...')
|
||||
),
|
||||
) :
|
||||
array(
|
||||
array(
|
||||
'id' => 'select',
|
||||
'name' => __('Select all...'),
|
||||
),
|
||||
array(
|
||||
'id' => 'deselect',
|
||||
'name' => __('Deselect all...')
|
||||
),
|
||||
);
|
||||
$select2Fields = array(
|
||||
array(
|
||||
'name' => __('Actions'),
|
||||
'children' => $actions
|
||||
),
|
||||
array(
|
||||
'name' => __('System columns'),
|
||||
'children' => $this->formatSubscriberFields($subscriberFields)
|
||||
)
|
||||
);
|
||||
if($subscriberCustomFields) {
|
||||
array_push($select2Fields, array(
|
||||
'name' => __('User columns'),
|
||||
'children' => $this->formatSubscriberCustomFields(
|
||||
$subscriberCustomFields
|
||||
)
|
||||
));
|
||||
}
|
||||
return $select2Fields;
|
||||
}
|
||||
|
||||
function bootstrap() {
|
||||
$subscriberFields = $this->getSubscriberFields();
|
||||
$subscriberCustomFields = $this->getSubscriberCustomFields();
|
||||
$data['segments'] = json_encode($this->getSegments());
|
||||
$data['subscriberFieldsSelect2'] = json_encode(
|
||||
$this->formatFieldsForSelect2(
|
||||
$subscriberFields,
|
||||
$subscriberCustomFields
|
||||
)
|
||||
);
|
||||
if($this->action === 'import') {
|
||||
$data['subscriberFields'] = json_encode(
|
||||
array_merge(
|
||||
$this->formatSubscriberFields($subscriberFields),
|
||||
$this->formatSubscriberCustomFields($subscriberCustomFields)
|
||||
)
|
||||
);
|
||||
$data['maxPostSizeBytes'] = Helpers::getMaxPostSize('bytes');
|
||||
$data['maxPostSize'] = Helpers::getMaxPostSize();
|
||||
} else {
|
||||
$data['segmentsWithConfirmedSubscribers'] =
|
||||
json_encode($this->getSegments($withConfirmedSubscribers = true));
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace MailPoet\Export;
|
||||
namespace MailPoet\ImportExport\ImportExport\Export;
|
||||
|
||||
class Export {
|
||||
public function __construct($data) {
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace MailPoet\Import;
|
||||
namespace MailPoet\ImportExport\Import;
|
||||
|
||||
use MailPoet\ImportExport\BootStrapMenu;
|
||||
use MailPoet\Models\Subscriber;
|
||||
use MailPoet\Models\SubscriberCustomField;
|
||||
use MailPoet\Models\SubscriberSegment;
|
||||
@ -66,7 +67,7 @@ class Import {
|
||||
'error' => $e->getMessage()
|
||||
);
|
||||
}
|
||||
$segments = new BootstrapMenu();
|
||||
$segments = new BootStrapMenu('import');
|
||||
return array(
|
||||
'result' => true,
|
||||
'data' => array(
|
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace MailPoet\Import;
|
||||
namespace MailPoet\ImportExport\Import;
|
||||
|
||||
use MailPoet\Util\Helpers;
|
||||
|
@ -94,16 +94,39 @@ class Segment extends Model {
|
||||
}
|
||||
}
|
||||
|
||||
static function filterWithSubscriberCount($orm) {
|
||||
$orm = $orm
|
||||
->selectMany(array(self::$_table.'.id', self::$_table.'.name'))
|
||||
->select_expr('COUNT('.MP_SUBSCRIBER_SEGMENT_TABLE.'.subscriber_id)', 'subscribers')
|
||||
static function getSegmentsForImport() {
|
||||
return self::selectMany(array(self::$_table.'.id', self::$_table.'.name'))
|
||||
->select_expr(
|
||||
'COUNT('.MP_SUBSCRIBER_SEGMENT_TABLE.'.subscriber_id)', 'subscribers'
|
||||
)
|
||||
->left_outer_join(
|
||||
MP_SUBSCRIBER_SEGMENT_TABLE,
|
||||
array(self::$_table.'.id', '=', MP_SUBSCRIBER_SEGMENT_TABLE.'.segment_id'))
|
||||
->group_by(self::$_table.'.id')
|
||||
->group_by(self::$_table.'.name');
|
||||
return $orm;
|
||||
->group_by(self::$_table.'.name')
|
||||
->findArray();
|
||||
}
|
||||
|
||||
static function getSegmentsForExport($withConfirmedSubscribers = false) {
|
||||
return self::raw_query(
|
||||
'(SELECT segments.id, segments.name, COUNT(relation.subscriber_id) as subscribers ' .
|
||||
'FROM ' . MP_SUBSCRIBER_SEGMENT_TABLE . ' relation ' .
|
||||
'LEFT JOIN ' . self::$_table . ' segments ON segments.id = relation.segment_id ' .
|
||||
'LEFT JOIN ' . MP_SUBSCRIBERS_TABLE . ' subscribers ON subscribers.id = relation.subscriber_id ' .
|
||||
(($withConfirmedSubscribers) ?
|
||||
'WHERE subscribers.status = 1 ' :
|
||||
'WHERE relation.segment_id IS NOT NULL ') .
|
||||
'GROUP BY segments.id) ' .
|
||||
'UNION ALL ' .
|
||||
'(SELECT 0 as id, "' . __('Not In List') . '" as name, COUNT(*) as subscribers ' .
|
||||
'FROM ' . MP_SUBSCRIBERS_TABLE . ' subscribers ' .
|
||||
'LEFT JOIN ' . MP_SUBSCRIBER_SEGMENT_TABLE . ' relation on relation.subscriber_id = subscribers.id ' .
|
||||
(($withConfirmedSubscribers) ?
|
||||
'WHERE relation.subscriber_id is NULL AND subscribers.status = 1 ' :
|
||||
'WHERE relation.subscriber_id is NULL ') .
|
||||
'HAVING subscribers) ' .
|
||||
'ORDER BY name'
|
||||
)->findArray();
|
||||
}
|
||||
|
||||
static function createOrUpdate($data = array()) {
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
namespace MailPoet\Router;
|
||||
|
||||
use MailPoet\Import\MailChimp;
|
||||
use MailPoet\ImportExport\Import\MailChimp;
|
||||
use MailPoet\Models\CustomField;
|
||||
use MailPoet\Models\Segment;
|
||||
|
||||
@ -49,7 +49,7 @@ class Import {
|
||||
}
|
||||
|
||||
function process($data) {
|
||||
$import = new \MailPoet\Import\Import(json_decode($data, true));
|
||||
$import = new \MailPoet\ImportExport\Import\Import(json_decode($data, true));
|
||||
wp_send_json($import->process());
|
||||
}
|
||||
}
|
@ -55,6 +55,7 @@ class Segments {
|
||||
)
|
||||
->findOne()->asArray();
|
||||
|
||||
!d(\ORM::get_last_query());exit;
|
||||
$item = array_merge($item, $stats);
|
||||
|
||||
$item['subscribers_url'] = admin_url(
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
use MailPoet\Import\BootstrapMenu;
|
||||
use MailPoet\ImportExport\BootStrapMenu;
|
||||
use MailPoet\Models\CustomField;
|
||||
use MailPoet\Models\Segment;
|
||||
use MailPoet\Models\Subscriber;
|
||||
@ -22,11 +22,13 @@ class BootStrapMenuCest {
|
||||
array(
|
||||
'first_name' => 'John',
|
||||
'last_name' => 'Mailer',
|
||||
'status' => 0,
|
||||
'email' => 'john@mailpoet.com'
|
||||
),
|
||||
array(
|
||||
'first_name' => 'Mike',
|
||||
'last_name' => 'Smith',
|
||||
'status' => 1,
|
||||
'email' => 'mike@maipoet.com'
|
||||
)
|
||||
);
|
||||
@ -37,20 +39,39 @@ class BootStrapMenuCest {
|
||||
$customField = CustomField::create();
|
||||
$customField->hydrate($this->customFieldsData);
|
||||
$customField->save();
|
||||
$this->bootStrapMenu = new BootstrapMenu();
|
||||
$this->bootStrapImportMenu = new BootStrapMenu('import');
|
||||
$this->bootStrapExportMenu = new BootStrapMenu('export');
|
||||
}
|
||||
|
||||
function itCanGetSegments() {
|
||||
function itCanGetSegmentsForImport() {
|
||||
$this->_createSegmentsAndSubscribers();
|
||||
$segments = $this->bootStrapMenu->getSegments();
|
||||
$segments = $this->bootStrapImportMenu->getSegments();
|
||||
expect(count($segments))->equals(2);
|
||||
expect($segments[0]['name'])->equals($this->segmentsData[0]['name']);
|
||||
expect($segments[0]['subscriberCount'])->equals(1);
|
||||
expect($segments[1]['subscriberCount'])->equals(0);
|
||||
expect($segments[1]['subscriberCount'])->equals(1);
|
||||
}
|
||||
|
||||
function itCanGetSegmentsForExport() {
|
||||
$this->_createSegmentsAndSubscribers();
|
||||
$segments = $this->bootStrapExportMenu->getSegments();
|
||||
expect(count($segments))->equals(2);
|
||||
expect($segments[0]['name'])->equals($this->segmentsData[0]['name']);
|
||||
expect($segments[0]['subscriberCount'])->equals(1);
|
||||
expect($segments[1]['subscriberCount'])->equals(1);
|
||||
}
|
||||
|
||||
function itCanGetSegmentsWithConfirmedSubscribersForExport() {
|
||||
$this->_createSegmentsAndSubscribers();
|
||||
$segments = $this->bootStrapExportMenu->getSegments(
|
||||
$withConfirmedSubscribers = true
|
||||
);
|
||||
expect(count($segments))->equals(1);
|
||||
expect($segments[0]['name'])->equals($this->segmentsData[1]['name']);
|
||||
}
|
||||
|
||||
function itCanGetSubscriberFields() {
|
||||
$subsriberFields = $this->bootStrapMenu->getSubscriberFields();
|
||||
$subsriberFields = $this->bootStrapImportMenu->getSubscriberFields();
|
||||
$fields = array(
|
||||
'email',
|
||||
'first_name',
|
||||
@ -64,8 +85,8 @@ class BootStrapMenuCest {
|
||||
|
||||
function itCanFormatSubsciberFields() {
|
||||
$formattedSubscriberFields =
|
||||
$this->bootStrapMenu->formatSubscriberFields(
|
||||
$this->bootStrapMenu->getSubscriberFields()
|
||||
$this->bootStrapImportMenu->formatSubscriberFields(
|
||||
$this->bootStrapImportMenu->getSubscriberFields()
|
||||
);
|
||||
$fields = array(
|
||||
'id',
|
||||
@ -82,7 +103,7 @@ class BootStrapMenuCest {
|
||||
|
||||
function itCanGetSubsciberCustomFields() {
|
||||
$subscriberCustomFields =
|
||||
$this->bootStrapMenu
|
||||
$this->bootStrapImportMenu
|
||||
->getSubscriberCustomFields();
|
||||
expect($subscriberCustomFields[0]['type'])
|
||||
->equals($this->customFieldsData['type']);
|
||||
@ -90,8 +111,8 @@ class BootStrapMenuCest {
|
||||
|
||||
function itCanFormatSubsciberCustomFields() {
|
||||
$formattedSubscriberCustomFields =
|
||||
$this->bootStrapMenu->formatSubscriberCustomFields(
|
||||
$this->bootStrapMenu->getSubscriberCustomFields()
|
||||
$this->bootStrapImportMenu->formatSubscriberCustomFields(
|
||||
$this->bootStrapImportMenu->getSubscriberCustomFields()
|
||||
);
|
||||
$fields = array(
|
||||
'id',
|
||||
@ -106,8 +127,8 @@ class BootStrapMenuCest {
|
||||
expect($formattedSubscriberCustomFields[0]['custom'])->true();
|
||||
}
|
||||
|
||||
function itCanFormatFieldsForSelect2() {
|
||||
$bootStrapMenu = clone($this->bootStrapMenu);
|
||||
function itCanFormatFieldsForSelect2Import() {
|
||||
$bootStrapMenu = clone($this->bootStrapImportMenu);
|
||||
$select2FieldsWithoutCustomFields = array(
|
||||
array(
|
||||
'name' => 'Actions',
|
||||
@ -140,50 +161,112 @@ class BootStrapMenuCest {
|
||||
)
|
||||
));
|
||||
$formattedFieldsForSelect2 = $bootStrapMenu->formatFieldsForSelect2(
|
||||
$bootStrapMenu->subscriberFields,
|
||||
$bootStrapMenu->subscriberCustomFields
|
||||
$bootStrapMenu->getSubscriberFields(),
|
||||
$bootStrapMenu->getSubscriberCustomFields()
|
||||
);
|
||||
expect($formattedFieldsForSelect2)->equals($select2FieldsWithCustomFields);
|
||||
$bootStrapMenu->subscriberCustomFields = false;
|
||||
$formattedFieldsForSelect2 = $bootStrapMenu->formatFieldsForSelect2(
|
||||
$bootStrapMenu->subscriberFields,
|
||||
$bootStrapMenu->subscriberCustomFields
|
||||
$bootStrapMenu->getSubscriberFields(),
|
||||
$bootStrapMenu->getSubscriberCustomFields()
|
||||
);
|
||||
expect($formattedFieldsForSelect2)->equals($select2FieldsWithoutCustomFields);
|
||||
}
|
||||
|
||||
function itCanBootstrap() {
|
||||
function itCanFormatFieldsForSelect2Export() {
|
||||
$bootStrapMenu = clone($this->bootStrapExportMenu);
|
||||
$select2FieldsWithoutCustomFields = array(
|
||||
array(
|
||||
'name' => 'Actions',
|
||||
'children' => array(
|
||||
array(
|
||||
'id' => 'select',
|
||||
'name' => __('Select all...'),
|
||||
),
|
||||
array(
|
||||
'id' => 'deselect',
|
||||
'name' => __('Deselect all...')
|
||||
),
|
||||
)
|
||||
),
|
||||
array(
|
||||
'name' => 'System columns',
|
||||
'children' => $bootStrapMenu->formatSubscriberFields(
|
||||
$bootStrapMenu->subscriberFields
|
||||
)
|
||||
)
|
||||
);
|
||||
$select2FieldsWithCustomFields = array_merge(
|
||||
$select2FieldsWithoutCustomFields,
|
||||
array(
|
||||
array(
|
||||
'name' => __('User columns'),
|
||||
'children' => $bootStrapMenu->formatSubscriberCustomFields(
|
||||
$bootStrapMenu->subscriberCustomFields
|
||||
)
|
||||
)
|
||||
));
|
||||
$formattedFieldsForSelect2 = $bootStrapMenu->formatFieldsForSelect2(
|
||||
$bootStrapMenu->getSubscriberFields(),
|
||||
$bootStrapMenu->getSubscriberCustomFields()
|
||||
);
|
||||
expect($formattedFieldsForSelect2)->equals($select2FieldsWithCustomFields);
|
||||
$bootStrapMenu->subscriberCustomFields = false;
|
||||
$formattedFieldsForSelect2 = $bootStrapMenu->formatFieldsForSelect2(
|
||||
$bootStrapMenu->getSubscriberFields(),
|
||||
$bootStrapMenu->getSubscriberCustomFields()
|
||||
);
|
||||
expect($formattedFieldsForSelect2)->equals($select2FieldsWithoutCustomFields);
|
||||
}
|
||||
|
||||
function itCanBootStrapImport() {
|
||||
$customField = CustomField::create();
|
||||
$customField->hydrate($this->customFieldsData);
|
||||
$customField->save();
|
||||
$bootstrap = clone($this->bootStrapMenu);
|
||||
$this->_createSegmentsAndSubscribers();
|
||||
$bootstrap->segments = $bootstrap->getSegments();
|
||||
$menu = $bootstrap->bootstrap();
|
||||
expect(count(json_decode($menu['segments'], true)))->equals(2);
|
||||
$import = clone($this->bootStrapImportMenu);
|
||||
$importMenu = $import->bootstrap();
|
||||
expect(count(json_decode($importMenu['segments'], true)))
|
||||
->equals(2);
|
||||
// email, first_name, last_name, status + 1 custom field
|
||||
expect(count(json_decode($menu['subscriberFields'], true)))->equals(5);
|
||||
expect(count(json_decode($importMenu['subscriberFields'], true)))
|
||||
->equals(5);
|
||||
// action, system columns, user columns
|
||||
expect(count(json_decode($menu['subscriberFieldsSelect2'], true)))->equals(3);
|
||||
expect($menu['maxPostSize'])->equals(ini_get('post_max_size'));
|
||||
expect($menu['maxPostSizeBytes'])->equals(
|
||||
expect(count(json_decode($importMenu['subscriberFieldsSelect2'], true)))
|
||||
->equals(3);
|
||||
expect($importMenu['maxPostSize'])->equals(ini_get('post_max_size'));
|
||||
expect($importMenu['maxPostSizeBytes'])->equals(
|
||||
(int) ini_get('post_max_size') * 1048576
|
||||
);
|
||||
}
|
||||
|
||||
function itCanBootStrapExport() {
|
||||
$customField = CustomField::create();
|
||||
$customField->hydrate($this->customFieldsData);
|
||||
$customField->save();
|
||||
$this->_createSegmentsAndSubscribers();
|
||||
$export = clone($this->bootStrapImportMenu);
|
||||
$exportMenu = $export->bootstrap();
|
||||
expect(count(json_decode($exportMenu['segments'], true)))
|
||||
->equals(2);
|
||||
// action, system columns, user columns
|
||||
expect(count(json_decode($exportMenu['subscriberFieldsSelect2'], true)))
|
||||
->equals(3);
|
||||
}
|
||||
|
||||
function _createSegmentsAndSubscribers() {
|
||||
foreach ($this->segmentsData as $segmentData) {
|
||||
$segment = Segment::create();
|
||||
$segment->hydrate($segmentData);
|
||||
$segment->save();
|
||||
}
|
||||
foreach ($this->subscribersData as $index => $subscriberData) {
|
||||
foreach ($this->subscribersData as $subscriberData) {
|
||||
$subscriber = Subscriber::create();
|
||||
$subscriber->hydrate($subscriberData);
|
||||
$subscriber->save();
|
||||
$association = SubscriberSegment::create();
|
||||
$association->subscriber_id = $subscriber->id;
|
||||
$association->segment_id = $index;
|
||||
$association->segment_id = $subscriber->id;
|
||||
$association->save();
|
||||
};
|
||||
}
|
23
tests/unit/ImportExport/Export/ExportCest.php
Normal file
23
tests/unit/ImportExport/Export/ExportCest.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
use MailPoet\ImportExport\Export;
|
||||
|
||||
class ExportCest {
|
||||
function __construct() {
|
||||
}
|
||||
|
||||
function itCanConstruct() {
|
||||
}
|
||||
|
||||
function itCanProcess() {
|
||||
}
|
||||
|
||||
function _after() {
|
||||
ORM::forTable(Subscriber::$_table)
|
||||
->deleteMany();
|
||||
ORM::forTable(SubscriberCustomField::$_table)
|
||||
->deleteMany();
|
||||
ORM::forTable(SubscriberSegment::$_table)
|
||||
->deleteMany();
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
use MailPoet\Import\Import;
|
||||
use MailPoet\ImportExport\Import\Import;
|
||||
use MailPoet\Models\Subscriber;
|
||||
use MailPoet\Models\SubscriberCustomField;
|
||||
use MailPoet\Models\SubscriberSegment;
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
use MailPoet\Import\MailChimp;
|
||||
use MailPoet\ImportExport\Import\MailChimp;
|
||||
|
||||
class MailChimpCest {
|
||||
function __construct() {
|
@ -1,10 +1,10 @@
|
||||
<?php
|
||||
|
||||
use MailPoet\Models\SubscriberSegment;
|
||||
use MailPoet\Models\Subscriber;
|
||||
use MailPoet\Models\Segment;
|
||||
use MailPoet\Models\Newsletter;
|
||||
use MailPoet\Models\NewsletterSegment;
|
||||
use MailPoet\Models\Segment;
|
||||
use MailPoet\Models\Subscriber;
|
||||
use MailPoet\Models\SubscriberSegment;
|
||||
|
||||
class SegmentCest {
|
||||
function _before() {
|
||||
@ -17,11 +17,13 @@ class SegmentCest {
|
||||
array(
|
||||
'first_name' => 'John',
|
||||
'last_name' => 'Mailer',
|
||||
'status' => 0,
|
||||
'email' => 'john@mailpoet.com'
|
||||
),
|
||||
array(
|
||||
'first_name' => 'Mike',
|
||||
'last_name' => 'Smith',
|
||||
'status' => 1,
|
||||
'email' => 'mike@maipoet.com'
|
||||
)
|
||||
);
|
||||
@ -99,24 +101,27 @@ class SegmentCest {
|
||||
|
||||
function itCanCreateOrUpdate() {
|
||||
$is_created = Segment::createOrUpdate(array(
|
||||
'name' => 'new list'
|
||||
));
|
||||
'name' => 'new list'
|
||||
));
|
||||
expect($is_created)->notEquals(false);
|
||||
expect($is_created->getValidationErrors())->isEmpty();
|
||||
|
||||
$segment = Segment::where('name', 'new list')->findOne();
|
||||
$segment = Segment::where('name', 'new list')
|
||||
->findOne();
|
||||
expect($segment->name)->equals('new list');
|
||||
|
||||
$is_updated = Segment::createOrUpdate(array(
|
||||
'id' => $segment->id,
|
||||
'name' => 'updated list'
|
||||
));
|
||||
$segment = Segment::where('name', 'updated list')->findOne();
|
||||
$is_updated = Segment::createOrUpdate(
|
||||
array(
|
||||
'id' => $segment->id,
|
||||
'name' => 'updated list'
|
||||
));
|
||||
$segment = Segment::where('name', 'updated list')
|
||||
->findOne();
|
||||
expect($segment->name)->equals('updated list');
|
||||
}
|
||||
|
||||
function itCanHaveManySubscribers() {
|
||||
foreach($this->subscribersData as $subscriberData) {
|
||||
foreach ($this->subscribersData as $subscriberData) {
|
||||
$subscriber = Subscriber::create();
|
||||
$subscriber->hydrate($subscriberData);
|
||||
$subscriber->save();
|
||||
@ -125,15 +130,15 @@ class SegmentCest {
|
||||
$association->segment_id = $this->segment->id;
|
||||
$association->save();
|
||||
}
|
||||
|
||||
$segment = Segment::findOne($this->segment->id);
|
||||
$subscribers = $segment->subscribers()->findArray();
|
||||
$subscribers = $segment->subscribers()
|
||||
->findArray();
|
||||
|
||||
expect(count($subscribers))->equals(2);
|
||||
}
|
||||
|
||||
function itCanHaveManyNewsletters() {
|
||||
foreach($this->newslettersData as $newsletterData) {
|
||||
foreach ($this->newslettersData as $newsletterData) {
|
||||
$newsletter = Newsletter::create();
|
||||
$newsletter->hydrate($newsletterData);
|
||||
$newsletter->save();
|
||||
@ -142,15 +147,15 @@ class SegmentCest {
|
||||
$association->segment_id = $this->segment->id;
|
||||
$association->save();
|
||||
}
|
||||
|
||||
$segment = Segment::findOne($this->segment->id);
|
||||
$newsletters = $segment->newsletters()->findArray();
|
||||
$newsletters = $segment->newsletters()
|
||||
->findArray();
|
||||
|
||||
expect(count($newsletters))->equals(2);
|
||||
}
|
||||
|
||||
function itCanReturnSubscriberCount() {
|
||||
foreach($this->subscribersData as $subscriberData) {
|
||||
function itCanGetSegmentsForImport() {
|
||||
foreach ($this->subscribersData as $subscriberData) {
|
||||
$subscriber = Subscriber::create();
|
||||
$subscriber->hydrate($subscriberData);
|
||||
$subscriber->save();
|
||||
@ -159,11 +164,29 @@ class SegmentCest {
|
||||
$association->segment_id = $this->segment->id;
|
||||
$association->save();
|
||||
}
|
||||
|
||||
$segment = Segment::filter('filterWithSubscriberCount')->findArray();
|
||||
$segment = Segment::getSegmentsForImport();
|
||||
expect($segment[0]['subscribers'])->equals(2);
|
||||
}
|
||||
|
||||
function itCanGetSegmentsForExport() {
|
||||
foreach ($this->subscribersData as $index => $subscriberData) {
|
||||
$subscriber = Subscriber::create();
|
||||
$subscriber->hydrate($subscriberData);
|
||||
$subscriber->save();
|
||||
if(!$index) {
|
||||
$association = SubscriberSegment::create();
|
||||
$association->subscriber_id = $subscriber->id;
|
||||
$association->segment_id = $this->segment->id;
|
||||
$association->save();
|
||||
}
|
||||
}
|
||||
$segments = Segment::getSegmentsForExport();
|
||||
expect(count($segments))->equals(2);
|
||||
expect($segments[0]['name'])->equals('Not In List');
|
||||
$segments = Segment::getSegmentsForExport($withConfirmedSubscribers = true);
|
||||
expect(count($segments))->equals(1);
|
||||
}
|
||||
|
||||
function _after() {
|
||||
ORM::forTable(Segment::$_table)
|
||||
->deleteMany();
|
||||
|
@ -3,13 +3,126 @@
|
||||
<% block content %>
|
||||
<div id="mailpoet_subscribers_export" class="wrap">
|
||||
<h2 class="title"><%= __('Export') %></h2>
|
||||
<% if segments is empty %>
|
||||
<div class="notice">
|
||||
<ul>
|
||||
<li><%= __("Yikes! Couldn't find any subscribers.") %></li>
|
||||
</ul>
|
||||
</div>
|
||||
<% endif %>
|
||||
<div class="inside">
|
||||
<!-- Template data -->
|
||||
</div>
|
||||
</div>
|
||||
<script id="mailpoet_subscribers_export_template" type="text/x-handlebars-template">
|
||||
<div id="export_result_notice" class="notice mailpoet_hidden">
|
||||
<ul>
|
||||
<li></li>
|
||||
</ul>
|
||||
</div>
|
||||
<table class="form-table">
|
||||
<tbody>
|
||||
{{#if segments}}
|
||||
<tr>
|
||||
<th scope="row">
|
||||
<label for="s2id_autogen2">
|
||||
<%= __('Pick a list') %>
|
||||
</label>
|
||||
</th>
|
||||
<td>
|
||||
<select id="export_lists" data-placeholder="<%= __('Select') %>" multiple="multiple"></select>
|
||||
</td>
|
||||
</tr>
|
||||
{{/if}}
|
||||
<tr>
|
||||
<th scope="row">
|
||||
<label for="s2id_autogen1">
|
||||
<%= __('List of fields to export') %>
|
||||
</label>
|
||||
</th>
|
||||
<td>
|
||||
<select id="export_columns" data-placeholder="<%= __('Select') %>" multiple="multiple"></select>
|
||||
</td>
|
||||
</tr>
|
||||
{{#if groupBySegmentOption}}
|
||||
<tr class="mailpoet_group_by_list mailpoet_hidden">
|
||||
<th scope="row">
|
||||
<%= __('Group subscribers by list') %>
|
||||
</th>
|
||||
<td>
|
||||
<input type="checkbox" name="option_group_by_list" checked>
|
||||
</td>
|
||||
</tr>
|
||||
{{/if}}
|
||||
{{#if exportConfirmedOption}}
|
||||
<tr>
|
||||
<th scope="row">
|
||||
<%= __('Export confirmed subscribers only') %>
|
||||
</th>
|
||||
<td>
|
||||
<div>
|
||||
<label>
|
||||
<input type="radio"
|
||||
name="option_confirmed" value=1><%= __('Yes') %>
|
||||
</label>
|
||||
|
||||
<label>
|
||||
<input type="radio"
|
||||
name="option_confirmed" value=0 checked><%= __('No') %>
|
||||
</label>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
{{/if}}
|
||||
<tr>
|
||||
<th scope="row">
|
||||
<%= __('Format') %>
|
||||
</th>
|
||||
<td>
|
||||
<label>
|
||||
<input type="radio" name="option_format"
|
||||
value="csv"
|
||||
checked><%= __('CSV file') %>
|
||||
</label>
|
||||
|
||||
<label>
|
||||
<input type="radio" name="option_format"
|
||||
value="xlsx"><%= __('Excel') %>
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="mailpoet_export_process">
|
||||
<th scope="row">
|
||||
<a href="javascript:;"
|
||||
class="button-primary button-disabled wysija mailpoet_export_process"><%= __('Export') %></a>
|
||||
</th>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</script>
|
||||
</div>
|
||||
|
||||
<%= stylesheet('export.css') %>
|
||||
<%= stylesheet('importExport.css') %>
|
||||
|
||||
<%= localize({
|
||||
}) %>
|
||||
|
||||
<script type="text/javascript">
|
||||
// define data variables
|
||||
var
|
||||
segments = <%= segments|raw %>,
|
||||
segmentsWithConfirmedSubscribers =
|
||||
<%= segmentsWithConfirmedSubscribers|raw %>,
|
||||
subscriberFieldsSelect2 =
|
||||
<%= subscriberFieldsSelect2|raw %>,
|
||||
exportData = {
|
||||
segments: segments.length || null,
|
||||
segmentsWithConfirmedSubscribers: segmentsWithConfirmedSubscribers.length || null,
|
||||
exportConfirmedOption: false,
|
||||
groupBySegmentOption: (segments.length > 1 || segmentsWithConfirmedSubscribers.length > 1) ? true : null
|
||||
},
|
||||
export_location = '',
|
||||
export_directory = '',
|
||||
export_url = '';
|
||||
</script>
|
||||
<% endblock %>
|
@ -11,7 +11,7 @@
|
||||
<% include 'import/step3.html' %>
|
||||
</div>
|
||||
|
||||
<%= stylesheet('import.css') %>
|
||||
<%= stylesheet('importExport.css') %>
|
||||
|
||||
<%= localize({
|
||||
'noMailChimpLists': __('No active lists found.'),
|
||||
|
Reference in New Issue
Block a user