Fix code style and add checks

This commit is contained in:
Amine Ben hammou
2019-06-25 11:36:01 +01:00
committed by M. Shull
parent 232ef05e81
commit 7fba1be402
4 changed files with 17 additions and 12 deletions

View File

@ -38,7 +38,6 @@ if (!defined('ABSPATH')) exit;
class Menu { class Menu {
const MAIN_PAGE_SLUG = 'mailpoet-newsletters'; const MAIN_PAGE_SLUG = 'mailpoet-newsletters';
const LAST_ANNOUNCEMENT_DATE = '2019-06-10 10:00:00';
/** @var WooCommerceHelper */ /** @var WooCommerceHelper */
private $woocommerce_helper; private $woocommerce_helper;

View File

@ -37,10 +37,13 @@ class Populator {
private $default_segment; private $default_segment;
/** @var SettingsController */ /** @var SettingsController */
private $settings; private $settings;
/** @var WPFunctions */
private $wp;
const TEMPLATES_NAMESPACE = '\MailPoet\Config\PopulatorData\Templates\\'; const TEMPLATES_NAMESPACE = '\MailPoet\Config\PopulatorData\Templates\\';
function __construct() { function __construct() {
$this->settings = new SettingsController(); $this->settings = new SettingsController();
$this->wp = new WPFunctions();
$this->prefix = Env::$db_prefix; $this->prefix = Env::$db_prefix;
$this->models = [ $this->models = [
'newsletter_option_fields', 'newsletter_option_fields',
@ -146,7 +149,7 @@ class Populator {
} }
private function createMailPoetPage() { private function createMailPoetPage() {
$pages = WPFunctions::get()->getPosts([ $pages = $this->wp->getPosts([
'posts_per_page' => 1, 'posts_per_page' => 1,
'orderby' => 'date', 'orderby' => 'date',
'order' => 'DESC', 'order' => 'DESC',
@ -178,7 +181,7 @@ class Populator {
} }
private function createDefaultSettings() { private function createDefaultSettings() {
$current_user = WPFunctions::get()->wpGetCurrentUser(); $current_user = $this->wp->wpGetCurrentUser();
$settings_db_version = $this->settings->fetch('db_version'); $settings_db_version = $this->settings->fetch('db_version');
// set cron trigger option to default method // set cron trigger option to default method
@ -204,8 +207,8 @@ class Populator {
$this->settings->set('signup_confirmation', [ $this->settings->set('signup_confirmation', [
'enabled' => true, 'enabled' => true,
'from' => [ 'from' => [
'name' => WPFunctions::get()->getOption('blogname'), 'name' => $this->wp->getOption('blogname'),
'address' => WPFunctions::get()->getOption('admin_email'), 'address' => $this->wp->getOption('admin_email'),
], ],
'reply_to' => $sender, 'reply_to' => $sender,
]); ]);
@ -248,7 +251,7 @@ class Populator {
if (empty($woocommerce_optin_on_checkout)) { if (empty($woocommerce_optin_on_checkout)) {
$this->settings->set('woocommerce.optin_on_checkout', [ $this->settings->set('woocommerce.optin_on_checkout', [
'enabled' => empty($settings_db_version), // enable on new installs only 'enabled' => empty($settings_db_version), // enable on new installs only
'message' => WPFunctions::get()->_x('Yes, I would like to be added to your mailing list', "default email opt-in message displayed on checkout page for ecommerce websites"), 'message' => $this->wp->_x('Yes, I would like to be added to your mailing list', "default email opt-in message displayed on checkout page for ecommerce websites"),
]); ]);
} }
@ -298,9 +301,9 @@ class Populator {
if (Segment::where('type', 'default')->count() === 0) { if (Segment::where('type', 'default')->count() === 0) {
$this->default_segment = Segment::create(); $this->default_segment = Segment::create();
$this->default_segment->hydrate([ $this->default_segment->hydrate([
'name' => WPFunctions::get()->__('My First List', 'mailpoet'), 'name' => $this->wp->__('My First List', 'mailpoet'),
'description' => 'description' =>
WPFunctions::get()->__('This list is automatically created when you install MailPoet.', 'mailpoet'), $this->wp->__('This list is automatically created when you install MailPoet.', 'mailpoet'),
]); ]);
$this->default_segment->save(); $this->default_segment->save();
} }
@ -537,7 +540,7 @@ class Populator {
private function scheduleInitialInactiveSubscribersCheck() { private function scheduleInitialInactiveSubscribersCheck() {
$this->scheduleTask( $this->scheduleTask(
InactiveSubscribers::TASK_TYPE, InactiveSubscribers::TASK_TYPE,
Carbon::createFromTimestamp(WPFunctions::get()->currentTime('timestamp'))->addHour() Carbon::createFromTimestamp($this->wp->currentTime('timestamp'))->addHour()
); );
} }
@ -547,7 +550,7 @@ class Populator {
} }
$this->scheduleTask( $this->scheduleTask(
AuthorizedSendingEmailsCheck::TASK_TYPE, AuthorizedSendingEmailsCheck::TASK_TYPE,
Carbon::createFromTimestamp(WPFunctions::get()->currentTime('timestamp')) Carbon::createFromTimestamp($this->wp->currentTime('timestamp'))
); );
} }
@ -555,7 +558,7 @@ class Populator {
if (!$this->settings->get('last_announcement_date')) { if (!$this->settings->get('last_announcement_date')) {
$this->scheduleTask( $this->scheduleTask(
Beamer::TASK_TYPE, Beamer::TASK_TYPE,
Carbon::createFromTimestamp(WPFunctions::get()->currentTime('timestamp')) Carbon::createFromTimestamp($this->wp->currentTime('timestamp'))
); );
} }
} }

View File

@ -39,6 +39,7 @@ class Beamer extends SimpleWorker {
$posts = $this->wp->wpRemoteRetrieveBody($response); $posts = $this->wp->wpRemoteRetrieveBody($response);
if (empty($posts)) return false; if (empty($posts)) return false;
$posts = json_decode($posts); $posts = json_decode($posts);
if (empty($posts) || empty($posts[0]->date)) return false;
$this->settings->set('last_announcement_date', Carbon::createFromTimeString($posts[0]->date)->getTimestamp()); $this->settings->set('last_announcement_date', Carbon::createFromTimeString($posts[0]->date)->getTimestamp());
return true; return true;
} }

View File

@ -8,6 +8,7 @@ use MailPoet\Settings\SettingsController;
use MailPoet\WP\Functions as WPFunctions; use MailPoet\WP\Functions as WPFunctions;
class BeamerTest extends \MailPoetTest { class BeamerTest extends \MailPoetTest {
function testItSetsLastAnnouncementDate() { function testItSetsLastAnnouncementDate() {
$oldDate = '2019-05-18T10:25:00.000Z'; $oldDate = '2019-05-18T10:25:00.000Z';
$newDate = '2019-05-22T10:25:00.000Z'; $newDate = '2019-05-22T10:25:00.000Z';
@ -21,6 +22,7 @@ class BeamerTest extends \MailPoetTest {
]); ]);
$beamer = new Beamer($settings, $wp); $beamer = new Beamer($settings, $wp);
$beamer->setLastAnnouncementDate(); $beamer->setLastAnnouncementDate();
expect($settings->get('last_announcement_date'))->equals( Carbon::createFromTimeString($newDate)->getTimestamp()); expect($settings->get('last_announcement_date'))->equals(Carbon::createFromTimeString($newDate)->getTimestamp());
} }
} }