v1.18.x
barisusakli 10 years ago
parent 52a53df80d
commit 8bba811aaf

@ -4,12 +4,13 @@
var async = require('async'), var async = require('async'),
winston = require('winston'), winston = require('winston'),
db = require('./../database'), db = require('../database'),
posts = require('./../posts'), posts = require('../posts'),
privileges = require('../privileges'), privileges = require('../privileges'),
postTools = require('./../postTools'), postTools = require('../postTools'),
threadTools = require('./../threadTools'); plugins = require('../plugins'),
threadTools = require('../threadTools');
module.exports = function(Topics) { module.exports = function(Topics) {
@ -70,41 +71,48 @@ module.exports = function(Topics) {
}; };
Topics.movePostToTopic = function(pid, tid, callback) { Topics.movePostToTopic = function(pid, tid, callback) {
threadTools.exists(tid, function(err, exists) { var postData;
if (err || !exists) { async.waterfall([
return callback(err || new Error('[[error:no-topic]]')); function(next) {
} threadTools.exists(tid, next);
},
posts.getPostFields(pid, ['tid', 'timestamp', 'votes'], function(err, postData) { function(exists, next) {
if (err) { if (!exists) {
return callback(err); return next(new Error('[[error:no-topic]]'));
} }
posts.getPostFields(pid, ['tid', 'timestamp', 'votes'], next);
if (!postData || !postData.tid) { },
return callback(new Error('[[error:no-post]]')); function(post, next) {
if (!post || !post.tid) {
return next(new Error('[[error:no-post]]'));
} }
postData = post;
postData.pid = pid;
Topics.removePostFromTopic(postData.tid, pid, function(err) { Topics.removePostFromTopic(postData.tid, pid, next);
if (err) { },
return callback(err); function(next) {
async.parallel([
function(next) {
Topics.decreasePostCount(postData.tid, next);
},
function(next) {
Topics.increasePostCount(tid, next);
},
function(next) {
posts.setPostField(pid, 'tid', tid, next);
},
function(next) {
Topics.addPostToTopic(tid, pid, postData.timestamp, postData.votes, next);
} }
], next);
async.parallel([ }
function(next) { ], function(err) {
Topics.decreasePostCount(postData.tid, next); if (err) {
}, return callback(err);
function(next) { }
Topics.increasePostCount(tid, next); plugins.fireHook('action:post.move', {post: postData, tid: tid});
}, callback(null);
function(next) {
posts.setPostField(pid, 'tid', tid, next);
},
function(next) {
Topics.addPostToTopic(tid, pid, postData.timestamp, postData.votes, next);
}
], callback);
});
});
}); });
}; };
}; };

@ -201,7 +201,9 @@ module.exports = function(Topics) {
function (next) { function (next) {
db.sortedSetRemove('tid:' + tid + ':posts:votes', pid, next); db.sortedSetRemove('tid:' + tid + ':posts:votes', pid, next);
} }
], callback); ], function(err, results) {
callback(err);
});
}; };
Topics.getPids = function(tid, callback) { Topics.getPids = function(tid, callback) {

Loading…
Cancel
Save