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 init() {
|
||||
register_activation_hook(
|
||||
Env::$file,
|
||||
array($this, 'activate')
|
||||
);
|
||||
}
|
||||
|
||||
function activate() {
|
||||
$migrator = new Migrator();
|
||||
$migrator->up();
|
||||
|
@ -18,8 +18,8 @@ class Initializer {
|
||||
}
|
||||
|
||||
function init() {
|
||||
try {
|
||||
$this->setupDB();
|
||||
$this->setupActivator();
|
||||
$this->setupRenderer();
|
||||
$this->setupLocalizer();
|
||||
$this->setupMenu();
|
||||
@ -34,6 +34,11 @@ class Initializer {
|
||||
$this->setupHooks();
|
||||
$this->setupPages();
|
||||
$this->setupImages();
|
||||
} catch(\Exception $e) {
|
||||
// if anything goes wrong during init
|
||||
// automatically deactivate the plugin
|
||||
deactivate_plugins(Env::$file);
|
||||
}
|
||||
}
|
||||
|
||||
function setupDB() {
|
||||
@ -81,9 +86,10 @@ class Initializer {
|
||||
define('MP_NEWSLETTER_STATISTICS_TABLE', $newsletter_statistics);
|
||||
}
|
||||
|
||||
function setupActivator() {
|
||||
$activator = new Activator();
|
||||
$activator->init();
|
||||
function runPopulator() {
|
||||
$this->init();
|
||||
$populator = new Populator();
|
||||
$populator->up();
|
||||
}
|
||||
|
||||
function setupRenderer() {
|
||||
@ -138,6 +144,7 @@ class Initializer {
|
||||
$shortcodes = new Shortcodes();
|
||||
$shortcodes->init();
|
||||
}
|
||||
|
||||
function setupHooks() {
|
||||
$hooks = new Hooks();
|
||||
$hooks->init();
|
||||
|
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
use \MailPoet\Config\Initializer;
|
||||
use \MailPoet\Config\Migrator;
|
||||
|
||||
if (!defined('ABSPATH')) exit;
|
||||
|
||||
@ -29,4 +30,10 @@ $initializer = new Initializer(array(
|
||||
'file' => __FILE__,
|
||||
'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