mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-09 07:25:46 +01:00
moving deleted topics wont cause topic count to go negative
This commit is contained in:
@@ -186,44 +186,40 @@ var winston = require('winston'),
|
||||
}
|
||||
|
||||
ThreadTools.move = function(tid, cid, callback) {
|
||||
topics.getTopicFields(tid, ['cid', 'lastposttime'], function(err, topicData) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
var oldCid = topicData.cid;
|
||||
if(!oldCid) {
|
||||
return callback(new Error('invalid-topic'));
|
||||
}
|
||||
|
||||
db.sortedSetRemove('categories:' + oldCid + ':tid', tid, function(err, result) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
db.sortedSetAdd('categories:' + cid + ':tid', topicData.lastposttime, tid, function(err, result) {
|
||||
|
||||
var topic;
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
topics.getTopicFields(tid, ['cid', 'lastposttime', 'deleted'], next);
|
||||
},
|
||||
function(topicData, next) {
|
||||
topic = topicData;
|
||||
db.sortedSetRemove('categories:' + topicData.cid + ':tid', tid, next);
|
||||
},
|
||||
function(result, next) {
|
||||
db.sortedSetAdd('categories:' + cid + ':tid', topic.lastposttime, tid, next);
|
||||
}
|
||||
], function(err, result) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
var oldCid = topic.cid;
|
||||
|
||||
topics.setTopicField(tid, 'cid', cid);
|
||||
|
||||
categories.moveActiveUsers(tid, oldCid, cid);
|
||||
categories.moveRecentReplies(tid, oldCid, cid, function(err, data) {
|
||||
if (err) {
|
||||
winston.err(err);
|
||||
}
|
||||
});
|
||||
|
||||
categories.moveActiveUsers(tid, oldCid, cid);
|
||||
|
||||
if(!parseInt(topic.deleted, 10)) {
|
||||
categories.incrementCategoryFieldBy(oldCid, 'topic_count', -1);
|
||||
categories.incrementCategoryFieldBy(cid, 'topic_count', 1);
|
||||
}
|
||||
|
||||
callback(null);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
ThreadTools.isFollowing = function(tid, uid, callback) {
|
||||
|
||||
Reference in New Issue
Block a user