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 */
|
/** @var CronHelper */
|
||||||
private $cron_helper;
|
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->page_renderer = $page_renderer;
|
||||||
$this->tasks_state = $tasks_state;
|
$this->tasks_state = $tasks_state;
|
||||||
$this->cron_helper = $cron_helper;
|
$this->cron_helper = $cron_helper;
|
||||||
|
$this->helpscout_beacon = $helpscout_beacon;
|
||||||
}
|
}
|
||||||
|
|
||||||
function render() {
|
function render() {
|
||||||
$system_info_data = Beacon::getData();
|
$system_info_data = $this->helpscout_beacon->getData();
|
||||||
$cron_ping_response = $this->cron_helper->pingDaemon();
|
$cron_ping_response = $this->cron_helper->pingDaemon();
|
||||||
$system_status_data = [
|
$system_status_data = [
|
||||||
'cron' => [
|
'cron' => [
|
||||||
|
@@ -145,6 +145,8 @@ class ContainerConfigurator implements IContainerConfigurator {
|
|||||||
// Form
|
// Form
|
||||||
$container->autowire(\MailPoet\Form\Util\FieldNameObfuscator::class)->setPublic(true);
|
$container->autowire(\MailPoet\Form\Util\FieldNameObfuscator::class)->setPublic(true);
|
||||||
$container->autowire(\MailPoet\Form\AssetsController::class);
|
$container->autowire(\MailPoet\Form\AssetsController::class);
|
||||||
|
// Helpscout
|
||||||
|
$container->autowire(\MailPoet\Helpscout\Beacon::class);
|
||||||
// Listing
|
// Listing
|
||||||
$container->autowire(\MailPoet\Listing\BulkActionController::class)->setPublic(true);
|
$container->autowire(\MailPoet\Listing\BulkActionController::class)->setPublic(true);
|
||||||
$container->autowire(\MailPoet\Listing\BulkActionFactory::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;
|
use MailPoet\WP\Functions as WPFunctions;
|
||||||
|
|
||||||
class Beacon {
|
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;
|
global $wpdb;
|
||||||
$settings = new SettingsController();
|
|
||||||
$db_version = $wpdb->get_var('SELECT @@VERSION');
|
$db_version = $wpdb->get_var('SELECT @@VERSION');
|
||||||
$mta = $settings->get('mta');
|
$mta = $this->settings->get('mta');
|
||||||
$current_theme = WPFunctions::get()->wpGetTheme();
|
$current_theme = WPFunctions::get()->wpGetTheme();
|
||||||
$current_user = WPFunctions::get()->wpGetCurrentUser();
|
$current_user = WPFunctions::get()->wpGetCurrentUser();
|
||||||
$sender = $settings->get('sender');
|
$sender = $this->settings->get('sender');
|
||||||
$premium_key = $settings->get(Bridge::PREMIUM_KEY_SETTING_NAME) ?: $settings->get(Bridge::API_KEY_SETTING_NAME);
|
$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_helper = ContainerWrapper::getInstance()->get(CronHelper::class);
|
||||||
$cron_ping_url = $cron_helper->getCronUrl(
|
$cron_ping_url = $cron_helper->getCronUrl(
|
||||||
CronDaemon::ACTION_PING
|
CronDaemon::ACTION_PING
|
||||||
@@ -31,7 +41,7 @@ class Beacon {
|
|||||||
'MailPoet Free version' => MAILPOET_VERSION,
|
'MailPoet Free version' => MAILPOET_VERSION,
|
||||||
'MailPoet Premium version' => (defined('MAILPOET_PREMIUM_VERSION')) ? MAILPOET_PREMIUM_VERSION : 'N/A',
|
'MailPoet Premium version' => (defined('MAILPOET_PREMIUM_VERSION')) ? MAILPOET_PREMIUM_VERSION : 'N/A',
|
||||||
'MailPoet Premium/MSS key' => $premium_key,
|
'MailPoet Premium/MSS key' => $premium_key,
|
||||||
'WordPress version' => WPFunctions::get()->getBloginfo('version'),
|
'WordPress version' => $this->wp->getBloginfo('version'),
|
||||||
'Database version' => $db_version,
|
'Database version' => $db_version,
|
||||||
'Web server' => (!empty($_SERVER["SERVER_SOFTWARE"])) ? $_SERVER["SERVER_SOFTWARE"] : 'N/A',
|
'Web server' => (!empty($_SERVER["SERVER_SOFTWARE"])) ? $_SERVER["SERVER_SOFTWARE"] : 'N/A',
|
||||||
'Server OS' => (function_exists('php_uname')) ? utf8_encode(php_uname()) : '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 memory_limit' => ini_get('memory_limit'),
|
||||||
'PHP upload_max_filesize' => ini_get('upload_max_filesize'),
|
'PHP upload_max_filesize' => ini_get('upload_max_filesize'),
|
||||||
'PHP post_max_size' => ini_get('post_max_size'),
|
'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'),
|
'Multisite environment?' => (is_multisite() ? 'Yes' : 'No'),
|
||||||
'Current Theme' => $current_theme->get('Name') .
|
'Current Theme' => $current_theme->get('Name') .
|
||||||
' (version ' . $current_theme->get('Version') . ')',
|
' (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 Method' => $mta['method'],
|
||||||
'Sending Frequency' => sprintf('%d emails every %d minutes',
|
'Sending Frequency' => sprintf('%d emails every %d minutes',
|
||||||
$mta['frequency']['emails'],
|
$mta['frequency']['emails'],
|
||||||
$mta['frequency']['interval']
|
$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,
|
'Cron ping URL' => $cron_ping_url,
|
||||||
'Default FROM address' => $settings->get('sender.address'),
|
'Default FROM address' => $this->settings->get('sender.address'),
|
||||||
'Default Reply-To address' => $settings->get('reply_to.address'),
|
'Default Reply-To address' => $this->settings->get('reply_to.address'),
|
||||||
'Bounce Email Address' => $settings->get('bounce.address'),
|
'Bounce Email Address' => $this->settings->get('bounce.address'),
|
||||||
'Total number of subscribers' => Subscriber::getTotalSubscribers(),
|
'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;
|
namespace MailPoet\Twig;
|
||||||
|
|
||||||
|
use MailPoet\DI\ContainerWrapper;
|
||||||
|
use MailPoet\Helpscout\Beacon;
|
||||||
use MailPoetVendor\Twig\TwigFunction;
|
use MailPoetVendor\Twig\TwigFunction;
|
||||||
|
|
||||||
class Helpscout extends \MailPoetVendor\Twig\Extension\AbstractExtension {
|
class Helpscout extends \MailPoetVendor\Twig\Extension\AbstractExtension {
|
||||||
@@ -9,9 +11,13 @@ class Helpscout extends \MailPoetVendor\Twig\Extension\AbstractExtension {
|
|||||||
return [
|
return [
|
||||||
new TwigFunction(
|
new TwigFunction(
|
||||||
'get_helpscout_data',
|
'get_helpscout_data',
|
||||||
'\MailPoet\Helpscout\Beacon::getData',
|
[$this, 'getHelpscoutData'],
|
||||||
['is_safe' => ['all']]
|
['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,
|
'status' => Subscriber::STATUS_BOUNCED,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->beacon_data = Beacon::getData();
|
$this->beacon_data = $this->di_container->get(Beacon::class)->getData();
|
||||||
$this->settings = new SettingsController();
|
$this->settings = new SettingsController();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,7 +135,7 @@ class BeaconTest extends \MailPoetTest {
|
|||||||
};
|
};
|
||||||
$wp = new WPFunctions;
|
$wp = new WPFunctions;
|
||||||
$wp->addFilter('mailpoet_cron_request_url', $filter);
|
$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\/!');
|
expect($beacon_data['Cron ping URL'])->regExp('!^http:\/\/custom_url\/!');
|
||||||
$wp->removeFilter('mailpoet_cron_request_url', $filter);
|
$wp->removeFilter('mailpoet_cron_request_url', $filter);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user