From 74bee5ec1e2465fdbec27076ccfb7716ad9f0e2c Mon Sep 17 00:00:00 2001 From: Rostislav Wolny Date: Fri, 22 Mar 2019 11:01:41 +0100 Subject: [PATCH] Refactor changelog check method [MAILPOET-1732] --- lib/Config/Changelog.php | 57 ++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/lib/Config/Changelog.php b/lib/Config/Changelog.php index 733825d366..e7b654d194 100644 --- a/lib/Config/Changelog.php +++ b/lib/Config/Changelog.php @@ -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); + } }