Add task scheduler field

[MAILPOET-2680]
This commit is contained in:
Amine Ben hammou
2020-03-19 20:24:16 +01:00
committed by Veljko V
parent 103a2e7423
commit 903314669a
7 changed files with 119 additions and 4 deletions

View File

@@ -1,10 +1,12 @@
import React from 'react';
import BounceAddress from './bounce_address';
import TaskScheduler from './task_scheduler';
export default function Advanced() {
return (
<div className="mailpoet-settings-grid">
<BounceAddress />
<TaskScheduler />
</div>
);
}

View File

@@ -0,0 +1,101 @@
import React from 'react';
import ReactStringReplace from 'react-string-replace';
import { t, onChange } from 'common/functions';
import { useSetting, useSelector } from 'settings/store/hooks';
import { Label, Inputs } from 'settings/components';
export default function TaskScheduler() {
const [method, setMethod] = useSetting('cron_trigger', 'method');
const paths = useSelector('getPaths')();
return (
<>
<Label
title={t('taskCron')}
description={(
<>
{t('taskCronDescription')}
{' '}
<a
href="https://kb.mailpoet.com/article/129-what-is-the-newsletter-task-scheduler"
data-beacon-article="57ce0a7a903360649f6e5703"
rel="noopener noreferrer"
target="_blank"
>
{t('readMore')}
</a>
</>
)}
htmlFor="cron_trigger-method"
/>
<Inputs>
<input
type="radio"
id="cron_trigger-method-wordpress"
value="WordPress"
checked={method === 'WordPress'}
onChange={onChange(setMethod)}
/>
<label htmlFor="cron_trigger-method-wordpress">
{t('websiteVisitors')}
</label>
<br />
<input
type="radio"
id="cron_trigger-method-mailpoet"
value="MailPoet"
checked={method === 'MailPoet'}
onChange={onChange(setMethod)}
/>
<label htmlFor="cron_trigger-method-mailpoet">
{ReactStringReplace(t('mailpoetScript'),
/\[link\](.*?)\[\/link\]/,
(text) => (
<a
key={text}
href="https://kb.mailpoet.com/article/131-hosts-which-mailpoet-task-scheduler-wont-work"
data-beacon-article="57ce0b05c6979108399a0456"
rel="noopener noreferrer"
target="_blank"
>
{text}
</a>
))}
</label>
<br />
<input
type="radio"
id="cron_trigger-method-cron"
value="Linux Cron"
checked={method === 'Linux Cron'}
onChange={onChange(setMethod)}
/>
<label htmlFor="cron_trigger-method-cron">
{t('serverCron')}
</label>
{method === 'Linux Cron' && (
<>
<br />
{t('addCommandToCrontab')}
<br />
<input
type="text"
readOnly
className="large-text"
value={`php ${paths.plugin}/mailpoet-cron.php ${paths.root}`}
/>
<br />
{t('withFrequency')}
<br />
<input
type="text"
readOnly
value="*/1 * * * *"
/>
</>
)}
</Inputs>
</>
);
}

View File

@@ -4,6 +4,7 @@ import normalizeSettings from './normalize_settings';
export default function makeDefaultState(window: any): State {
const pages = window.mailpoet_pages;
const paths = window.mailpoet_paths;
const segments = window.mailpoet_segments;
const save = { inProgress: false, error: null };
const data = normalizeSettings(window.mailpoet_settings);
@@ -32,7 +33,7 @@ export default function makeDefaultState(window: any): State {
key: data.premium.premium_key || data.mta.mailpoet_api_key,
};
return {
data, flags, save, keyActivation, segments, pages,
data, flags, save, keyActivation, segments, pages, paths,
};
}

View File

@@ -48,3 +48,7 @@ export function getPages(state: State) {
export function getKeyActivationState(state: State) {
return state.keyActivation;
}
export function getPaths(state: State) {
return state.paths;
}

View File

@@ -226,6 +226,10 @@ export type State = {
data: Settings
segments: Segment[]
pages: Page[]
paths: {
root: string
plugin: string
}
flags: {
woocommerce: boolean
newUser: boolean

View File

@@ -78,13 +78,15 @@ class Settings {
'members_plugin_active' => $this->wp->isPluginActive('members/members.php'),
'pages' => Pages::getAll(),
'current_user' => $this->wp->wpGetCurrentUser(),
'linux_cron_path' => dirname(dirname(dirname(__DIR__))),
'is_woocommerce_active' => $this->woocommerceHelper->isWooCommerceActive(),
'ABSPATH' => ABSPATH,
'hosts' => [
'web' => Hosts::getWebHosts(),
'smtp' => Hosts::getSMTPHosts(),
],
'paths' => [
'root' => ABSPATH,
'plugin' => dirname(dirname(dirname(__DIR__))),
],
'built_in_captcha_supported' => $this->captcha->isSupported(),
];

View File

@@ -17,6 +17,7 @@
var mailpoet_mss_key_valid = <%= json_encode(mss_key_valid) %>;
var mailpoet_premium_key_valid = <%= json_encode(premium_key_valid) %>;
var mailpoet_premium_plugin_installed = <%= json_encode(premium_plugin_installed) %>;
var mailpoet_paths = <%= json_encode(paths) %>;
<% endautoescape %>
var mailpoet_beacon_articles = [
'57f71d49c697911f2d323486',
@@ -109,7 +110,7 @@
'taskCron': __('Newsletter task scheduler (cron)'),
'taskCronDescription': __('Select what will activate your newsletter queue.'),
'websiteVisitors': __('Visitors to your website (recommended)'),
'mailPoetScript': __("MailPoet's own script. Doesn't work with [link]these hosts[/link]."),
'mailpoetScript': __("MailPoet's own script. Doesn't work with [link]these hosts[/link]."),
'serverCron': __("Server side cron (Linux cron)"),
'addCommandToCrontab': __("To use this option please add this command to your crontab:"),
'withFrequency': __("With the frequency of running it every minute:"),