Manually change digest settings

Unsolved Technical Support
  • I did a massive migration 2 years ago and as a result nearly everybody in the system was set to "weekly" as the default digest setting. I also have emails the as so old they will bounce.

    1. What query/script could I run to change all the weekly values to system default?
    2. Given a list of email addresses, what query or script could I run to change the digest value to none or whatever "off" would be.

    Thanks in advance.

  • I think a script like this could work:

    'use strict';
    
    var nconf = require('nconf');
    var async = require('async');
    
    nconf.file({
    	file: 'config.json',
    });
    
    nconf.defaults({
    	base_dir: __dirname,
    	views_dir: './build/public/templates',
    });
    
    var db = require('./src/database');
    
    async.series([
    	db.init,
    	process,
    ], (err) => {
    	if (err) {
    		console.error(err);
    		process.exit(1);
    	}
    
    	process.exit();
    });
    
    const freq = 'off'; // or daily, weekly, monthly
    
    function process(callback) {
    	var batch = require('./src/batch');
            var User = require('./src/user');
    
    	batch.processSortedSet('users:joindate', function (uids, next) {
    		async.parallel([
    			cb => async.each(uids, (uid, next) => {
    				User.setSetting(uid, 'dailyDigestFreq', freq, next);
    			}, cb),
                            cb => async.each(uids, (uid, next) => {
    				User.updateDigestSetting(uid, freq, next);
    			}, cb),
    		], next);
    	}, callback);
    }
    

    I think this should work to set all users to a specific frequency. Please backup your database before trying this. You might also need to fix a couple JS errors, I haven't tried this myself.

    Create a new file called process-users.js in your main nodebb directory (the one with config.json etc), paste that script into it, set the frequency you desire, and run node process-users from within that directory to set all of your users to the selected frequency.


Suggested Topics