diff --git a/assets/js/src/notice-php-warning.jsx b/assets/js/src/dismissible-notice.jsx similarity index 54% rename from assets/js/src/notice-php-warning.jsx rename to assets/js/src/dismissible-notice.jsx index 8e95a41761..94b1c5095a 100644 --- a/assets/js/src/notice-php-warning.jsx +++ b/assets/js/src/dismissible-notice.jsx @@ -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', diff --git a/lib/Config/Initializer.php b/lib/Config/Initializer.php index eecc1565c6..44723132ac 100644 --- a/lib/Config/Initializer.php +++ b/lib/Config/Initializer.php @@ -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) { diff --git a/lib/Config/MP2Migrator.php b/lib/Config/MP2Migrator.php index 77607727d8..36a2ae2b42 100644 --- a/lib/Config/MP2Migrator.php +++ b/lib/Config/MP2Migrator.php @@ -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))); diff --git a/lib/Util/Notices/AfterMigrationNotice.php b/lib/Util/Notices/AfterMigrationNotice.php new file mode 100644 index 0000000000..62ca535a66 --- /dev/null +++ b/lib/Util/Notices/AfterMigrationNotice.php @@ -0,0 +1,40 @@ +display(); + } + } + + private function display() { + $message = Helpers::replaceLinkTags( + __('Congrats! You’re 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; + } + +} diff --git a/lib/Config/PHPVersionWarnings.php b/lib/Util/Notices/PHPVersionWarnings.php similarity index 50% rename from lib/Config/PHPVersionWarnings.php rename to lib/Util/Notices/PHPVersionWarnings.php index e2ced87ec9..239cf85622 100644 --- a/lib/Config/PHPVersionWarnings.php +++ b/lib/Util/Notices/PHPVersionWarnings.php @@ -1,6 +1,6 @@ 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); } } diff --git a/lib/Util/Notices/PermanentNotices.php b/lib/Util/Notices/PermanentNotices.php new file mode 100644 index 0000000000..89631b9190 --- /dev/null +++ b/lib/Util/Notices/PermanentNotices.php @@ -0,0 +1,47 @@ +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; + } + } + +} + diff --git a/tests/unit/Subscribers/ImportExport/Import/ImportTest.php b/tests/unit/Subscribers/ImportExport/Import/ImportTest.php index d2b99bb143..c1b3e5c95c 100644 --- a/tests/unit/Subscribers/ImportExport/Import/ImportTest.php +++ b/tests/unit/Subscribers/ImportExport/Import/ImportTest.php @@ -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(); } diff --git a/tests/unit/Util/Notices/AfterMigrationNoticeTest.php b/tests/unit/Util/Notices/AfterMigrationNoticeTest.php new file mode 100644 index 0000000000..a14d63a49a --- /dev/null +++ b/tests/unit/Util/Notices/AfterMigrationNoticeTest.php @@ -0,0 +1,27 @@ +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(); + } + +} diff --git a/tests/unit/Config/PHPVersionWarningsTest.php b/tests/unit/Util/Notices/PHPVersionWarningsTest.php similarity index 98% rename from tests/unit/Config/PHPVersionWarningsTest.php rename to tests/unit/Util/Notices/PHPVersionWarningsTest.php index a39ad920e6..c8d109d859 100644 --- a/tests/unit/Config/PHPVersionWarningsTest.php +++ b/tests/unit/Util/Notices/PHPVersionWarningsTest.php @@ -1,6 +1,6 @@