New: Redirect the user to the migration page if the import has started but is not finished to prevent him from using MailPoet with incomplete data. So he can resume the import where it left off.

This commit is contained in:
fred
2017-06-07 11:59:35 +02:00
parent f5e985baa4
commit c07e1eff3c
3 changed files with 47 additions and 20 deletions

View File

@@ -10,7 +10,7 @@ define('mp2migrator', ['mailpoet', 'jquery'], function(MailPoet, jQuery) {
clearTimeout(MailPoet.MP2Migrator.displayLogs_timeout);
clearTimeout(MailPoet.MP2Migrator.updateProgressbar_timeout);
clearTimeout(MailPoet.MP2Migrator.update_wordpress_info_timeout);
MailPoet.MP2Migrator.updateDisplay();
setTimeout(MailPoet.MP2Migrator.updateDisplay, 1000)
},
stopLogger: function () {
@@ -18,8 +18,8 @@ define('mp2migrator', ['mailpoet', 'jquery'], function(MailPoet, jQuery) {
},
updateDisplay: function () {
MailPoet.MP2Migrator.displayLogs_timeout = setTimeout(MailPoet.MP2Migrator.displayLogs, 1000);
MailPoet.MP2Migrator.updateProgressbar_timeout = setTimeout(MailPoet.MP2Migrator.updateProgressbar, 1000);
MailPoet.MP2Migrator.displayLogs();
MailPoet.MP2Migrator.updateProgressbar();
},
displayLogs: function () {
@@ -55,12 +55,15 @@ define('mp2migrator', ['mailpoet', 'jquery'], function(MailPoet, jQuery) {
dataType: 'json'
}).always(function (result) {
// Move the progress bar
var progress = 100;
if(Number(result.total) !== 0) {
var progress = 0;
if((result.total !== undefined) && (Number(result.total) !== 0)) {
progress = Math.round(Number(result.current) / Number(result.total) * 100);
}
jQuery('#progressbar').progressbar('option', 'value', progress);
jQuery('#progresslabel').html(progress + '%');
if(Number(result.current !== 0)) {
jQuery('#skip-import').hide();
}
if(MailPoet.MP2Migrator.is_logging) {
MailPoet.MP2Migrator.updateProgressbar_timeout = setTimeout(MailPoet.MP2Migrator.updateProgressbar, 1000);
}
@@ -75,6 +78,8 @@ define('mp2migrator', ['mailpoet', 'jquery'], function(MailPoet, jQuery) {
// Disable the import button
MailPoet.MP2Migrator.import_button_label = jQuery('#import').val();
jQuery('#import').val(MailPoet.I18n.t('importing')).attr('disabled', 'disabled');
// Hide the Skip button
jQuery('#skip-import').hide();
// Show the stop button
jQuery('#stop-import').show();
@@ -174,6 +179,9 @@ define('mp2migrator', ['mailpoet', 'jquery'], function(MailPoet, jQuery) {
jQuery('#goto-welcome').click(function() {
MailPoet.MP2Migrator.gotoWelcomePage();
});
// Update the display
MailPoet.MP2Migrator.updateDisplay();
});
});

View File

@@ -34,18 +34,23 @@ class Changelog {
$version = Setting::getValue('version', null);
$redirect_url = null;
if($version === null) {
// new install
$mp2_migrator = new MP2Migrator();
if($mp2_migrator->isMigrationNeeded()) {
// Migration from MP2
$redirect_url = admin_url('admin.php?page=mailpoet-migration');
} else {
$redirect_url = admin_url('admin.php?page=mailpoet-welcome');
$mp2_migrator = new MP2Migrator();
if(!in_array($_GET['page'], array('mailpoet-migration', 'mailpoet-settings')) && $mp2_migrator->isMigrationStartedAndNotCompleted()) {
// Force the redirection if the migration has started but is not completed
$redirect_url = admin_url('admin.php?page=mailpoet-migration');
} else {
if($version === null) {
// new install
if($mp2_migrator->isMigrationNeeded()) {
// Migration from MP2
$redirect_url = admin_url('admin.php?page=mailpoet-migration');
} else {
$redirect_url = admin_url('admin.php?page=mailpoet-welcome');
}
} else if($version !== Env::$version) {
// update
$redirect_url = admin_url('admin.php?page=mailpoet-update');
}
} else if($version !== Env::$version) {
// update
$redirect_url = admin_url('admin.php?page=mailpoet-update');
}
if($redirect_url !== null) {

View File

@@ -58,6 +58,15 @@ class MP2Migrator {
}
}
/**
* Test if the migration is already started but is not completed
*
* @return boolean
*/
public function isMigrationStartedAndNotCompleted() {
return Setting::getValue('mailpoet_migration_started', false) && !Setting::getValue('mailpoet_migration_complete', false);
}
/**
* Test if the migration is needed
*
@@ -104,6 +113,10 @@ class MP2Migrator {
*
*/
public function init() {
if(!Setting::getValue('mailpoet_migration_started', false)) {
$this->emptyLog();
$this->progressbar->setTotalCount(0);
}
$this->enqueueScripts();
}
@@ -132,7 +145,6 @@ class MP2Migrator {
public function import() {
set_time_limit(self::IMPORT_TIMEOUT_IN_SECONDS);
ob_start();
$this->emptyLog();
$datetime = new \MailPoet\WP\DateTime();
$this->log(sprintf('=== ' . __('START IMPORT', 'mailpoet') . ' %s ===', $datetime->formatTime(time(), \MailPoet\WP\DateTime::DEFAULT_DATE_TIME_FORMAT)));
Setting::setValue('import_stopped', false); // Reset the stop import action
@@ -148,9 +160,11 @@ class MP2Migrator {
$this->importCustomFields();
$this->importSubscribers();
Setting::setValue('mailpoet_migration_complete', true);
$this->log(__('IMPORT COMPLETE', 'mailpoet'));
if(!$this->importStopped()) {
Setting::setValue('mailpoet_migration_complete', true);
$this->log(__('IMPORT COMPLETE', 'mailpoet'));
}
$this->log(sprintf('=== ' . __('END IMPORT', 'mailpoet') . ' %s ===', $datetime->formatTime(time(), \MailPoet\WP\DateTime::DEFAULT_DATE_TIME_FORMAT)));
$result = ob_get_contents();
ob_clean();