mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-05-07 22:06:07 +02:00
closes #6274
This commit is contained in:
@@ -253,16 +253,13 @@ module.exports = function (Topics) {
|
||||
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
Topics.exists(tid, next);
|
||||
},
|
||||
function (exists, next) {
|
||||
if (!exists) {
|
||||
return next(new Error('[[error:no-topic]]'));
|
||||
}
|
||||
Topics.getTopicFields(tid, ['cid', 'lastposttime', 'pinned', 'deleted', 'postcount', 'upvotes', 'downvotes'], next);
|
||||
Topics.getTopicData(tid, next);
|
||||
},
|
||||
function (topicData, next) {
|
||||
topic = topicData;
|
||||
if (!topic) {
|
||||
return next(new Error('[[error:no-topic]]'));
|
||||
}
|
||||
if (parseInt(cid, 10) === parseInt(topic.cid, 10)) {
|
||||
return next(new Error('[[error:cant-move-topic-to-same-category]]'));
|
||||
}
|
||||
@@ -273,11 +270,15 @@ module.exports = function (Topics) {
|
||||
'cid:' + topicData.cid + ':tids:votes',
|
||||
'cid:' + topicData.cid + ':tids:lastposttime',
|
||||
'cid:' + topicData.cid + ':recent_tids',
|
||||
'cid:' + topicData.cid + ':uid:' + topicData.uid + ':tids',
|
||||
], tid, next);
|
||||
},
|
||||
function (next) {
|
||||
db.sortedSetAdd('cid:' + cid + ':tids:lastposttime', topic.lastposttime, tid, next);
|
||||
},
|
||||
function (next) {
|
||||
db.sortedSetAdd('cid:' + cid + ':uid:' + topic.uid + ':tids', topic.timestamp, tid, next);
|
||||
},
|
||||
function (next) {
|
||||
if (parseInt(topic.pinned, 10)) {
|
||||
db.sortedSetAdd('cid:' + cid + ':tids:pinned', Date.now(), tid, next);
|
||||
|
||||
52
src/upgrades/1.7.4/fix_user_topics_per_category.js
Normal file
52
src/upgrades/1.7.4/fix_user_topics_per_category.js
Normal file
@@ -0,0 +1,52 @@
|
||||
'use strict';
|
||||
|
||||
var async = require('async');
|
||||
var batch = require('../../batch');
|
||||
var db = require('../../database');
|
||||
|
||||
module.exports = {
|
||||
name: 'Fix topics in categories per user if they were moved',
|
||||
timestamp: Date.UTC(2018, 0, 22),
|
||||
method: function (callback) {
|
||||
var progress = this.progress;
|
||||
|
||||
batch.processSortedSet('topics:tid', function (tids, next) {
|
||||
async.eachLimit(tids, 500, function (tid, _next) {
|
||||
progress.incr();
|
||||
var topicData;
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
db.getObjectFields('topic:' + tid, ['cid', 'tid', 'uid', 'oldCid', 'timestamp'], next);
|
||||
},
|
||||
function (_topicData, next) {
|
||||
topicData = _topicData;
|
||||
if (!topicData.cid || !topicData.oldCid) {
|
||||
return _next();
|
||||
}
|
||||
|
||||
db.isSortedSetMember('cid:' + topicData.oldCid + ':uid:' + topicData.uid, topicData.tid, next);
|
||||
},
|
||||
function (isMember, next) {
|
||||
if (isMember) {
|
||||
async.series([
|
||||
function (next) {
|
||||
db.sortedSetRemove('cid:' + topicData.oldCid + ':uid:' + topicData.uid + ':tids', tid, next);
|
||||
},
|
||||
function (next) {
|
||||
db.sortedSetAdd('cid:' + topicData.cid + ':uid:' + topicData.uid + ':tids', topicData.timestamp, tid, next);
|
||||
},
|
||||
], function (err) {
|
||||
next(err);
|
||||
});
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
},
|
||||
], _next);
|
||||
}, next);
|
||||
}, {
|
||||
progress: progress,
|
||||
batch: 500,
|
||||
}, callback);
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user