- 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')
|
||||
.find('a.mailpoet_process'),
|
||||
mailChimpKeyInputElement = jQuery('#mailchimp_key'),
|
||||
mailChimpKeyVerifyButtonEelement = jQuery('#mailchimp_key_verify'),
|
||||
mailChimpKeyVerifyButtonElement = jQuery('#mailchimp_key_verify'),
|
||||
mailChimpListsContainerElement = jQuery('#mailchimp_lists'),
|
||||
mailChimpProcessButtonElement =
|
||||
jQuery('#method_mailchimp > div.mailpoet_method_process')
|
||||
@ -178,15 +178,11 @@ define(
|
||||
jQuery('.mailpoet_mailchimp-key-status')
|
||||
.html('')
|
||||
.removeClass('mailpoet_mailchimp-ok mailpoet_mailchimp-error');
|
||||
mailChimpKeyVerifyButtonEelement.prop('disabled', true);
|
||||
toggleNextStepButton(mailChimpProcessButtonElement, 'off');
|
||||
}
|
||||
else {
|
||||
mailChimpKeyVerifyButtonEelement.prop('disabled', false);
|
||||
}
|
||||
});
|
||||
|
||||
mailChimpKeyVerifyButtonEelement.click(function () {
|
||||
mailChimpKeyVerifyButtonElement.click(function () {
|
||||
MailPoet.Modal.loading(true);
|
||||
MailPoet.Ajax.post({
|
||||
endpoint: 'ImportExport',
|
||||
@ -1051,7 +1047,7 @@ define(
|
||||
importResults.created = response.data.created;
|
||||
importResults.updated = response.data.updated;
|
||||
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();
|
||||
})
|
||||
@ -1119,10 +1115,8 @@ define(
|
||||
.replace('%1$s', '<strong>' + importData.step2.updated.toLocaleString() + '</strong>')
|
||||
.replace('%2$s', '"' + importData.step2.segments.join('", "') + '"')
|
||||
: false,
|
||||
no_action: (!importData.step2.created && !importData.step2.updated)
|
||||
? true
|
||||
: false,
|
||||
segments_with_welcome_notification: importData.step2.segments_with_welcome_notification
|
||||
no_action: (!importData.step2.created && !importData.step2.updated),
|
||||
added_to_segment_with_welcome_notification: importData.step2.added_to_segment_with_welcome_notification
|
||||
};
|
||||
|
||||
jQuery('#subscribers_data_import_results')
|
||||
|
@ -10,7 +10,7 @@ use MailPoet\Models\Setting;
|
||||
use MailPoet\Settings\Charsets;
|
||||
use MailPoet\Settings\Hosts;
|
||||
use MailPoet\Settings\Pages;
|
||||
use MailPoet\Subscribers\ImportExport\BootStrapMenu;
|
||||
use MailPoet\Subscribers\ImportExport\ImportExportFactory;
|
||||
use MailPoet\Util\DKIM;
|
||||
use MailPoet\Util\Permissions;
|
||||
use MailPoet\Listing;
|
||||
@ -438,14 +438,14 @@ class Menu {
|
||||
}
|
||||
|
||||
function import() {
|
||||
$import = new BootStrapMenu('import');
|
||||
$import = new ImportExportFactory('import');
|
||||
$data = $import->bootstrap();
|
||||
$data['sub_menu'] = 'mailpoet-subscribers';
|
||||
echo $this->renderer->render('subscribers/importExport/import.html', $data);
|
||||
}
|
||||
|
||||
function export() {
|
||||
$export = new BootStrapMenu('export');
|
||||
$export = new ImportExportFactory('export');
|
||||
$data = $export->bootstrap();
|
||||
$data['sub_menu'] = 'mailpoet-subscribers';
|
||||
echo $this->renderer->render('subscribers/importExport/export.html', $data);
|
||||
|
@ -5,6 +5,8 @@ if(!defined('ABSPATH')) exit;
|
||||
|
||||
class Newsletter extends Model {
|
||||
public static $_table = MP_NEWSLETTERS_TABLE;
|
||||
const TYPE_WELCOME = 'wecome';
|
||||
const TYPE_NOTIFICATION = 'notification';
|
||||
|
||||
function __construct() {
|
||||
parent::__construct();
|
||||
@ -259,4 +261,25 @@ class Newsletter extends Model {
|
||||
$newsletter->save();
|
||||
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\Subscriber;
|
||||
use MailPoet\Models\SubscriberSegment;
|
||||
use MailPoet\Subscribers\ImportExport\BootStrapMenu;
|
||||
use MailPoet\Subscribers\ImportExport\ImportExportFactory;
|
||||
use MailPoet\Util\Helpers;
|
||||
use MailPoet\Util\XLSXWriter;
|
||||
|
||||
@ -258,8 +258,8 @@ class Export {
|
||||
}
|
||||
|
||||
function formatSubscriberFields($subscriber_fields, $subscriber_custom_fields) {
|
||||
$bootstrap_menu = new BootStrapMenu();
|
||||
$translated_fields = $bootstrap_menu->getSubscriberFields();
|
||||
$export_factory = new ImportExportFactory();
|
||||
$translated_fields = $export_factory->getSubscriberFields();
|
||||
return array_map(function($field) use (
|
||||
$translated_fields, $subscriber_custom_fields
|
||||
) {
|
||||
|
@ -1,11 +1,11 @@
|
||||
<?php
|
||||
namespace MailPoet\Subscribers\ImportExport\Import;
|
||||
|
||||
use MailPoet\Models\NewsletterOption;
|
||||
use MailPoet\Models\Newsletter;
|
||||
use MailPoet\Models\Subscriber;
|
||||
use MailPoet\Models\SubscriberCustomField;
|
||||
use MailPoet\Models\SubscriberSegment;
|
||||
use MailPoet\Subscribers\ImportExport\BootStrapMenu;
|
||||
use MailPoet\Subscribers\ImportExport\ImportExportFactory;
|
||||
use MailPoet\Util\Helpers;
|
||||
|
||||
class Import {
|
||||
@ -79,11 +79,11 @@ class Import {
|
||||
'errors' => array($e->getMessage())
|
||||
);
|
||||
}
|
||||
$segments = new BootStrapMenu('import');
|
||||
$segments = $segments->getSegments();
|
||||
$segments_with_welcome_notification =
|
||||
$import_factory = new ImportExportFactory('import');
|
||||
$segments = $import_factory->getSegments();
|
||||
$welcome_notifications_in_segments =
|
||||
($created_subscribers || $updated_subscribers) ?
|
||||
$this->getSegmentsWithWelcomeNotification($this->segments) :
|
||||
Newsletter::getWelcomeNotificationsForSegments($this->segments) :
|
||||
false;
|
||||
return array(
|
||||
'result' => true,
|
||||
@ -91,8 +91,8 @@ class Import {
|
||||
'created' => count($created_subscribers),
|
||||
'updated' => count($updated_subscribers),
|
||||
'segments' => $segments,
|
||||
'segments_with_welcome_notification' =>
|
||||
($segments_with_welcome_notification) ? true : false
|
||||
'added_to_segment_with_welcome_notification' =>
|
||||
($welcome_notifications_in_segments) ? true : false
|
||||
),
|
||||
'profiler' => $this->timeExecution()
|
||||
);
|
||||
@ -371,23 +371,4 @@ class Import {
|
||||
$profiler_end = microtime(true);
|
||||
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\Util\Helpers;
|
||||
|
||||
class BootStrapMenu {
|
||||
class ImportExportFactory {
|
||||
public $action;
|
||||
|
||||
function __construct($action = null) {
|
@ -4,7 +4,7 @@
|
||||
<div id="mailpoet_subscribers_export" class="wrap">
|
||||
<h1 class="title">
|
||||
<%= __('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>
|
||||
<% if segments is empty %>
|
||||
<div class="notice">
|
||||
|
@ -81,7 +81,7 @@
|
||||
</th>
|
||||
<td>
|
||||
<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>
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -4,7 +4,7 @@
|
||||
</div>
|
||||
|
||||
<script id="subscribers_data_parse_results_template" type="text/x-handlebars-template">
|
||||
<div class="notice">
|
||||
<div class="error">
|
||||
<ul>
|
||||
<li>{{{notice}}}</li>
|
||||
<li><a class="mailpoet_subscribers_data_parse_results_details_show"
|
||||
|
@ -1,5 +1,5 @@
|
||||
<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 -->
|
||||
</div>
|
||||
|
||||
@ -28,7 +28,7 @@
|
||||
{{#if no_action}}
|
||||
<li><%= __('No new subscribers were found/added.') %></li>
|
||||
{{/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>
|
||||
{{/if}}
|
||||
</ul>
|
||||
|
Reference in New Issue
Block a user