Skip to content

Node.js based forum software built for the modern web

module changes, fixed missing interval

barisusakli83ab462ff5eb
diff --git a/src/emailer.js b/src/emailer.js
index d3b7d1f9aa..bc98431b9f 100644
--- a/src/emailer.js
+++ b/src/emailer.js
@@ -11,52 +11,56 @@ var fs = require('fs'),
meta = require('./meta'),
translator = require('../public/src/translator'),
- app = {},
- Emailer = {};
-
-
-Emailer.registerApp = function(expressApp) {
- app = expressApp;
- return Emailer;
-};
-
-Emailer.send = function(template, uid, params) {
- async.parallel({
- html: function(next) {
- app.render('emails/' + template, params, next);
- },
- plaintext: function(next) {
- app.render('emails/' + template + '_plaintext', params, next);
- },
- email: async.apply(User.getUserField, uid, 'email'),
- settings: async.apply(User.getSettings, uid)
- }, function(err, results) {
- async.map([results.html, results.plaintext, params.subject], function(raw, next) {
- translator.translate(raw, results.settings.language || meta.config.defaultLang || 'en_GB', function(translated) {
- next(undefined, translated);
- });
- }, function(err, translated) {
- if (err) {
- return winston.error(err.message);
- } else if (!results.email) {
- return winston.warn('uid : ' + uid + ' has no email, not sending.');
- }
-
- if (Plugins.hasListeners('action:email.send')) {
- Plugins.fireHook('action:email.send', {
- to: results.email,
- from: meta.config['email:from'] || '[email protected]',
- subject: translated[2],
- html: translated[0],
- plaintext: translated[1],
- template: template,
- uid: uid
+ app;
+
+(function(Emailer) {
+ Emailer.registerApp = function(expressApp) {
+ app = expressApp;
+ return Emailer;
+ };
+
+ Emailer.send = function(template, uid, params) {
+ if (!app) {
+ winston.warn('[emailer] App not ready!');
+ return;
+ }
+
+ async.parallel({
+ html: function(next) {
+ app.render('emails/' + template, params, next);
+ },
+ plaintext: function(next) {
+ app.render('emails/' + template + '_plaintext', params, next);
+ },
+ email: async.apply(User.getUserField, uid, 'email'),
+ settings: async.apply(User.getSettings, uid)
+ }, function(err, results) {
+ async.map([results.html, results.plaintext, params.subject], function(raw, next) {
+ translator.translate(raw, results.settings.language || meta.config.defaultLang || 'en_GB', function(translated) {
+ next(undefined, translated);
});
- } else {
- winston.warn('[emailer] No active email plugin found!');
- }
+ }, function(err, translated) {
+ if (err) {
+ return winston.error(err.message);
+ } else if (!results.email) {
+ return winston.warn('uid : ' + uid + ' has no email, not sending.');
+ }
+
+ if (Plugins.hasListeners('action:email.send')) {
+ Plugins.fireHook('action:email.send', {
+ to: results.email,
+ from: meta.config['email:from'] || '[email protected]',
+ subject: translated[2],
+ html: translated[0],
+ plaintext: translated[1],
+ template: template,
+ uid: uid
+ });
+ } else {
+ winston.warn('[emailer] No active email plugin found!');
+ }
+ });
});
- });
-};
+ };
+}(module.exports));
-module.exports = Emailer;
diff --git a/src/user/digest.js b/src/user/digest.js
index a253ae62af..a5d8f4d8e8 100644
--- a/src/user/digest.js
+++ b/src/user/digest.js
@@ -11,7 +11,7 @@ var async = require('async'),
batch = require('../batch'),
emailer = require('../emailer');
-module.exports = (function(Digest) {
+(function(Digest) {
Digest.execute = function(interval) {
var digestsDisabled = meta.config.disableEmailSubscriptions !== undefined && parseInt(meta.config.disableEmailSubscriptions, 10) === 1;
if (digestsDisabled) {
@@ -71,14 +71,14 @@ module.exports = (function(Digest) {
user.getMultipleUserFields(data.subscribers, ['uid', 'username', 'lastonline'], function(err, users) {
if (err) {
- winston.error('[user/jobs] Could not send digests (' + interval + '): ' + err.message);
+ winston.error('[user/jobs] Could not send digests (' + data.interval + '): ' + err.message);
return callback(err);
}
async.eachLimit(users, 100, function(userObj, next) {
user.notifications.getDailyUnread(userObj.uid, function(err, notifications) {
if (err) {
- winston.error('[user/jobs] Could not send digests (' + interval + '): ' + err.message);
+ winston.error('[user/jobs] Could not send digests (' + data.interval + '): ' + err.message);
return next(err);
}
@@ -109,7 +109,6 @@ module.exports = (function(Digest) {
});
}, callback);
});
- }
+ };
- return Digest;
-})({});
+}(module.exports));