Refactor changelog check method
[MAILPOET-1732]
This commit is contained in:
committed by
M. Shull
parent
58d2bbab1a
commit
74bee5ec1e
@ -43,37 +43,44 @@ class Changelog {
|
|||||||
|
|
||||||
function check() {
|
function check() {
|
||||||
$version = $this->settings->get('version');
|
$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();
|
$mp2_migrator = new MP2Migrator();
|
||||||
if (!in_array($_GET['page'], array('mailpoet-migration', 'mailpoet-settings')) && $mp2_migrator->isMigrationStartedAndNotCompleted()) {
|
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
|
// Force the redirection if the migration has started but is not completed
|
||||||
$redirect_url = WPFunctions::get()->adminUrl('admin.php?page=mailpoet-migration');
|
return $this->terminateWithRedirect($this->wp->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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($redirect_url !== null) {
|
if ($version === null && $mp2_migrator->isMigrationNeeded()) {
|
||||||
// save version number
|
$this->terminateWithRedirect($this->wp->adminUrl('admin.php?page=mailpoet-migration'));
|
||||||
$this->settings->set('version', Env::$version);
|
|
||||||
|
|
||||||
Url::redirectWithReferer($redirect_url);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user