handle db update
This commit is contained in:
@ -1,23 +1,20 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace MailPoet\Config;
|
namespace MailPoet\Config;
|
||||||
use \MailPoet\Config\Migrator;
|
|
||||||
use \MailPoet\Config\Populator;
|
|
||||||
|
|
||||||
if(!defined('ABSPATH')) exit;
|
if(!defined('ABSPATH')) exit;
|
||||||
|
|
||||||
class Activator {
|
class Activator {
|
||||||
function __construct() {
|
static function activate() {
|
||||||
}
|
|
||||||
|
|
||||||
function activate() {
|
|
||||||
$migrator = new Migrator();
|
$migrator = new Migrator();
|
||||||
$migrator->up();
|
$migrator->up();
|
||||||
|
|
||||||
$populator = new Populator();
|
$populator = new Populator();
|
||||||
$populator->up();
|
$populator->up();
|
||||||
|
|
||||||
|
update_option('mailpoet_db_version', Env::$version);
|
||||||
}
|
}
|
||||||
|
|
||||||
function deactivate() {
|
static function deactivate() {
|
||||||
$migrator = new Migrator();
|
$migrator = new Migrator();
|
||||||
$migrator->down();
|
$migrator->down();
|
||||||
}
|
}
|
||||||
|
@ -29,8 +29,11 @@ class Initializer {
|
|||||||
|
|
||||||
$this->setupDB();
|
$this->setupDB();
|
||||||
|
|
||||||
register_activation_hook(Env::$file, array($this, 'runMigrator'));
|
// activation function
|
||||||
register_activation_hook(Env::$file, array($this, 'runPopulator'));
|
register_activation_hook(
|
||||||
|
Env::$file,
|
||||||
|
array('MailPoet\Config\Activator', 'activate')
|
||||||
|
);
|
||||||
|
|
||||||
add_action('plugins_loaded', array($this, 'setup'));
|
add_action('plugins_loaded', array($this, 'setup'));
|
||||||
add_action('init', array($this, 'onInit'));
|
add_action('init', array($this, 'onInit'));
|
||||||
@ -96,18 +99,9 @@ class Initializer {
|
|||||||
define('MP_STATISTICS_FORMS_TABLE', $statistics_forms);
|
define('MP_STATISTICS_FORMS_TABLE', $statistics_forms);
|
||||||
}
|
}
|
||||||
|
|
||||||
function runMigrator() {
|
|
||||||
$migrator = new Migrator();
|
|
||||||
$migrator->up();
|
|
||||||
}
|
|
||||||
|
|
||||||
function runPopulator() {
|
|
||||||
$populator = new Populator();
|
|
||||||
$populator->up();
|
|
||||||
}
|
|
||||||
|
|
||||||
function setup() {
|
function setup() {
|
||||||
try {
|
try {
|
||||||
|
$this->maybeDbUpdate();
|
||||||
$this->setupRenderer();
|
$this->setupRenderer();
|
||||||
$this->setupLocalizer();
|
$this->setupLocalizer();
|
||||||
$this->setupMenu();
|
$this->setupMenu();
|
||||||
@ -141,6 +135,15 @@ class Initializer {
|
|||||||
define('MAILPOET_INITIALIZED', true);
|
define('MAILPOET_INITIALIZED', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function maybeDbUpdate() {
|
||||||
|
$current_db_version = get_option('mailpoet_db_version', false);
|
||||||
|
|
||||||
|
// if current db version and plugin version differ
|
||||||
|
if(version_compare($current_db_version, Env::$version) !== 0) {
|
||||||
|
Activator::activate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function setupWidget() {
|
function setupWidget() {
|
||||||
if(!$this->plugin_initialized) {
|
if(!$this->plugin_initialized) {
|
||||||
return;
|
return;
|
||||||
|
Reference in New Issue
Block a user