updated emailer code so digest emails when tested in ACP are sent with real data instead of incomplete fake data

v1.18.x
Julian Lam 8 years ago
parent fa25dcd6a5
commit 313d48b47d

@ -8,6 +8,7 @@ var meta = require('../meta');
var plugins = require('../plugins');
var widgets = require('../widgets');
var user = require('../user');
var userDigest = require('../user/digest');
var logger = require('../logger');
var events = require('../events');
var emailer = require('../emailer');
@ -204,12 +205,23 @@ SocketAdmin.settings.clearSitemapCache = function (socket, data, callback) {
};
SocketAdmin.email.test = function (socket, data, callback) {
var site_title = meta.config.title || 'NodeBB';
emailer.send(data.template, socket.uid, {
subject: '[' + site_title + '] Test Email',
site_title: site_title,
url: nconf.get('url'),
}, callback);
switch (data.template) {
case 'digest':
userDigest.execute({
interval: 'day',
subscribers: [socket.uid],
}, callback);
break;
default:
var site_title = meta.config.title || 'NodeBB';
emailer.send(data.template, socket.uid, {
subject: '[' + site_title + '] Test Email',
site_title: site_title,
url: nconf.get('url'),
}, callback);
break;
}
};
SocketAdmin.analytics.get = function (socket, data, callback) {

@ -14,12 +14,12 @@ var utils = require('../utils');
var Digest = module.exports;
Digest.execute = function (interval, callback) {
Digest.execute = function (payload, callback) {
callback = callback || function () {};
var digestsDisabled = parseInt(meta.config.disableEmailSubscriptions, 10) === 1;
if (digestsDisabled) {
winston.info('[user/jobs] Did not send digests (' + interval + ') because subscription system is disabled.');
winston.info('[user/jobs] Did not send digests (' + payload.interval + ') because subscription system is disabled.');
return callback();
}
@ -27,8 +27,14 @@ Digest.execute = function (interval, callback) {
async.waterfall([
function (next) {
async.parallel({
topics: async.apply(topics.getLatestTopics, 0, 0, 9, interval),
subscribers: async.apply(Digest.getSubscribers, interval),
topics: async.apply(topics.getLatestTopics, 0, 0, 9, payload.interval),
subscribers: function (next) {
if (payload.subscribers) {
setImmediate(next, undefined, payload.subscribers);
} else {
Digest.getSubscribers(payload.interval, next);
}
},
}, next);
},
function (data, next) {
@ -47,14 +53,14 @@ Digest.execute = function (interval, callback) {
return topicObj;
});
data.interval = interval;
data.interval = payload.interval;
Digest.send(data, next);
},
], function (err) {
if (err) {
winston.error('[user/jobs] Could not send digests (' + interval + '): ' + err.message);
winston.error('[user/jobs] Could not send digests (' + payload.interval + '): ' + err.message);
} else {
winston.info('[user/jobs] Digest (' + interval + ') scheduling completed. ' + subscribers.length + ' email(s) sent.');
winston.info('[user/jobs] Digest (' + payload.interval + ') scheduling completed. ' + subscribers.length + ' email(s) sent.');
}
callback(err);

Loading…
Cancel
Save