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,22 +18,27 @@ class Initializer {
|
||||
}
|
||||
|
||||
function init() {
|
||||
$this->setupDB();
|
||||
$this->setupActivator();
|
||||
$this->setupRenderer();
|
||||
$this->setupLocalizer();
|
||||
$this->setupMenu();
|
||||
$this->setupRouter();
|
||||
$this->setupWidget();
|
||||
$this->setupAnalytics();
|
||||
$this->setupPermissions();
|
||||
$this->setupChangelog();
|
||||
$this->setupPublicAPI();
|
||||
$this->runQueueSupervisor();
|
||||
$this->setupShortcodes();
|
||||
$this->setupHooks();
|
||||
$this->setupPages();
|
||||
$this->setupImages();
|
||||
try {
|
||||
$this->setupDB();
|
||||
$this->setupRenderer();
|
||||
$this->setupLocalizer();
|
||||
$this->setupMenu();
|
||||
$this->setupRouter();
|
||||
$this->setupWidget();
|
||||
$this->setupAnalytics();
|
||||
$this->setupPermissions();
|
||||
$this->setupChangelog();
|
||||
$this->setupPublicAPI();
|
||||
$this->runQueueSupervisor();
|
||||
$this->setupShortcodes();
|
||||
$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();
|
||||
@ -153,7 +160,7 @@ class Initializer {
|
||||
try {
|
||||
$supervisor = new Supervisor();
|
||||
$supervisor->checkDaemon();
|
||||
} catch (\Exception $e) {
|
||||
} catch(\Exception $e) {
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
namespace MailPoet\Config;
|
||||
|
||||
if (!defined('ABSPATH')) exit;
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
|
||||
|
||||
|
15
mailpoet.php
15
mailpoet.php
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
use \MailPoet\Config\Initializer;
|
||||
use \MailPoet\Config\Migrator;
|
||||
|
||||
if (!defined('ABSPATH')) exit;
|
||||
|
||||
@ -26,7 +27,13 @@ require 'vendor/autoload.php';
|
||||
define('MAILPOET_VERSION', '0.0.12');
|
||||
|
||||
$initializer = new Initializer(array(
|
||||
'file' => __FILE__,
|
||||
'version' => MAILPOET_VERSION
|
||||
));
|
||||
$initializer->init();
|
||||
'file' => __FILE__,
|
||||
'version' => MAILPOET_VERSION
|
||||
));
|
||||
|
||||
$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