mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-07-07 18:01:51 +02:00
closes #4766
This commit is contained in:
@@ -8,6 +8,11 @@ define('admin/settings/email', ['admin/settings'], function(settings) {
|
||||
module.init = function() {
|
||||
configureEmailTester();
|
||||
configureEmailEditor();
|
||||
|
||||
$(window).on('action:admin.settingsLoaded action:admin.settingsSaved', handleDigestHourChange);
|
||||
$(window).on('action:admin.settingsSaved', function() {
|
||||
socket.emit('admin.user.restartJobs');
|
||||
});
|
||||
};
|
||||
|
||||
function configureEmailTester() {
|
||||
@@ -57,5 +62,30 @@ define('admin/settings/email', ['admin/settings'], function(settings) {
|
||||
});
|
||||
}
|
||||
|
||||
function handleDigestHourChange() {
|
||||
var hour = parseInt($('#digestHour').val(), 10);
|
||||
|
||||
if (isNaN(hour)) {
|
||||
hour = 17;
|
||||
} else if (hour > 23 || hour < 0) {
|
||||
hour = 0;
|
||||
}
|
||||
|
||||
socket.emit('meta.getServerTime', {}, function(err, now) {
|
||||
now = new Date(now);
|
||||
|
||||
$('#serverTime').text(now.toString());
|
||||
|
||||
now.setHours(parseInt(hour, 10), 0, 0, 0);
|
||||
|
||||
// If adjusted time is in the past, move to next day
|
||||
if (now.getTime() < Date.now()) {
|
||||
now.setDate(now.getDate() + 1);
|
||||
}
|
||||
|
||||
$('#nextDigestTime').text(now.toString());
|
||||
});
|
||||
}
|
||||
|
||||
return module;
|
||||
});
|
||||
|
||||
@@ -226,5 +226,8 @@ User.rejectRegistration = function(socket, data, callback) {
|
||||
user.rejectRegistration(data.username, callback);
|
||||
};
|
||||
|
||||
User.restartJobs = function(socket, data, callback) {
|
||||
user.startJobs(callback);
|
||||
};
|
||||
|
||||
module.exports = User;
|
||||
|
||||
@@ -68,6 +68,9 @@ function leaveCurrentRoom(socket) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SocketMeta.getServerTime = function(socket, data, callback) {
|
||||
// Returns server time in milliseconds
|
||||
callback(null, Date.now());
|
||||
};
|
||||
|
||||
module.exports = SocketMeta;
|
||||
|
||||
@@ -1,29 +1,69 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
var winston = require('winston'),
|
||||
cronJob = require('cron').CronJob,
|
||||
var winston = require('winston');
|
||||
var cronJob = require('cron').CronJob;
|
||||
|
||||
meta = require('../meta');
|
||||
var meta = require('../meta');
|
||||
|
||||
var jobs = {};
|
||||
|
||||
module.exports = function(User) {
|
||||
User.startJobs = function() {
|
||||
new cronJob('0 0 17 * * *', function() {
|
||||
winston.verbose('[user.startJobs] Digest job (daily) started.');
|
||||
User.startJobs = function(callback) {
|
||||
winston.verbose('[user/jobs] (Re-)starting user jobs...');
|
||||
var terminated = 0;
|
||||
var started = 0;
|
||||
var digestHour = parseInt(meta.config.digestHour, 10);
|
||||
|
||||
// Fix digest hour if invalid
|
||||
if (isNaN(digestHour)) {
|
||||
digestHour = 17;
|
||||
} else if (digestHour > 23 || digestHour < 0) {
|
||||
digestHour = 0;
|
||||
}
|
||||
|
||||
// Terminate any active cron jobs
|
||||
for(var jobId in jobs) {
|
||||
if (jobs.hasOwnProperty(jobId)) {
|
||||
winston.verbose('[user/jobs] Terminating job (' + jobId + ')');
|
||||
jobs[jobId].stop();
|
||||
delete jobs[jobId];
|
||||
++terminated;
|
||||
}
|
||||
}
|
||||
winston.verbose('[user/jobs] ' + terminated + ' jobs terminated');
|
||||
|
||||
jobs['digest.daily'] = new cronJob('0 0 ' + digestHour + ' * * *', function() {
|
||||
winston.verbose('[user/jobs] Digest job (daily) started.');
|
||||
User.digest.execute('day');
|
||||
}, null, true);
|
||||
winston.verbose('[user/jobs] Starting job (digest.daily)');
|
||||
++started;
|
||||
|
||||
new cronJob('0 0 17 * * 0', function() {
|
||||
winston.verbose('[user.startJobs] Digest job (weekly) started.');
|
||||
jobs['digest.weekly'] = new cronJob('0 0 ' + digestHour + ' * * 0', function() {
|
||||
winston.verbose('[user/jobs] Digest job (weekly) started.');
|
||||
User.digest.execute('week');
|
||||
}, null, true);
|
||||
winston.verbose('[user/jobs] Starting job (digest.weekly)');
|
||||
++started;
|
||||
|
||||
new cronJob('0 0 17 1 * *', function() {
|
||||
winston.verbose('[user.startJobs] Digest job (monthly) started.');
|
||||
jobs['digest.monthly'] = new cronJob('0 0 ' + digestHour + ' 1 * *', function() {
|
||||
winston.verbose('[user/jobs] Digest job (monthly) started.');
|
||||
User.digest.execute('month');
|
||||
}, null, true);
|
||||
winston.verbose('[user/jobs] Starting job (digest.monthly)');
|
||||
++started;
|
||||
|
||||
new cronJob('0 0 0 * * *', User.reset.clean, null, true);
|
||||
jobs['reset.clean'] = new cronJob('0 0 0 * * *', User.reset.clean, null, true);
|
||||
winston.verbose('[user/jobs] Starting job (reset.clean)');
|
||||
++started;
|
||||
|
||||
winston.verbose('[user/jobs] ' + started + ' jobs started');
|
||||
|
||||
if (typeof callback === 'function') {
|
||||
callback();
|
||||
}
|
||||
|
||||
return;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -34,14 +34,14 @@
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="email:GmailTransport:user"><strong>Username</strong></label>
|
||||
<input type="text" class="form-control input-lg" id="email:GmailTransport:user" data-field="email:GmailTransport:user" placeholder="admin@example.org" /><br />
|
||||
<input type="text" class="form-control input-lg" id="email:GmailTransport:user" data-field="email:GmailTransport:user" placeholder="admin@example.org" />
|
||||
<p class="help-block">
|
||||
Enter the full email address here, especially if you are using a Google Apps managed domain.
|
||||
</p>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="email:GmailTransport:pass"><strong>Password</strong></label>
|
||||
<input type="password" class="form-control input-lg" id="email:GmailTransport:pass" data-field="email:GmailTransport:pass" /><br />
|
||||
<input type="password" class="form-control input-lg" id="email:GmailTransport:pass" data-field="email:GmailTransport:pass" />
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
@@ -92,6 +92,17 @@
|
||||
<span class="mdl-switch__label">Disable subscriber notification emails</span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="digestHour"><strong>Digest Hour</strong></label>
|
||||
<input type="number" class="form-control input-lg" id="digestHour" data-field="digestHour" placeholder="17" min="0" max="24" />
|
||||
<p class="help-block">
|
||||
Please enter a number representing the hour to send scheduled email digests (e.g. <code>0</code> for midnight, <code>17</code> for 5:00pm).
|
||||
Keep in mind that this is the hour according to the server itself, and may not exactly match your system clock.<br />
|
||||
The approximate server time is: <span id="serverTime"></span><br />
|
||||
The next daily digest is scheduled to be sent <span id="nextDigestTime"></span>
|
||||
</p>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user