diff --git a/lib/API/JSON/v1/Setup.php b/lib/API/JSON/v1/Setup.php index 5c3b62adc2..96b1eeffbc 100644 --- a/lib/API/JSON/v1/Setup.php +++ b/lib/API/JSON/v1/Setup.php @@ -7,6 +7,7 @@ use MailPoet\WP\Functions as WPFunctions; use MailPoet\Config\AccessControl; use MailPoet\Config\Activator; use MailPoet\Settings\SettingsController; +use MailPoet\Config\Populator; if (!defined('ABSPATH')) exit; @@ -22,7 +23,8 @@ class Setup extends APIEndpoint { function reset() { try { - $activator = new Activator(new SettingsController()); + $settings = new SettingsController(); + $activator = new Activator($settings, new Populator($settings, $this->wp)); $activator->deactivate(); $activator->activate(); $this->wp->doAction('mailpoet_setup_reset'); diff --git a/lib/Config/Activator.php b/lib/Config/Activator.php index 7c6dda826f..a33640a7e3 100644 --- a/lib/Config/Activator.php +++ b/lib/Config/Activator.php @@ -11,16 +11,19 @@ class Activator { /** @var SettingsController */ private $settings; - function __construct(SettingsController $settings) { + /** @var Populator */ + private $populator; + + function __construct(SettingsController $settings, Populator $populator) { $this->settings = $settings; + $this->populator = $populator; } function activate() { $migrator = new Migrator(); $migrator->up(); - $populator = new Populator(); - $populator->up(); + $this->populator->up(); $this->updateDbVersion(); $caps = new Capabilities(); diff --git a/lib/Config/Populator.php b/lib/Config/Populator.php index 6b55a49cbe..d613ffa3e3 100644 --- a/lib/Config/Populator.php +++ b/lib/Config/Populator.php @@ -41,9 +41,9 @@ class Populator { private $wp; const TEMPLATES_NAMESPACE = '\MailPoet\Config\PopulatorData\Templates\\'; - function __construct() { - $this->settings = new SettingsController(); - $this->wp = new WPFunctions(); + function __construct(SettingsController $settings, WPFunctions $wp) { + $this->settings = $settings; + $this->wp = $wp; $this->prefix = Env::$db_prefix; $this->models = [ 'newsletter_option_fields', diff --git a/lib/DI/ContainerConfigurator.php b/lib/DI/ContainerConfigurator.php index c7e4fff8e8..123a7a801b 100644 --- a/lib/DI/ContainerConfigurator.php +++ b/lib/DI/ContainerConfigurator.php @@ -57,6 +57,7 @@ class ContainerConfigurator implements IContainerConfigurator { // Config $container->autowire(\MailPoet\Config\AccessControl::class)->setPublic(true); $container->autowire(\MailPoet\Config\Activator::class)->setPublic(true); + $container->autowire(\MailPoet\Config\Populator::class)->setPublic(true); $container->autowire(\MailPoet\Config\Changelog::class)->setPublic(true); $container->autowire(\MailPoet\Config\Hooks::class)->setPublic(true); $container->autowire(\MailPoet\Config\Initializer::class)->setPublic(true); diff --git a/tests/integration/Cron/Workers/SendingQueue/SendingQueueTest.php b/tests/integration/Cron/Workers/SendingQueue/SendingQueueTest.php index b3ede6a595..53bd8f6d7a 100644 --- a/tests/integration/Cron/Workers/SendingQueue/SendingQueueTest.php +++ b/tests/integration/Cron/Workers/SendingQueue/SendingQueueTest.php @@ -46,7 +46,8 @@ class SendingQueueTest extends \MailPoetTest { parent::_before(); $wp_users = get_users(); wp_set_current_user($wp_users[0]->ID); - $populator = new Populator(); + $this->settings = new SettingsController(); + $populator = new Populator($this->settings, WPFunctions::get()); $populator->up(); $this->subscriber = Subscriber::create(); $this->subscriber->email = 'john@doe.com'; @@ -83,7 +84,6 @@ class SendingQueueTest extends \MailPoetTest { $this->newsletter_link->hash = 'abcde'; $this->newsletter_link->save(); $this->sending_error_handler = new SendingErrorHandler(); - $this->settings = new SettingsController(); $this->stats_notifications_worker = new StatsNotificationsScheduler($this->settings); $this->sending_queue_worker = new SendingQueueWorker($this->sending_error_handler, $this->stats_notifications_worker); } diff --git a/tests/integration/Cron/Workers/SendingQueue/Tasks/MailerTest.php b/tests/integration/Cron/Workers/SendingQueue/Tasks/MailerTest.php index 3afaa47ec3..f6f33959f4 100644 --- a/tests/integration/Cron/Workers/SendingQueue/Tasks/MailerTest.php +++ b/tests/integration/Cron/Workers/SendingQueue/Tasks/MailerTest.php @@ -9,6 +9,7 @@ use MailPoet\Mailer\Mailer; use MailPoet\Models\Setting; use MailPoet\Models\Subscriber; use MailPoet\Settings\SettingsController; +use MailPoet\WP\Functions as WPFunctions; if (!defined('ABSPATH')) exit; @@ -23,10 +24,10 @@ class MailerTest extends \MailPoetTest { parent::_before(); $wp_users = get_users(); wp_set_current_user($wp_users[0]->ID); - $populator = new Populator(); + $this->settings = new SettingsController(); + $populator = new Populator($this->settings, WPFunctions::get()); $populator->up(); $this->mailer_task = new MailerTask(); - $this->settings = new SettingsController(); $this->sender = $this->settings->get('sender'); } diff --git a/tests/integration/Newsletter/ShortcodesTest.php b/tests/integration/Newsletter/ShortcodesTest.php index 15296e4a6a..4fb4c354fe 100644 --- a/tests/integration/Newsletter/ShortcodesTest.php +++ b/tests/integration/Newsletter/ShortcodesTest.php @@ -11,6 +11,7 @@ use MailPoet\Newsletter\Shortcodes\Categories\Date; use MailPoet\Newsletter\Url as NewsletterUrl; use MailPoet\Settings\SettingsController; use MailPoet\Subscription\Url as SubscriptionUrl; +use MailPoet\WP\Functions as WPFunctions; require_once(ABSPATH . 'wp-admin/includes/user.php'); @@ -23,9 +24,9 @@ class ShortcodesTest extends \MailPoetTest { function _before() { parent::_before(); - $populator = new Populator(); - $populator->up(); $this->settings = new SettingsController(); + $populator = new Populator($this->settings, WPFunctions::get()); + $populator->up(); $this->WP_user = $this->_createWPUser(); $this->WP_post = $this->_createWPPost(); $this->subscriber = $this->_createSubscriber(); diff --git a/tests/integration/Subscription/UrlTest.php b/tests/integration/Subscription/UrlTest.php index 3250b0a669..635fc4d808 100644 --- a/tests/integration/Subscription/UrlTest.php +++ b/tests/integration/Subscription/UrlTest.php @@ -6,11 +6,13 @@ use MailPoet\Subscription\Url; use MailPoet\Models\Subscriber; use MailPoet\Models\Setting; use MailPoet\Config\Populator; +use MailPoet\Settings\SettingsController; +use MailPoet\WP\Functions as WPFunctions; class UrlTest extends \MailPoetTest { function _before() { parent::_before(); - $populator = new Populator(); + $populator = new Populator(new SettingsController, WPFunctions::get()); $populator->up(); }