Skip to content

Instantly share code, notes, and snippets.

@psychobunny
Last active April 16, 2020 09:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save psychobunny/5f0f25c6efdfc2df9d6d to your computer and use it in GitHub Desktop.
Save psychobunny/5f0f25c6efdfc2df9d6d to your computer and use it in GitHub Desktop.
NodeBB patch - Remove OP and replace it with first reply
// paste this in https://github.com/NodeBB/NodeBB/blob/master/src/routes/debug.js
// and then don't forget to remove it!
router.get('/remove-op', function(req, res) {
var db = require('../database'),
async = require('async');
db.getSortedSetRange('topics:tid', 0, -1, function(err, tids) {
async.eachLimit(tids, 50, function(tid, next) {
db.getSortedSetRange('tid:' + tid + ':posts', 0, 0, function(err, pid) {
if (err) {
throw new Error(err);
}
pid = pid[0];
db.sortedSetRemove('tid:' + tid + ':posts', pid, function(err) {
if (err) {
throw new Error(err);
}
db.setObjectField('topic:' + tid, 'mainPid', pid, next);
});
});
}, function(err) {
if (err) {
throw new Error(err);
}
res.json({status: true});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment