Eliminate SettingsController creation in Helpscout Beacon
[MAILPOET-2436]
This commit is contained in:
committed by
Jack Kitterhing
parent
486e39af7c
commit
c91cd1255a
@@ -21,14 +21,18 @@ class Help {
|
||||
/** @var CronHelper */
|
||||
private $cron_helper;
|
||||
|
||||
function __construct(PageRenderer $page_renderer, State $tasks_state, CronHelper $cron_helper) {
|
||||
/** @var Beacon */
|
||||
private $helpscout_beacon;
|
||||
|
||||
function __construct(PageRenderer $page_renderer, State $tasks_state, CronHelper $cron_helper, Beacon $helpscout_beacon) {
|
||||
$this->page_renderer = $page_renderer;
|
||||
$this->tasks_state = $tasks_state;
|
||||
$this->cron_helper = $cron_helper;
|
||||
$this->helpscout_beacon = $helpscout_beacon;
|
||||
}
|
||||
|
||||
function render() {
|
||||
$system_info_data = Beacon::getData();
|
||||
$system_info_data = $this->helpscout_beacon->getData();
|
||||
$cron_ping_response = $this->cron_helper->pingDaemon();
|
||||
$system_status_data = [
|
||||
'cron' => [
|
||||
|
@@ -145,6 +145,8 @@ class ContainerConfigurator implements IContainerConfigurator {
|
||||
// Form
|
||||
$container->autowire(\MailPoet\Form\Util\FieldNameObfuscator::class)->setPublic(true);
|
||||
$container->autowire(\MailPoet\Form\AssetsController::class);
|
||||
// Helpscout
|
||||
$container->autowire(\MailPoet\Helpscout\Beacon::class);
|
||||
// Listing
|
||||
$container->autowire(\MailPoet\Listing\BulkActionController::class)->setPublic(true);
|
||||
$container->autowire(\MailPoet\Listing\BulkActionFactory::class)->setPublic(true);
|
||||
|
@@ -11,15 +11,25 @@ use MailPoet\Settings\SettingsController;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
class Beacon {
|
||||
static function getData() {
|
||||
/** @var SettingsController */
|
||||
private $settings;
|
||||
|
||||
/** @var WPFunctions */
|
||||
private $wp;
|
||||
|
||||
function __construct(SettingsController $settings, WPFunctions $wp) {
|
||||
$this->settings = $settings;
|
||||
$this->wp = $wp;
|
||||
}
|
||||
|
||||
function getData() {
|
||||
global $wpdb;
|
||||
$settings = new SettingsController();
|
||||
$db_version = $wpdb->get_var('SELECT @@VERSION');
|
||||
$mta = $settings->get('mta');
|
||||
$mta = $this->settings->get('mta');
|
||||
$current_theme = WPFunctions::get()->wpGetTheme();
|
||||
$current_user = WPFunctions::get()->wpGetCurrentUser();
|
||||
$sender = $settings->get('sender');
|
||||
$premium_key = $settings->get(Bridge::PREMIUM_KEY_SETTING_NAME) ?: $settings->get(Bridge::API_KEY_SETTING_NAME);
|
||||
$sender = $this->settings->get('sender');
|
||||
$premium_key = $this->settings->get(Bridge::PREMIUM_KEY_SETTING_NAME) ?: $this->settings->get(Bridge::API_KEY_SETTING_NAME);
|
||||
$cron_helper = ContainerWrapper::getInstance()->get(CronHelper::class);
|
||||
$cron_ping_url = $cron_helper->getCronUrl(
|
||||
CronDaemon::ACTION_PING
|
||||
@@ -31,7 +41,7 @@ class Beacon {
|
||||
'MailPoet Free version' => MAILPOET_VERSION,
|
||||
'MailPoet Premium version' => (defined('MAILPOET_PREMIUM_VERSION')) ? MAILPOET_PREMIUM_VERSION : 'N/A',
|
||||
'MailPoet Premium/MSS key' => $premium_key,
|
||||
'WordPress version' => WPFunctions::get()->getBloginfo('version'),
|
||||
'WordPress version' => $this->wp->getBloginfo('version'),
|
||||
'Database version' => $db_version,
|
||||
'Web server' => (!empty($_SERVER["SERVER_SOFTWARE"])) ? $_SERVER["SERVER_SOFTWARE"] : 'N/A',
|
||||
'Server OS' => (function_exists('php_uname')) ? utf8_encode(php_uname()) : 'N/A',
|
||||
@@ -42,23 +52,23 @@ class Beacon {
|
||||
'PHP memory_limit' => ini_get('memory_limit'),
|
||||
'PHP upload_max_filesize' => ini_get('upload_max_filesize'),
|
||||
'PHP post_max_size' => ini_get('post_max_size'),
|
||||
'WordPress language' => WPFunctions::get()->getLocale(),
|
||||
'WordPress language' => $this->wp->getLocale(),
|
||||
'Multisite environment?' => (is_multisite() ? 'Yes' : 'No'),
|
||||
'Current Theme' => $current_theme->get('Name') .
|
||||
' (version ' . $current_theme->get('Version') . ')',
|
||||
'Active Plugin names' => join(", ", WPFunctions::get()->getOption('active_plugins')),
|
||||
'Active Plugin names' => join(", ", $this->wp->getOption('active_plugins')),
|
||||
'Sending Method' => $mta['method'],
|
||||
'Sending Frequency' => sprintf('%d emails every %d minutes',
|
||||
$mta['frequency']['emails'],
|
||||
$mta['frequency']['interval']
|
||||
),
|
||||
'Task Scheduler method' => $settings->get('cron_trigger.method'),
|
||||
'Task Scheduler method' => $this->settings->get('cron_trigger.method'),
|
||||
'Cron ping URL' => $cron_ping_url,
|
||||
'Default FROM address' => $settings->get('sender.address'),
|
||||
'Default Reply-To address' => $settings->get('reply_to.address'),
|
||||
'Bounce Email Address' => $settings->get('bounce.address'),
|
||||
'Default FROM address' => $this->settings->get('sender.address'),
|
||||
'Default Reply-To address' => $this->settings->get('reply_to.address'),
|
||||
'Bounce Email Address' => $this->settings->get('bounce.address'),
|
||||
'Total number of subscribers' => Subscriber::getTotalSubscribers(),
|
||||
'Plugin installed at' => $settings->get('installed_at'),
|
||||
'Plugin installed at' => $this->settings->get('installed_at'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace MailPoet\Twig;
|
||||
|
||||
use MailPoet\DI\ContainerWrapper;
|
||||
use MailPoet\Helpscout\Beacon;
|
||||
use MailPoetVendor\Twig\TwigFunction;
|
||||
|
||||
class Helpscout extends \MailPoetVendor\Twig\Extension\AbstractExtension {
|
||||
@@ -9,9 +11,13 @@ class Helpscout extends \MailPoetVendor\Twig\Extension\AbstractExtension {
|
||||
return [
|
||||
new TwigFunction(
|
||||
'get_helpscout_data',
|
||||
'\MailPoet\Helpscout\Beacon::getData',
|
||||
[$this, 'getHelpscoutData'],
|
||||
['is_safe' => ['all']]
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
public function getHelpscoutData() {
|
||||
return ContainerWrapper::getInstance()->get(Beacon::class)->getData();
|
||||
}
|
||||
}
|
||||
|
@@ -29,7 +29,7 @@ class BeaconTest extends \MailPoetTest {
|
||||
'status' => Subscriber::STATUS_BOUNCED,
|
||||
]);
|
||||
|
||||
$this->beacon_data = Beacon::getData();
|
||||
$this->beacon_data = $this->di_container->get(Beacon::class)->getData();
|
||||
$this->settings = new SettingsController();
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ class BeaconTest extends \MailPoetTest {
|
||||
};
|
||||
$wp = new WPFunctions;
|
||||
$wp->addFilter('mailpoet_cron_request_url', $filter);
|
||||
$beacon_data = Beacon::getData();
|
||||
$beacon_data = $this->beacon_data = $this->di_container->get(Beacon::class)->getData();
|
||||
expect($beacon_data['Cron ping URL'])->regExp('!^http:\/\/custom_url\/!');
|
||||
$wp->removeFilter('mailpoet_cron_request_url', $filter);
|
||||
}
|
||||
|
Reference in New Issue
Block a user