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:
Jonathan Labreuille
2015-12-07 13:29:42 +01:00
parent c0ba218949
commit 268dabdc9f
8 changed files with 132 additions and 108 deletions

View File

@@ -11,52 +11,56 @@ define(
) {
var CronControl = React.createClass({
getInitialState: function() {
return (cronDaemon) ? cronDaemon : null;
return {
status: 'loading'
};
},
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() {
componentDidMount: function() {
if(this.isMounted()) {
this.getDaemonData;
this.getDaemonData();
setInterval(this.getDaemonData, 5000);
}
},
controlDaemon: function(action) {
jQuery('.button-primary').addClass('disabled');
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>
if(this.state.status === 'loading') {
return(<div>Loading daemon status...</div>);
}
switch(this.state.status) {
case 'started':
return(
<div>
<div>
Cron daemon is running.
<br/>
@@ -70,7 +74,6 @@ define(
<a href="#" className="button-primary" onClick={this.controlDaemon.bind(null, 'stop')}>Stop</a>&nbsp;&nbsp;
<a href="#" className="button-primary" onClick={this.controlDaemon.bind(null, 'pause')}>Pause</a>
</div>
</div>
);
break;
case 'paused':
@@ -82,17 +85,18 @@ define(
<br />
<a href="#" className="button-primary" onClick={this.controlDaemon.bind(null, 'start')}>Start</a>
</div>
)
);
break;
}
}
});
let container = document.getElementById('cron_container');
const container = document.getElementById('cron_container');
if(container) {
ReactDOM.render(
<CronControl />,
document.getElementById('cron_status')
)
}
}
container
);
}
});

View File

@@ -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');
}
}

View File

@@ -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)'

View File

@@ -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) {

View File

@@ -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 {

View File

@@ -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(

View File

@@ -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 %>

View File

@@ -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>