Use DI to inject MP2Migrator to MP2Migrator API endpoint and Changelog
[MAILPOET-2203]
This commit is contained in:
committed by
Rostislav Wolný
parent
92495b20a5
commit
47861cdf19
@ -11,10 +11,12 @@ class MP2Migrator extends APIEndpoint {
|
||||
public $permissions = [
|
||||
'global' => AccessControl::PERMISSION_MANAGE_SETTINGS,
|
||||
];
|
||||
|
||||
/** @var \MailPoet\Config\MP2Migrator */
|
||||
private $MP2Migrator;
|
||||
|
||||
public function __construct() {
|
||||
$this->MP2Migrator = new \MailPoet\Config\MP2Migrator();
|
||||
public function __construct(\MailPoet\Config\MP2Migrator $MP2Migrator) {
|
||||
$this->MP2Migrator = $MP2Migrator;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -25,7 +27,7 @@ class MP2Migrator extends APIEndpoint {
|
||||
*/
|
||||
public function import($data) {
|
||||
try {
|
||||
$process = $this->MP2Migrator->import($data);
|
||||
$process = $this->MP2Migrator->import();
|
||||
return $this->successResponse($process);
|
||||
} catch (\Exception $e) {
|
||||
return $this->errorResponse([
|
||||
|
@ -20,16 +20,21 @@ class Changelog {
|
||||
/** @var Url */
|
||||
private $url_helper;
|
||||
|
||||
/** @var MP2Migrator */
|
||||
private $mp2_migrator;
|
||||
|
||||
function __construct(
|
||||
SettingsController $settings,
|
||||
WPFunctions $wp,
|
||||
Helper $wooCommerceHelper,
|
||||
Url $url_helper
|
||||
Url $url_helper,
|
||||
MP2Migrator $mp2_migrator
|
||||
) {
|
||||
$this->wooCommerceHelper = $wooCommerceHelper;
|
||||
$this->settings = $settings;
|
||||
$this->wp = $wp;
|
||||
$this->url_helper = $url_helper;
|
||||
$this->mp2_migrator = $mp2_migrator;
|
||||
}
|
||||
|
||||
function init() {
|
||||
@ -67,13 +72,12 @@ class Changelog {
|
||||
}
|
||||
|
||||
private function checkMp2Migration($version) {
|
||||
$mp2_migrator = new MP2Migrator();
|
||||
if (!in_array($_GET['page'], ['mailpoet-migration', 'mailpoet-settings']) && $mp2_migrator->isMigrationStartedAndNotCompleted()) {
|
||||
if (!in_array($_GET['page'], ['mailpoet-migration', 'mailpoet-settings']) && $this->mp2_migrator->isMigrationStartedAndNotCompleted()) {
|
||||
// Force the redirection if the migration has started but is not completed
|
||||
return $this->terminateWithRedirect($this->wp->adminUrl('admin.php?page=mailpoet-migration'));
|
||||
}
|
||||
|
||||
if ($version === null && $mp2_migrator->isMigrationNeeded()) {
|
||||
if ($version === null && $this->mp2_migrator->isMigrationNeeded()) {
|
||||
$this->terminateWithRedirect($this->wp->adminUrl('admin.php?page=mailpoet-migration'));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user