Refactor changelog check method

[MAILPOET-1732]
This commit is contained in:
Rostislav Wolny
2019-03-22 11:01:41 +01:00
committed by M. Shull
parent 58d2bbab1a
commit 74bee5ec1e

View File

@ -43,37 +43,44 @@ class Changelog {
function check() {
$version = $this->settings->get('version');
$redirect_url = null;
$this->checkMp2Migration($version);
if ($version === null) {
$this->setupNewInstallation();
$this->checkWelcomeWizard();
}
}
private function checkMp2Migration($version) {
$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 = WPFunctions::get()->adminUrl('admin.php?page=mailpoet-migration');
} else {
if ($version === null) {
// new install
if ($mp2_migrator->isMigrationNeeded()) {
// Migration from MP2
$redirect_url = WPFunctions::get()->adminUrl('admin.php?page=mailpoet-migration');
} else {
$skip_wizard = $this->wp->applyFilters('mailpoet_skip_welcome_wizard', false);
$redirect_url = $skip_wizard ? null : WPFunctions::get()->adminUrl('admin.php?page=mailpoet-welcome-wizard');
// ensure there was no MP2 migration (migration resets $version so it must be checked)
if ($this->settings->get('mailpoet_migration_started') === null) {
$this->settings->set('show_intro', true);
}
}
$this->settings->set('show_congratulate_after_first_newsletter', true);
$this->settings->set('show_poll_success_delivery_preview', true);
}
return $this->terminateWithRedirect($this->wp->adminUrl('admin.php?page=mailpoet-migration'));
}
if ($redirect_url !== null) {
// save version number
$this->settings->set('version', Env::$version);
Url::redirectWithReferer($redirect_url);
if ($version === null && $mp2_migrator->isMigrationNeeded()) {
$this->terminateWithRedirect($this->wp->adminUrl('admin.php?page=mailpoet-migration'));
}
}
private function setupNewInstallation() {
// ensure there was no MP2 migration (migration resets $version so it must be checked)
if ($this->settings->get('mailpoet_migration_started') === null) {
$this->settings->set('show_intro', true);
}
$this->settings->set('show_congratulate_after_first_newsletter', true);
$this->settings->set('show_poll_success_delivery_preview', true);
}
private function checkWelcomeWizard() {
$skip_wizard = $this->wp->applyFilters('mailpoet_skip_welcome_wizard', false);
if (!$skip_wizard) {
$this->terminateWithRedirect($this->wp->adminUrl('admin.php?page=mailpoet-welcome-wizard'));
}
}
private function terminateWithRedirect($redirect_url) {
// save version number
$this->settings->set('version', Env::$version);
Url::redirectWithReferer($redirect_url);
}
}