moving deleted topics wont cause topic count to go negative

v1.18.x
Baris Soner Usakli 11 years ago
parent 3d61a1b15b
commit 8bba4889d2

@ -186,44 +186,40 @@ var winston = require('winston'),
} }
ThreadTools.move = function(tid, cid, callback) { ThreadTools.move = function(tid, cid, callback) {
topics.getTopicFields(tid, ['cid', 'lastposttime'], function(err, topicData) { var topic;
if(err) { async.waterfall([
return callback(err); function(next) {
} topics.getTopicFields(tid, ['cid', 'lastposttime', 'deleted'], next);
},
var oldCid = topicData.cid; function(topicData, next) {
if(!oldCid) { topic = topicData;
return callback(new Error('invalid-topic')); db.sortedSetRemove('categories:' + topicData.cid + ':tid', tid, next);
} },
function(result, next) {
db.sortedSetRemove('categories:' + oldCid + ':tid', tid, function(err, result) { db.sortedSetAdd('categories:' + cid + ':tid', topic.lastposttime, tid, next);
if(err) {
return callback(err);
} }
], function(err, result) {
db.sortedSetAdd('categories:' + cid + ':tid', topicData.lastposttime, tid, function(err, result) {
if(err) { if(err) {
return callback(err); return callback(err);
} }
var oldCid = topic.cid;
topics.setTopicField(tid, 'cid', cid); topics.setTopicField(tid, 'cid', cid);
categories.moveActiveUsers(tid, oldCid, cid);
categories.moveRecentReplies(tid, oldCid, cid, function(err, data) { categories.moveRecentReplies(tid, oldCid, cid, function(err, data) {
if (err) { if (err) {
winston.err(err); winston.err(err);
} }
}); });
categories.moveActiveUsers(tid, oldCid, cid); if(!parseInt(topic.deleted, 10)) {
categories.incrementCategoryFieldBy(oldCid, 'topic_count', -1); categories.incrementCategoryFieldBy(oldCid, 'topic_count', -1);
categories.incrementCategoryFieldBy(cid, 'topic_count', 1); categories.incrementCategoryFieldBy(cid, 'topic_count', 1);
}
callback(null); callback(null);
}); });
});
});
} }
ThreadTools.isFollowing = function(tid, uid, callback) { ThreadTools.isFollowing = function(tid, uid, callback) {

Loading…
Cancel
Save