diff --git a/lib/Config/Menu.php b/lib/Config/Menu.php index 5009bd7983..2d1bf20276 100644 --- a/lib/Config/Menu.php +++ b/lib/Config/Menu.php @@ -38,7 +38,6 @@ if (!defined('ABSPATH')) exit; class Menu { const MAIN_PAGE_SLUG = 'mailpoet-newsletters'; - const LAST_ANNOUNCEMENT_DATE = '2019-06-10 10:00:00'; /** @var WooCommerceHelper */ private $woocommerce_helper; diff --git a/lib/Config/Populator.php b/lib/Config/Populator.php index 8e0dd2e577..6b55a49cbe 100644 --- a/lib/Config/Populator.php +++ b/lib/Config/Populator.php @@ -37,10 +37,13 @@ class Populator { private $default_segment; /** @var SettingsController */ private $settings; + /** @var WPFunctions */ + private $wp; const TEMPLATES_NAMESPACE = '\MailPoet\Config\PopulatorData\Templates\\'; function __construct() { $this->settings = new SettingsController(); + $this->wp = new WPFunctions(); $this->prefix = Env::$db_prefix; $this->models = [ 'newsletter_option_fields', @@ -146,7 +149,7 @@ class Populator { } private function createMailPoetPage() { - $pages = WPFunctions::get()->getPosts([ + $pages = $this->wp->getPosts([ 'posts_per_page' => 1, 'orderby' => 'date', 'order' => 'DESC', @@ -178,7 +181,7 @@ class Populator { } private function createDefaultSettings() { - $current_user = WPFunctions::get()->wpGetCurrentUser(); + $current_user = $this->wp->wpGetCurrentUser(); $settings_db_version = $this->settings->fetch('db_version'); // set cron trigger option to default method @@ -204,8 +207,8 @@ class Populator { $this->settings->set('signup_confirmation', [ 'enabled' => true, 'from' => [ - 'name' => WPFunctions::get()->getOption('blogname'), - 'address' => WPFunctions::get()->getOption('admin_email'), + 'name' => $this->wp->getOption('blogname'), + 'address' => $this->wp->getOption('admin_email'), ], 'reply_to' => $sender, ]); @@ -248,7 +251,7 @@ class Populator { if (empty($woocommerce_optin_on_checkout)) { $this->settings->set('woocommerce.optin_on_checkout', [ '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) { $this->default_segment = Segment::create(); $this->default_segment->hydrate([ - 'name' => WPFunctions::get()->__('My First List', 'mailpoet'), + 'name' => $this->wp->__('My First List', 'mailpoet'), '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(); } @@ -537,7 +540,7 @@ class Populator { private function scheduleInitialInactiveSubscribersCheck() { $this->scheduleTask( 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( 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')) { $this->scheduleTask( Beamer::TASK_TYPE, - Carbon::createFromTimestamp(WPFunctions::get()->currentTime('timestamp')) + Carbon::createFromTimestamp($this->wp->currentTime('timestamp')) ); } } diff --git a/lib/Cron/Workers/Beamer.php b/lib/Cron/Workers/Beamer.php index 0ac894f6d9..9a6166c0dd 100644 --- a/lib/Cron/Workers/Beamer.php +++ b/lib/Cron/Workers/Beamer.php @@ -39,6 +39,7 @@ class Beamer extends SimpleWorker { $posts = $this->wp->wpRemoteRetrieveBody($response); if (empty($posts)) return false; $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()); return true; } diff --git a/tests/integration/Cron/Workers/BeamerTest.php b/tests/integration/Cron/Workers/BeamerTest.php index 9f7052bec4..4883491627 100644 --- a/tests/integration/Cron/Workers/BeamerTest.php +++ b/tests/integration/Cron/Workers/BeamerTest.php @@ -8,6 +8,7 @@ use MailPoet\Settings\SettingsController; use MailPoet\WP\Functions as WPFunctions; class BeamerTest extends \MailPoetTest { + function testItSetsLastAnnouncementDate() { $oldDate = '2019-05-18T10:25:00.000Z'; $newDate = '2019-05-22T10:25:00.000Z'; @@ -21,6 +22,7 @@ class BeamerTest extends \MailPoetTest { ]); $beamer = new Beamer($settings, $wp); $beamer->setLastAnnouncementDate(); - expect($settings->get('last_announcement_date'))->equals( Carbon::createFromTimeString($newDate)->getTimestamp()); + expect($settings->get('last_announcement_date'))->equals(Carbon::createFromTimeString($newDate)->getTimestamp()); } + }