Uses plugin's settings to store DB version
This commit is contained in:
@ -2,6 +2,8 @@
|
||||
|
||||
namespace MailPoet\Config;
|
||||
|
||||
use MailPoet\Models\Setting;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
class Activator {
|
||||
@ -11,8 +13,7 @@ class Activator {
|
||||
|
||||
$populator = new Populator();
|
||||
$populator->up();
|
||||
|
||||
update_option('mailpoet_db_version', Env::$version);
|
||||
Setting::setValue('version', Env::$version);
|
||||
}
|
||||
|
||||
function deactivate() {
|
||||
|
@ -4,6 +4,7 @@ namespace MailPoet\Config;
|
||||
|
||||
use MailPoet\API;
|
||||
use MailPoet\Cron\CronTrigger;
|
||||
use MailPoet\Models\Setting;
|
||||
use MailPoet\Router;
|
||||
use MailPoet\Util\ConflictResolver;
|
||||
use MailPoet\Util\Helpers;
|
||||
@ -122,7 +123,11 @@ class Initializer {
|
||||
}
|
||||
|
||||
function maybeDbUpdate() {
|
||||
$current_db_version = get_option('mailpoet_db_version', false);
|
||||
try {
|
||||
$current_db_version = Setting::getValue('version');
|
||||
} catch(\Exception $e) {
|
||||
$current_db_version = null;
|
||||
}
|
||||
|
||||
// if current db version and plugin version differ
|
||||
if(version_compare($current_db_version, Env::$version) !== 0) {
|
||||
|
@ -337,7 +337,7 @@ class Populator {
|
||||
function convertExistingDataToUTF8() {
|
||||
global $wpdb;
|
||||
|
||||
if(!version_compare(get_option('mailpoet_db_version', '3.0.0-beta.33'), '3.0.0-beta.32', '<=')) {
|
||||
if(!version_compare(Setting::getValue('version', '3.0.0-beta.33'), '3.0.0-beta.32', '<=')) {
|
||||
// Data conversion should only be performed only once, when migrating from
|
||||
// older version
|
||||
return false;
|
||||
@ -402,7 +402,7 @@ class Populator {
|
||||
global $wpdb;
|
||||
|
||||
// perform once for versions below 3.0.0-beta.36.2.1
|
||||
if(version_compare(get_option('mailpoet_db_version', '3.0.0-beta.36.2.3'), '3.0.0-beta.36.2.1', '>=')) {
|
||||
if(version_compare(Setting::getValue('version', '3.0.0-beta.36.2.3'), '3.0.0-beta.36.2.1', '>=')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -455,7 +455,7 @@ class Populator {
|
||||
global $wpdb;
|
||||
|
||||
// perform once for versions below 3.0.0-beta.36.2.1
|
||||
if(version_compare(get_option('mailpoet_db_version', '3.0.0-beta.36.2.3'), '3.0.0-beta.36.2.1', '>=')) {
|
||||
if(version_compare(Setting::getValue('version', '3.0.0-beta.36.2.3'), '3.0.0-beta.36.2.1', '>=')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -5,13 +5,14 @@ use MailPoet\Config\Env;
|
||||
use MailPoet\Config\Populator;
|
||||
use MailPoet\Models\Newsletter;
|
||||
use MailPoet\Models\SendingQueue;
|
||||
use MailPoet\Models\Setting;
|
||||
|
||||
class PopulatorTest extends \MailPoetTest {
|
||||
function testItPopulatesNewslettersTableSentAtColumn() {
|
||||
// TODO: remove in final release
|
||||
|
||||
// run for versions <= 3.0.0-beta.36.2.0
|
||||
update_option('mailpoet_db_version', '3.0.0-beta.36.2.0');
|
||||
Setting::setValue('version', '3.0.0-beta.36.2.0');
|
||||
$newsletters = array();
|
||||
for($i = 1; $i <= 3; $i++) {
|
||||
$newsletters[$i] = Newsletter::create();
|
||||
@ -31,7 +32,7 @@ class PopulatorTest extends \MailPoetTest {
|
||||
expect(Newsletter::whereNotNull('sent_at')->findMany())->count(1);
|
||||
|
||||
// do not run for versions >= 3.0.0-beta.36.2.1
|
||||
update_option('mailpoet_db_version', '3.0.0-beta.36.2.1');
|
||||
Setting::setValue('version', '3.0.0-beta.36.2.1');
|
||||
$populator = new Populator();
|
||||
expect($populator->populateNewsletterSentAtField())->false();
|
||||
}
|
||||
@ -39,6 +40,6 @@ class PopulatorTest extends \MailPoetTest {
|
||||
function _after() {
|
||||
\ORM::raw_execute('TRUNCATE ' . Newsletter::$_table);
|
||||
\ORM::raw_execute('TRUNCATE ' . SendingQueue::$_table);
|
||||
update_option('mailpoet_db_version', MAILPOET_VERSION);
|
||||
Setting::setValue('version', MAILPOET_VERSION);
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace MailPoet\Test\Cron;
|
||||
|
||||
use MailPoet\Cron\CronHelper;
|
||||
@ -6,6 +7,10 @@ use MailPoet\Cron\Daemon;
|
||||
use MailPoet\Models\Setting;
|
||||
|
||||
class CronHelperTest extends \MailPoetTest {
|
||||
function _before() {
|
||||
Setting::setValue('version', MAILPOET_VERSION);
|
||||
}
|
||||
|
||||
function testItDefinesConstants() {
|
||||
expect(CronHelper::DAEMON_EXECUTION_LIMIT)->equals(20);
|
||||
expect(CronHelper::DAEMON_EXECUTION_TIMEOUT)->equals(35);
|
||||
|
Reference in New Issue
Block a user