Fix init/hooks so that we properly initialize db/plugin
- Added activation hook in main file (mailpoet.php) - auto deactivate plugin in case of fatal errors during init
This commit is contained in:
@ -9,13 +9,6 @@ class Activator {
|
|||||||
function __construct() {
|
function __construct() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function init() {
|
|
||||||
register_activation_hook(
|
|
||||||
Env::$file,
|
|
||||||
array($this, 'activate')
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function activate() {
|
function activate() {
|
||||||
$migrator = new Migrator();
|
$migrator = new Migrator();
|
||||||
$migrator->up();
|
$migrator->up();
|
||||||
|
@ -18,22 +18,27 @@ class Initializer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
$this->setupDB();
|
try {
|
||||||
$this->setupActivator();
|
$this->setupDB();
|
||||||
$this->setupRenderer();
|
$this->setupRenderer();
|
||||||
$this->setupLocalizer();
|
$this->setupLocalizer();
|
||||||
$this->setupMenu();
|
$this->setupMenu();
|
||||||
$this->setupRouter();
|
$this->setupRouter();
|
||||||
$this->setupWidget();
|
$this->setupWidget();
|
||||||
$this->setupAnalytics();
|
$this->setupAnalytics();
|
||||||
$this->setupPermissions();
|
$this->setupPermissions();
|
||||||
$this->setupChangelog();
|
$this->setupChangelog();
|
||||||
$this->setupPublicAPI();
|
$this->setupPublicAPI();
|
||||||
$this->runQueueSupervisor();
|
$this->runQueueSupervisor();
|
||||||
$this->setupShortcodes();
|
$this->setupShortcodes();
|
||||||
$this->setupHooks();
|
$this->setupHooks();
|
||||||
$this->setupPages();
|
$this->setupPages();
|
||||||
$this->setupImages();
|
$this->setupImages();
|
||||||
|
} catch(\Exception $e) {
|
||||||
|
// if anything goes wrong during init
|
||||||
|
// automatically deactivate the plugin
|
||||||
|
deactivate_plugins(Env::$file);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupDB() {
|
function setupDB() {
|
||||||
@ -81,9 +86,10 @@ class Initializer {
|
|||||||
define('MP_NEWSLETTER_STATISTICS_TABLE', $newsletter_statistics);
|
define('MP_NEWSLETTER_STATISTICS_TABLE', $newsletter_statistics);
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupActivator() {
|
function runPopulator() {
|
||||||
$activator = new Activator();
|
$this->init();
|
||||||
$activator->init();
|
$populator = new Populator();
|
||||||
|
$populator->up();
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupRenderer() {
|
function setupRenderer() {
|
||||||
@ -138,6 +144,7 @@ class Initializer {
|
|||||||
$shortcodes = new Shortcodes();
|
$shortcodes = new Shortcodes();
|
||||||
$shortcodes->init();
|
$shortcodes->init();
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupHooks() {
|
function setupHooks() {
|
||||||
$hooks = new Hooks();
|
$hooks = new Hooks();
|
||||||
$hooks->init();
|
$hooks->init();
|
||||||
@ -153,7 +160,7 @@ class Initializer {
|
|||||||
try {
|
try {
|
||||||
$supervisor = new Supervisor();
|
$supervisor = new Supervisor();
|
||||||
$supervisor->checkDaemon();
|
$supervisor->checkDaemon();
|
||||||
} catch (\Exception $e) {
|
} catch(\Exception $e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace MailPoet\Config;
|
namespace MailPoet\Config;
|
||||||
|
|
||||||
if (!defined('ABSPATH')) exit;
|
if(!defined('ABSPATH')) exit;
|
||||||
|
|
||||||
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
|
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
|
||||||
|
|
||||||
|
15
mailpoet.php
15
mailpoet.php
@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
use \MailPoet\Config\Initializer;
|
use \MailPoet\Config\Initializer;
|
||||||
|
use \MailPoet\Config\Migrator;
|
||||||
|
|
||||||
if (!defined('ABSPATH')) exit;
|
if (!defined('ABSPATH')) exit;
|
||||||
|
|
||||||
@ -26,7 +27,13 @@ require 'vendor/autoload.php';
|
|||||||
define('MAILPOET_VERSION', '0.0.12');
|
define('MAILPOET_VERSION', '0.0.12');
|
||||||
|
|
||||||
$initializer = new Initializer(array(
|
$initializer = new Initializer(array(
|
||||||
'file' => __FILE__,
|
'file' => __FILE__,
|
||||||
'version' => MAILPOET_VERSION
|
'version' => MAILPOET_VERSION
|
||||||
));
|
));
|
||||||
$initializer->init();
|
|
||||||
|
$migrator = new Migrator();
|
||||||
|
|
||||||
|
register_activation_hook(__FILE__, array($migrator, 'up'));
|
||||||
|
register_activation_hook(__FILE__, array($initializer, 'runPopulator'));
|
||||||
|
|
||||||
|
add_action('init', array($initializer, 'init'));
|
Reference in New Issue
Block a user