Merge pull request #1489 from mailpoet/migration-notice

Migration notice [MAILPOET-1492]
This commit is contained in:
Michelle Shull
2018-09-20 14:13:17 -04:00
committed by GitHub
10 changed files with 153 additions and 39 deletions

View File

@@ -1,8 +1,8 @@
import jQuery from 'jquery';
jQuery(($) => {
$(document).on('click', '.notice-php-warning .notice-dismiss', function xyz() {
const type = $(this).closest('.notice-php-warning').data('notice');
$(document).on('click', '.mailpoet-dismissible-notice .notice-dismiss', function dismiss() {
const type = $(this).closest('.mailpoet-dismissible-notice').data('notice');
$.ajax(window.ajaxurl,
{
type: 'POST',

View File

@@ -8,6 +8,7 @@ use MailPoet\Models\Setting;
use MailPoet\Router;
use MailPoet\Util\ConflictResolver;
use MailPoet\Util\Helpers;
use MailPoet\Util\Notices\PermanentNotices;
use MailPoet\WP\Notice as WPNotice;
if(!defined('ABSPATH')) exit;
@@ -144,7 +145,7 @@ class Initializer {
$this->setupPages();
$this->setupPHPVersionWarnings();
$this->setupPermanentNotices();
$this->setupDeactivationSurvey();
do_action('mailpoet_initialized', MAILPOET_VERSION);
@@ -289,9 +290,9 @@ class Initializer {
$erasers->init();
}
function setupPHPVersionWarnings() {
$php_version_warnings = new PHPVersionWarnings();
$php_version_warnings->init(phpversion(), Menu::isOnMailPoetAdminPage());
function setupPermanentNotices() {
$notices = new PermanentNotices();
$notices->init();
}
function handleFailedInitialization($exception) {

View File

@@ -10,6 +10,7 @@ use MailPoet\Models\Setting;
use MailPoet\Models\Subscriber;
use MailPoet\Models\SubscriberCustomField;
use MailPoet\Models\SubscriberSegment;
use MailPoet\Util\Notices\AfterMigrationNotice;
use MailPoet\Util\ProgressBar;
if(!defined('ABSPATH')) exit;
@@ -169,6 +170,8 @@ class MP2Migrator {
if(!$this->importStopped()) {
Setting::setValue('mailpoet_migration_complete', true);
$this->log(mb_strtoupper(__('Import complete', 'mailpoet'), 'UTF-8'));
$after_migration_notice = new AfterMigrationNotice();
$after_migration_notice->enable();
}
$this->log(sprintf('=== ' . mb_strtoupper(__('End import', 'mailpoet'), 'UTF-8') . ' %s ===', $datetime->formatTime(time(), \MailPoet\WP\DateTime::DEFAULT_DATE_TIME_FORMAT)));

View File

@@ -0,0 +1,40 @@
<?php
namespace MailPoet\Util\Notices;
use MailPoet\Models\Setting;
use MailPoet\Util\Helpers;
class AfterMigrationNotice {
const OPTION_NAME = 'mailpoet_display_after_migration_notice';
function enable() {
Setting::setValue(self::OPTION_NAME, true);
}
function disable() {
Setting::setValue(self::OPTION_NAME, false);
}
function init($should_display) {
if($should_display && Setting::getValue(self::OPTION_NAME, false)) {
return $this->display();
}
}
private function display() {
$message = Helpers::replaceLinkTags(
__('Congrats! Youre progressing well so far. Complete your upgrade thanks to this [link]checklist[/link].', 'mailpoet'),
'https://beta.docs.mailpoet.com/article/199-checklist-after-migrating-to-mailpoet3',
array('target' => '_blank')
);
$extra_classes = 'mailpoet-dismissible-notice is-dismissible';
$data_notice_name = self::OPTION_NAME;
\MailPoet\WP\Notice::displaySuccess($message, $extra_classes, $data_notice_name);
return $message;
}
}

View File

@@ -1,6 +1,6 @@
<?php
namespace MailPoet\Config;
namespace MailPoet\Util\Notices;
use MailPoet\Util\Helpers;
use MailPoet\WP\Notice as WPNotice;
@@ -8,34 +8,30 @@ use MailPoet\WP\Notice as WPNotice;
class PHPVersionWarnings {
const DISMISS_NOTICE_TIMEOUT_SECONDS = 2592000; // 30 days
const OPTION_NAME = 'dismissed-php-version-outdated-notice';
function init($php_version, $is_enabled) {
add_action('wp_ajax_dismissed_notice_handler', array(
$this,
'ajaxDismissNoticeHandler'
));
function init($php_version, $should_display) {
if($is_enabled && $this->isOutdatedPHPVersion($php_version)) {
return $this->displayError($php_version);
if($should_display && $this->isOutdatedPHPVersion($php_version)) {
return $this->display($php_version);
}
}
function isOutdatedPHPVersion($php_version) {
return version_compare($php_version, '5.6', '<') && !get_transient('dismissed-php-version-outdated-notice');
return version_compare($php_version, '5.6', '<') && !get_transient(self::OPTION_NAME);
}
function displayError($php_version) {
function display($php_version) {
$error_string = __('Your website is running on PHP %s. MailPoet requires version 5.6. Please consider upgrading your site\'s PHP version. [link]Your host can help you.[/link]', 'mailpoet');
$error_string = sprintf($error_string, $php_version);
$error = Helpers::replaceLinkTags($error_string, 'https://beta.docs.mailpoet.com/article/251-upgrading-the-websites-php-version', array('target' => '_blank'));
$extra_classes = 'notice-php-warning is-dismissible';
$data_notice_name = 'php-version-outdated';
$extra_classes = 'mailpoet-dismissible-notice is-dismissible';
return WPNotice::displayError($error, $extra_classes, $data_notice_name);
return WPNotice::displayError($error, $extra_classes, self::OPTION_NAME);
}
function ajaxDismissNoticeHandler() {
set_transient('dismissed-php-version-outdated-notice', true, self::DISMISS_NOTICE_TIMEOUT_SECONDS);
function disable() {
set_transient(self::OPTION_NAME, true, self::DISMISS_NOTICE_TIMEOUT_SECONDS);
}
}

View File

@@ -0,0 +1,47 @@
<?php
namespace MailPoet\Util\Notices;
use MailPoet\Config\Menu;
class PermanentNotices {
/** @var PHPVersionWarnings */
private $php_version_warnings;
/** @var AfterMigrationNotice */
private $after_migration_notice;
public function __construct() {
$this->php_version_warnings = new PHPVersionWarnings();
$this->after_migration_notice = new AfterMigrationNotice();
}
public function init() {
add_action('wp_ajax_dismissed_notice_handler', array(
$this,
'ajaxDismissNoticeHandler'
));
$this->php_version_warnings->init(phpversion(), Menu::isOnMailPoetAdminPage());
$this->after_migration_notice->init(
Menu::isOnMailPoetAdminPage()
&& $_GET['page'] !== 'mailpoet-welcome-wizard'
);
}
function ajaxDismissNoticeHandler() {
if(!isset($_POST['type'])) return;
switch($_POST['type']) {
case (PHPVersionWarnings::OPTION_NAME):
$this->php_version_warnings->disable();
break;
case (AfterMigrationNotice::OPTION_NAME):
$this->after_migration_notice->disable();
break;
}
}
}

View File

@@ -18,7 +18,7 @@ class ImportTest extends \MailPoetTest {
$this->subscribers_custom_fields = array((string)$custom_field->id);
$this->segment_1 = Segment::createOrUpdate(array('name' => 'Segment 1'));
$this->segment_2 = Segment::createOrUpdate(array('name' => 'Segment 2'));
$this->data = array(
$this->test_data = array(
'subscribers' => array(
array(
'Adam',
@@ -50,16 +50,16 @@ class ImportTest extends \MailPoetTest {
'last_name',
'email'
);
$this->import = new Import($this->data);
$this->import = new Import($this->test_data);
$this->subscribers_data = $this->import->transformSubscribersData(
$this->data['subscribers'],
$this->data['columns']
$this->test_data['subscribers'],
$this->test_data['columns']
);
}
function testItConstructs() {
expect(is_array($this->import->subscribers_data))->true();
expect($this->import->segments_ids)->equals($this->data['segments']);
expect($this->import->segments_ids)->equals($this->test_data['segments']);
expect(is_array($this->import->subscribers_fields))->true();
expect(is_array($this->import->subscribers_custom_fields))->true();
expect($this->import->subscribers_count)->equals(2);
@@ -68,7 +68,7 @@ class ImportTest extends \MailPoetTest {
}
function testItChecksForRequiredDataFields() {
$data = $this->data;
$data = $this->test_data;
// exception should be thrown when one or more fields do not exist
unset($data['timestamp']);
try {
@@ -78,11 +78,11 @@ class ImportTest extends \MailPoetTest {
expect($e->getMessage())->equals('Missing or invalid import data.');
}
// exception should not be thrown when all fields exist
$this->import->validateImportData($this->data);
$this->import->validateImportData($this->test_data);
}
function testItValidatesColumnNames() {
$data = $this->data;
$data = $this->test_data;
$data['columns']['test) values ((ExtractValue(1,CONCAT(0x5c, (SELECT version())))))%23'] = true;
try {
$this->import->validateImportData($data);
@@ -144,13 +144,13 @@ class ImportTest extends \MailPoetTest {
function testItTransformsSubscribers() {
$custom_field = $this->subscribers_custom_fields[0];
expect($this->import->subscribers_data['first_name'][0])
->equals($this->data['subscribers'][0][0]);
->equals($this->test_data['subscribers'][0][0]);
expect($this->import->subscribers_data['last_name'][0])
->equals($this->data['subscribers'][0][1]);
->equals($this->test_data['subscribers'][0][1]);
expect($this->import->subscribers_data['email'][0])
->equals($this->data['subscribers'][0][2]);
->equals($this->test_data['subscribers'][0][2]);
expect($this->import->subscribers_data[$custom_field][0])
->equals($this->data['subscribers'][0][3]);
->equals($this->test_data['subscribers'][0][3]);
}
function testItSplitsSubscribers() {
@@ -418,7 +418,7 @@ class ImportTest extends \MailPoetTest {
}
function testItDoesNotUpdateExistingSubscribersStatusWhenStatusColumnIsPresent() {
$data = $this->data;
$data = $this->test_data;
$data['columns']['status'] = array('index' => 4);
$data['subscribers'][0][] = 'subscribed';
$data['subscribers'][1][] = 'subscribed';
@@ -438,7 +438,7 @@ class ImportTest extends \MailPoetTest {
}
function testItImportsNewsSubscribersWithSubscribedStatus() {
$data = $this->data;
$data = $this->test_data;
$data['columns']['status'] = array('index' => 4);
$data['subscribers'][0][] = 'unsubscribed';
$data['subscribers'][1][] = 'unsubscribed';
@@ -474,7 +474,7 @@ class ImportTest extends \MailPoetTest {
// subscribers must be added to segments
foreach($db_subscribers as $db_subscriber) {
$subscriber_segment = SubscriberSegment::where('subscriber_id', $db_subscriber)
->where('segment_id', $this->data['segments'][0])
->where('segment_id', $this->test_data['segments'][0])
->findOne();
expect($subscriber_segment)->notEmpty();
}

View File

@@ -0,0 +1,27 @@
<?php
namespace MailPoet\Util\Notices;
class AfterMigrationNoticeTest extends \MailPoetTest {
public function testItDoesntDisplayIfShouldntDisplay() {
$notice = new AfterMigrationNotice();
$result = $notice->init(false);
expect($result)->isEmpty();
}
public function testItDoesntDisplayIfDisabled() {
$notice = new AfterMigrationNotice();
$notice->disable();
$result = $notice->init(true);
expect($result)->isEmpty();
}
public function testItDisplayIfEnabled() {
$notice = new AfterMigrationNotice();
$notice->enable();
$result = $notice->init(true);
expect($result)->notEmpty();
}
}

View File

@@ -1,6 +1,6 @@
<?php
namespace MailPoet\Config;
namespace MailPoet\Util\Notices;
use AspectMock\Test as Mock;

View File

@@ -239,7 +239,7 @@ var adminConfig = {
'analytics_event',
'help-tooltip.jsx',
'help-tooltip',
'notice-php-warning.jsx',
'dismissible-notice.jsx',
],
admin_vendor: [
'react',