Bugfixes on sending
- added checks to prevent adding to the queue useless items - fixed issue with mta settings (duplicated "host" input / renamed duplicate to "domain" for MailGun) - fixed namespace issue on cron daemon/supervisor - fixed typo in migration preventing the newsletter_templates table to be created. - partially fixed cron.jsx
This commit is contained in:
@@ -4,59 +4,63 @@ define(
|
||||
'react-dom',
|
||||
'mailpoet'
|
||||
],
|
||||
function (
|
||||
function(
|
||||
React,
|
||||
ReactDOM,
|
||||
MailPoet
|
||||
) {
|
||||
var CronControl = React.createClass({
|
||||
getInitialState: function () {
|
||||
return (cronDaemon) ? cronDaemon : null;
|
||||
getInitialState: function() {
|
||||
return {
|
||||
status: 'loading'
|
||||
};
|
||||
},
|
||||
getDaemonData: function () {
|
||||
getDaemonData: function() {
|
||||
MailPoet.Ajax.post({
|
||||
endpoint: 'cron',
|
||||
action: 'getDaemonStatus'
|
||||
}).done(function (response) {
|
||||
jQuery('.button-primary').removeClass('disabled');
|
||||
if (!response) {
|
||||
this.replaceState();
|
||||
} else {
|
||||
})
|
||||
.done(function(response) {
|
||||
jQuery('.button-primary')
|
||||
.removeClass('disabled');
|
||||
if(response.status !== undefined) {
|
||||
this.setState(response);
|
||||
} else {
|
||||
this.replaceState();
|
||||
}
|
||||
}.bind(this));
|
||||
},
|
||||
componentDidMount: function componentDidMount() {
|
||||
if (this.isMounted()) {
|
||||
this.getDaemonData;
|
||||
componentDidMount: function() {
|
||||
if(this.isMounted()) {
|
||||
this.getDaemonData();
|
||||
setInterval(this.getDaemonData, 5000);
|
||||
}
|
||||
},
|
||||
controlDaemon: function (action) {
|
||||
jQuery('.button-primary').addClass('disabled');
|
||||
controlDaemon: function(action) {
|
||||
jQuery('.button-primary')
|
||||
.addClass('disabled');
|
||||
MailPoet.Ajax.post({
|
||||
endpoint: 'cron',
|
||||
action: 'controlDaemon',
|
||||
data: {'action': action}
|
||||
}).done(function (response) {
|
||||
if (!response) {
|
||||
this.replaceState();
|
||||
data: {
|
||||
'action': action
|
||||
}
|
||||
})
|
||||
.done(function(response) {
|
||||
if(!response.result) {
|
||||
//this.replaceState();
|
||||
} else {
|
||||
this.setState(response);
|
||||
//this.setState(response);
|
||||
}
|
||||
}.bind(this));
|
||||
},
|
||||
render: function () {
|
||||
if (!this.state) {
|
||||
return
|
||||
<div>
|
||||
Woops, daemon is not running ;\
|
||||
</div>
|
||||
render: function() {
|
||||
if(this.state.status === 'loading') {
|
||||
return(<div>Loading daemon status...</div>);
|
||||
}
|
||||
switch (this.state.status) {
|
||||
switch(this.state.status) {
|
||||
case 'started':
|
||||
return (
|
||||
<div>
|
||||
return(
|
||||
<div>
|
||||
Cron daemon is running.
|
||||
<br/>
|
||||
@@ -70,29 +74,29 @@ define(
|
||||
<a href="#" className="button-primary" onClick={this.controlDaemon.bind(null, 'stop')}>Stop</a>
|
||||
<a href="#" className="button-primary" onClick={this.controlDaemon.bind(null, 'pause')}>Pause</a>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
break;
|
||||
case 'paused':
|
||||
case 'stopped':
|
||||
return (
|
||||
return(
|
||||
<div>
|
||||
Daemon is {this.state.status}
|
||||
<br />
|
||||
<br />
|
||||
<a href="#" className="button-primary" onClick={this.controlDaemon.bind(null, 'start')}>Start</a>
|
||||
</div>
|
||||
)
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
let container = document.getElementById('cron_container');
|
||||
if (container) {
|
||||
|
||||
const container = document.getElementById('cron_container');
|
||||
|
||||
if(container) {
|
||||
ReactDOM.render(
|
||||
<CronControl />,
|
||||
document.getElementById('cron_status')
|
||||
)
|
||||
container
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
@@ -381,8 +381,6 @@ class Menu {
|
||||
}
|
||||
|
||||
function cron() {
|
||||
$daemon = new \MailPoet\Cron\BootStrapMenu();
|
||||
$data['daemon'] = json_encode($daemon->bootstrap());
|
||||
echo $this->renderer->render('cron.html', $data);
|
||||
echo $this->renderer->render('cron.html');
|
||||
}
|
||||
}
|
||||
|
@@ -105,7 +105,7 @@ class Migrator {
|
||||
'description varchar(250) NOT NULL,',
|
||||
'body LONGTEXT,',
|
||||
'thumbnail LONGTEXT,',
|
||||
'readonly TINYINT(1) DEFAULT 0',
|
||||
'readonly TINYINT(1) DEFAULT 0,',
|
||||
'created_at TIMESTAMP NOT NULL DEFAULT 0,',
|
||||
'updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
|
||||
'PRIMARY KEY (id)'
|
||||
|
@@ -25,8 +25,12 @@ class PublicAPI {
|
||||
}
|
||||
|
||||
function queue() {
|
||||
try {
|
||||
$queue = new Daemon($this->payload);
|
||||
$this->_checkAndCallMethod($queue, $this->action);
|
||||
} catch(\Exception $e) {
|
||||
// mailer configuration error
|
||||
}
|
||||
}
|
||||
|
||||
private function _checkAndCallMethod($class, $method, $terminate = false) {
|
||||
|
@@ -11,14 +11,13 @@ class Cron {
|
||||
function controlDaemon($data) {
|
||||
switch($data['action']) {
|
||||
case 'start':
|
||||
$supervisor = new Supervisor($forceStart = true);
|
||||
$supervisor = new \MailPoet\Cron\Supervisor($forceStart = true);
|
||||
wp_send_json(
|
||||
array(
|
||||
'result' => $supervisor->checkDaemon() ?
|
||||
true :
|
||||
false
|
||||
'result' => $supervisor->checkDaemon()
|
||||
)
|
||||
);
|
||||
exit;
|
||||
break;
|
||||
case 'stop':
|
||||
$status = 'stopped';
|
||||
@@ -27,7 +26,7 @@ class Cron {
|
||||
$status = 'paused';
|
||||
break;
|
||||
}
|
||||
$daemon = new Daemon();
|
||||
$daemon = new \MailPoet\Cron\Daemon();
|
||||
if(!$daemon->daemon || $daemon->daemonData['status'] !== 'started') {
|
||||
$result = false;
|
||||
} else {
|
||||
|
@@ -9,6 +9,19 @@ if(!defined('ABSPATH')) exit;
|
||||
|
||||
class SendingQueue {
|
||||
function add($data) {
|
||||
// check if mailer is properly configured
|
||||
try {
|
||||
new Mailer(false);
|
||||
} catch(\Exception $e) {
|
||||
wp_send_json(
|
||||
array(
|
||||
'result' => false,
|
||||
'errors' => array($e->getMessage())
|
||||
)
|
||||
);
|
||||
exit;
|
||||
}
|
||||
|
||||
$queue = \MailPoet\Models\SendingQueue::where('newsletter_id', $data['newsletter_id'])
|
||||
->whereNull('status')
|
||||
->findArray();
|
||||
@@ -34,6 +47,17 @@ class SendingQueue {
|
||||
'id'
|
||||
));
|
||||
}
|
||||
|
||||
if(empty($subscriber_ids)) {
|
||||
wp_send_json(
|
||||
array(
|
||||
'result' => false,
|
||||
'errors' => array(__('There are no subscribers.'))
|
||||
)
|
||||
);
|
||||
exit;
|
||||
}
|
||||
|
||||
$subscriber_ids = array_unique($subscriber_ids);
|
||||
$queue->subscribers = json_encode(
|
||||
array(
|
||||
|
@@ -1,10 +1,5 @@
|
||||
<% extends 'layout.html' %>
|
||||
|
||||
<% block content %>
|
||||
<div id="cron_container">
|
||||
<div id="cron_status"></div>
|
||||
</div>
|
||||
<script>
|
||||
var cronDaemon = <%= daemon|raw %>
|
||||
</script>
|
||||
<div id="cron_container"></div>
|
||||
<% endblock %>
|
||||
|
@@ -492,9 +492,9 @@
|
||||
<input
|
||||
type="text"
|
||||
class="regular-text"
|
||||
id="settings[mta_host]"
|
||||
name="mta[host]"
|
||||
value="<%= settings.mta.host %>" />
|
||||
id="settings[mta_domain]"
|
||||
name="mta[domain]"
|
||||
value="<%= settings.mta.domain %>" />
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
|
Reference in New Issue
Block a user