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

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

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

Loading…
Cancel
Save