post count fix for post move

v1.18.x
barisusakli 10 years ago
parent 56947b999e
commit 782896997d

@ -71,31 +71,38 @@ module.exports = function(Topics) {
Topics.movePostToTopic = function(pid, tid, callback) { Topics.movePostToTopic = function(pid, tid, callback) {
threadTools.exists(tid, function(err, exists) { threadTools.exists(tid, function(err, exists) {
if(err || !exists) { if (err || !exists) {
return callback(err || new Error('[[error:no-topic]]')); return callback(err || new Error('[[error:no-topic]]'));
} }
posts.getPostFields(pid, ['deleted', 'tid', 'timestamp', 'votes'], function(err, postData) { posts.getPostFields(pid, ['tid', 'timestamp', 'votes'], function(err, postData) {
if(err) { if (err) {
return callback(err); return callback(err);
} }
if(!postData || !postData.tid) { if (!postData || !postData.tid) {
return callback(new Error('[[error:no-post]]')); return callback(new Error('[[error:no-post]]'));
} }
Topics.removePostFromTopic(postData.tid, pid, function(err) { Topics.removePostFromTopic(postData.tid, pid, function(err) {
if(err) { if (err) {
return callback(err); return callback(err);
} }
if(!parseInt(postData.deleted, 10)) { async.parallel([
Topics.decreasePostCount(postData.tid); function(next) {
Topics.increasePostCount(tid); Topics.decreasePostCount(postData.tid, next);
} },
function(next) {
posts.setPostField(pid, 'tid', tid); Topics.increasePostCount(tid, next);
Topics.addPostToTopic(tid, pid, postData.timestamp, postData.votes, callback); },
function(next) {
posts.setPostField(pid, 'tid', tid, next);
},
function(next) {
Topics.addPostToTopic(tid, pid, postData.timestamp, postData.votes, next);
}
], callback);
}); });
}); });
}); });

Loading…
Cancel
Save