- Removes validation of MailChimp API key
- Refactors import class - Creates new method in Newsletter model to select welcome notifications for specific segments - Updates Step 2 (error) and Step 3 (success) notices - Gives MenuBootstrap class a comprehensible name
This commit is contained in:
@ -71,7 +71,7 @@ define(
|
|||||||
jQuery('#method_paste > div.mailpoet_method_process')
|
jQuery('#method_paste > div.mailpoet_method_process')
|
||||||
.find('a.mailpoet_process'),
|
.find('a.mailpoet_process'),
|
||||||
mailChimpKeyInputElement = jQuery('#mailchimp_key'),
|
mailChimpKeyInputElement = jQuery('#mailchimp_key'),
|
||||||
mailChimpKeyVerifyButtonEelement = jQuery('#mailchimp_key_verify'),
|
mailChimpKeyVerifyButtonElement = jQuery('#mailchimp_key_verify'),
|
||||||
mailChimpListsContainerElement = jQuery('#mailchimp_lists'),
|
mailChimpListsContainerElement = jQuery('#mailchimp_lists'),
|
||||||
mailChimpProcessButtonElement =
|
mailChimpProcessButtonElement =
|
||||||
jQuery('#method_mailchimp > div.mailpoet_method_process')
|
jQuery('#method_mailchimp > div.mailpoet_method_process')
|
||||||
@ -178,15 +178,11 @@ define(
|
|||||||
jQuery('.mailpoet_mailchimp-key-status')
|
jQuery('.mailpoet_mailchimp-key-status')
|
||||||
.html('')
|
.html('')
|
||||||
.removeClass('mailpoet_mailchimp-ok mailpoet_mailchimp-error');
|
.removeClass('mailpoet_mailchimp-ok mailpoet_mailchimp-error');
|
||||||
mailChimpKeyVerifyButtonEelement.prop('disabled', true);
|
|
||||||
toggleNextStepButton(mailChimpProcessButtonElement, 'off');
|
toggleNextStepButton(mailChimpProcessButtonElement, 'off');
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
mailChimpKeyVerifyButtonEelement.prop('disabled', false);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
mailChimpKeyVerifyButtonEelement.click(function () {
|
mailChimpKeyVerifyButtonElement.click(function () {
|
||||||
MailPoet.Modal.loading(true);
|
MailPoet.Modal.loading(true);
|
||||||
MailPoet.Ajax.post({
|
MailPoet.Ajax.post({
|
||||||
endpoint: 'ImportExport',
|
endpoint: 'ImportExport',
|
||||||
@ -1051,7 +1047,7 @@ define(
|
|||||||
importResults.created = response.data.created;
|
importResults.created = response.data.created;
|
||||||
importResults.updated = response.data.updated;
|
importResults.updated = response.data.updated;
|
||||||
importResults.segments = response.data.segments;
|
importResults.segments = response.data.segments;
|
||||||
importResults.segments_with_welcome_notification = response.data.segments_with_welcome_notification;
|
importResults.added_to_segment_with_welcome_notification = response.data.added_to_segment_with_welcome_notification;
|
||||||
}
|
}
|
||||||
queue.run();
|
queue.run();
|
||||||
})
|
})
|
||||||
@ -1119,10 +1115,8 @@ define(
|
|||||||
.replace('%1$s', '<strong>' + importData.step2.updated.toLocaleString() + '</strong>')
|
.replace('%1$s', '<strong>' + importData.step2.updated.toLocaleString() + '</strong>')
|
||||||
.replace('%2$s', '"' + importData.step2.segments.join('", "') + '"')
|
.replace('%2$s', '"' + importData.step2.segments.join('", "') + '"')
|
||||||
: false,
|
: false,
|
||||||
no_action: (!importData.step2.created && !importData.step2.updated)
|
no_action: (!importData.step2.created && !importData.step2.updated),
|
||||||
? true
|
added_to_segment_with_welcome_notification: importData.step2.added_to_segment_with_welcome_notification
|
||||||
: false,
|
|
||||||
segments_with_welcome_notification: importData.step2.segments_with_welcome_notification
|
|
||||||
};
|
};
|
||||||
|
|
||||||
jQuery('#subscribers_data_import_results')
|
jQuery('#subscribers_data_import_results')
|
||||||
|
@ -10,7 +10,7 @@ use MailPoet\Models\Setting;
|
|||||||
use MailPoet\Settings\Charsets;
|
use MailPoet\Settings\Charsets;
|
||||||
use MailPoet\Settings\Hosts;
|
use MailPoet\Settings\Hosts;
|
||||||
use MailPoet\Settings\Pages;
|
use MailPoet\Settings\Pages;
|
||||||
use MailPoet\Subscribers\ImportExport\BootStrapMenu;
|
use MailPoet\Subscribers\ImportExport\ImportExportFactory;
|
||||||
use MailPoet\Util\DKIM;
|
use MailPoet\Util\DKIM;
|
||||||
use MailPoet\Util\Permissions;
|
use MailPoet\Util\Permissions;
|
||||||
use MailPoet\Listing;
|
use MailPoet\Listing;
|
||||||
@ -438,14 +438,14 @@ class Menu {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function import() {
|
function import() {
|
||||||
$import = new BootStrapMenu('import');
|
$import = new ImportExportFactory('import');
|
||||||
$data = $import->bootstrap();
|
$data = $import->bootstrap();
|
||||||
$data['sub_menu'] = 'mailpoet-subscribers';
|
$data['sub_menu'] = 'mailpoet-subscribers';
|
||||||
echo $this->renderer->render('subscribers/importExport/import.html', $data);
|
echo $this->renderer->render('subscribers/importExport/import.html', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
function export() {
|
function export() {
|
||||||
$export = new BootStrapMenu('export');
|
$export = new ImportExportFactory('export');
|
||||||
$data = $export->bootstrap();
|
$data = $export->bootstrap();
|
||||||
$data['sub_menu'] = 'mailpoet-subscribers';
|
$data['sub_menu'] = 'mailpoet-subscribers';
|
||||||
echo $this->renderer->render('subscribers/importExport/export.html', $data);
|
echo $this->renderer->render('subscribers/importExport/export.html', $data);
|
||||||
|
@ -5,6 +5,8 @@ if(!defined('ABSPATH')) exit;
|
|||||||
|
|
||||||
class Newsletter extends Model {
|
class Newsletter extends Model {
|
||||||
public static $_table = MP_NEWSLETTERS_TABLE;
|
public static $_table = MP_NEWSLETTERS_TABLE;
|
||||||
|
const TYPE_WELCOME = 'wecome';
|
||||||
|
const TYPE_NOTIFICATION = 'notification';
|
||||||
|
|
||||||
function __construct() {
|
function __construct() {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
@ -259,4 +261,25 @@ class Newsletter extends Model {
|
|||||||
$newsletter->save();
|
$newsletter->save();
|
||||||
return $newsletter;
|
return $newsletter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static function getWelcomeNotificationsForSegments($segments) {
|
||||||
|
return NewsletterOption::table_alias('options')
|
||||||
|
->select('options.newsletter_id')
|
||||||
|
->select('options.value', 'segment_id')
|
||||||
|
->join(
|
||||||
|
self::$_table,
|
||||||
|
'newsletters.id = options.newsletter_id',
|
||||||
|
'newsletters'
|
||||||
|
)
|
||||||
|
->join(
|
||||||
|
MP_NEWSLETTER_OPTION_FIELDS_TABLE,
|
||||||
|
'option_fields.id = options.option_field_id',
|
||||||
|
'option_fields'
|
||||||
|
)
|
||||||
|
->whereNull('newsletters.deleted_at')
|
||||||
|
->where('newsletters.type', 'welcome')
|
||||||
|
->where('option_fields.name', 'segment')
|
||||||
|
->whereIn('options.value', $segments)
|
||||||
|
->findMany();
|
||||||
|
}
|
||||||
}
|
}
|
@ -6,7 +6,7 @@ use MailPoet\Models\CustomField;
|
|||||||
use MailPoet\Models\Segment;
|
use MailPoet\Models\Segment;
|
||||||
use MailPoet\Models\Subscriber;
|
use MailPoet\Models\Subscriber;
|
||||||
use MailPoet\Models\SubscriberSegment;
|
use MailPoet\Models\SubscriberSegment;
|
||||||
use MailPoet\Subscribers\ImportExport\BootStrapMenu;
|
use MailPoet\Subscribers\ImportExport\ImportExportFactory;
|
||||||
use MailPoet\Util\Helpers;
|
use MailPoet\Util\Helpers;
|
||||||
use MailPoet\Util\XLSXWriter;
|
use MailPoet\Util\XLSXWriter;
|
||||||
|
|
||||||
@ -258,8 +258,8 @@ class Export {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function formatSubscriberFields($subscriber_fields, $subscriber_custom_fields) {
|
function formatSubscriberFields($subscriber_fields, $subscriber_custom_fields) {
|
||||||
$bootstrap_menu = new BootStrapMenu();
|
$export_factory = new ImportExportFactory();
|
||||||
$translated_fields = $bootstrap_menu->getSubscriberFields();
|
$translated_fields = $export_factory->getSubscriberFields();
|
||||||
return array_map(function($field) use (
|
return array_map(function($field) use (
|
||||||
$translated_fields, $subscriber_custom_fields
|
$translated_fields, $subscriber_custom_fields
|
||||||
) {
|
) {
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace MailPoet\Subscribers\ImportExport\Import;
|
namespace MailPoet\Subscribers\ImportExport\Import;
|
||||||
|
|
||||||
use MailPoet\Models\NewsletterOption;
|
use MailPoet\Models\Newsletter;
|
||||||
use MailPoet\Models\Subscriber;
|
use MailPoet\Models\Subscriber;
|
||||||
use MailPoet\Models\SubscriberCustomField;
|
use MailPoet\Models\SubscriberCustomField;
|
||||||
use MailPoet\Models\SubscriberSegment;
|
use MailPoet\Models\SubscriberSegment;
|
||||||
use MailPoet\Subscribers\ImportExport\BootStrapMenu;
|
use MailPoet\Subscribers\ImportExport\ImportExportFactory;
|
||||||
use MailPoet\Util\Helpers;
|
use MailPoet\Util\Helpers;
|
||||||
|
|
||||||
class Import {
|
class Import {
|
||||||
@ -79,11 +79,11 @@ class Import {
|
|||||||
'errors' => array($e->getMessage())
|
'errors' => array($e->getMessage())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
$segments = new BootStrapMenu('import');
|
$import_factory = new ImportExportFactory('import');
|
||||||
$segments = $segments->getSegments();
|
$segments = $import_factory->getSegments();
|
||||||
$segments_with_welcome_notification =
|
$welcome_notifications_in_segments =
|
||||||
($created_subscribers || $updated_subscribers) ?
|
($created_subscribers || $updated_subscribers) ?
|
||||||
$this->getSegmentsWithWelcomeNotification($this->segments) :
|
Newsletter::getWelcomeNotificationsForSegments($this->segments) :
|
||||||
false;
|
false;
|
||||||
return array(
|
return array(
|
||||||
'result' => true,
|
'result' => true,
|
||||||
@ -91,8 +91,8 @@ class Import {
|
|||||||
'created' => count($created_subscribers),
|
'created' => count($created_subscribers),
|
||||||
'updated' => count($updated_subscribers),
|
'updated' => count($updated_subscribers),
|
||||||
'segments' => $segments,
|
'segments' => $segments,
|
||||||
'segments_with_welcome_notification' =>
|
'added_to_segment_with_welcome_notification' =>
|
||||||
($segments_with_welcome_notification) ? true : false
|
($welcome_notifications_in_segments) ? true : false
|
||||||
),
|
),
|
||||||
'profiler' => $this->timeExecution()
|
'profiler' => $this->timeExecution()
|
||||||
);
|
);
|
||||||
@ -371,23 +371,4 @@ class Import {
|
|||||||
$profiler_end = microtime(true);
|
$profiler_end = microtime(true);
|
||||||
return ($profiler_end - $this->profiler_start) / 60;
|
return ($profiler_end - $this->profiler_start) / 60;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSegmentsWithWelcomeNotification($segments_ids) {
|
|
||||||
return NewsletterOption::table_alias('options')
|
|
||||||
->join(
|
|
||||||
MP_NEWSLETTERS_TABLE,
|
|
||||||
'newsletters.id = options.newsletter_id',
|
|
||||||
'newsletters'
|
|
||||||
)
|
|
||||||
->join(
|
|
||||||
MP_NEWSLETTER_OPTION_FIELDS_TABLE,
|
|
||||||
'option_fields.id = options.option_field_id',
|
|
||||||
'option_fields'
|
|
||||||
)
|
|
||||||
->whereNull('newsletters.deleted_at')
|
|
||||||
->where('newsletters.type', 'welcome')
|
|
||||||
->where('option_fields.name', 'segment')
|
|
||||||
->whereIn('options.value', $segments_ids)
|
|
||||||
->findMany();
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -5,7 +5,7 @@ use MailPoet\Models\CustomField;
|
|||||||
use MailPoet\Models\Segment;
|
use MailPoet\Models\Segment;
|
||||||
use MailPoet\Util\Helpers;
|
use MailPoet\Util\Helpers;
|
||||||
|
|
||||||
class BootStrapMenu {
|
class ImportExportFactory {
|
||||||
public $action;
|
public $action;
|
||||||
|
|
||||||
function __construct($action = null) {
|
function __construct($action = null) {
|
@ -4,7 +4,7 @@
|
|||||||
<div id="mailpoet_subscribers_export" class="wrap">
|
<div id="mailpoet_subscribers_export" class="wrap">
|
||||||
<h1 class="title">
|
<h1 class="title">
|
||||||
<%= __('Export') %>
|
<%= __('Export') %>
|
||||||
<a class="page-title-action" href="?page=mailpoet-subscribers#/"><%= __('Back to list') %></a>
|
<a class="page-title-action" href="?page=mailpoet-subscribers#/"><%= __('Back to subscribers') %></a>
|
||||||
</h1>
|
</h1>
|
||||||
<% if segments is empty %>
|
<% if segments is empty %>
|
||||||
<div class="notice">
|
<div class="notice">
|
||||||
|
@ -81,7 +81,7 @@
|
|||||||
</th>
|
</th>
|
||||||
<td>
|
<td>
|
||||||
<input type="text" id="mailchimp_key">
|
<input type="text" id="mailchimp_key">
|
||||||
<button id="mailchimp_key_verify" class="button" disabled><%= __('Verify') %></button>
|
<button id="mailchimp_key_verify" class="button"><%= __('Verify') %></button>
|
||||||
<span class="mailpoet_mailchimp-key-status"></span>
|
<span class="mailpoet_mailchimp-key-status"></span>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script id="subscribers_data_parse_results_template" type="text/x-handlebars-template">
|
<script id="subscribers_data_parse_results_template" type="text/x-handlebars-template">
|
||||||
<div class="notice">
|
<div class="error">
|
||||||
<ul>
|
<ul>
|
||||||
<li>{{{notice}}}</li>
|
<li>{{{notice}}}</li>
|
||||||
<li><a class="mailpoet_subscribers_data_parse_results_details_show"
|
<li><a class="mailpoet_subscribers_data_parse_results_details_show"
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<div id="step3" class="mailpoet_hidden">
|
<div id="step3" class="mailpoet_hidden">
|
||||||
<div id="subscribers_data_import_results" class="updated notice mailpoet_hidden">
|
<div id="subscribers_data_import_results" class="updated mailpoet_hidden">
|
||||||
<!-- Template data -->
|
<!-- Template data -->
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -28,7 +28,7 @@
|
|||||||
{{#if no_action}}
|
{{#if no_action}}
|
||||||
<li><%= __('No new subscribers were found/added.') %></li>
|
<li><%= __('No new subscribers were found/added.') %></li>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{#if segments_with_welcome_notification}}
|
{{#if added_to_segment_with_welcome_notification}}
|
||||||
<li><%= __('Important note: imported subscribers will not receive any welcome emails.') %></li>
|
<li><%= __('Important note: imported subscribers will not receive any welcome emails.') %></li>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</ul>
|
</ul>
|
||||||
|
Reference in New Issue
Block a user