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

@ -14,12 +14,12 @@ var utils = require('../utils');
var Digest = module.exports; var Digest = module.exports;
Digest.execute = function (interval, callback) { Digest.execute = function (payload, callback) {
callback = callback || function () {}; callback = callback || function () {};
var digestsDisabled = parseInt(meta.config.disableEmailSubscriptions, 10) === 1; var digestsDisabled = parseInt(meta.config.disableEmailSubscriptions, 10) === 1;
if (digestsDisabled) { 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(); return callback();
} }
@ -27,8 +27,14 @@ Digest.execute = function (interval, callback) {
async.waterfall([ async.waterfall([
function (next) { function (next) {
async.parallel({ async.parallel({
topics: async.apply(topics.getLatestTopics, 0, 0, 9, interval), topics: async.apply(topics.getLatestTopics, 0, 0, 9, payload.interval),
subscribers: async.apply(Digest.getSubscribers, interval), subscribers: function (next) {
if (payload.subscribers) {
setImmediate(next, undefined, payload.subscribers);
} else {
Digest.getSubscribers(payload.interval, next);
}
},
}, next); }, next);
}, },
function (data, next) { function (data, next) {
@ -47,14 +53,14 @@ Digest.execute = function (interval, callback) {
return topicObj; return topicObj;
}); });
data.interval = interval; data.interval = payload.interval;
Digest.send(data, next); Digest.send(data, next);
}, },
], function (err) { ], function (err) {
if (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 { } 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); callback(err);

Loading…
Cancel
Save