|
|
@ -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,25 +71,27 @@ 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]]'));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!postData || !postData.tid) {
|
|
|
|
|
|
|
|
return callback(new Error('[[error:no-post]]'));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
posts.getPostFields(pid, ['tid', 'timestamp', 'votes'], next);
|
|
|
|
Topics.removePostFromTopic(postData.tid, pid, function(err) {
|
|
|
|
},
|
|
|
|
if (err) {
|
|
|
|
function(post, next) {
|
|
|
|
return callback(err);
|
|
|
|
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([
|
|
|
|
async.parallel([
|
|
|
|
function(next) {
|
|
|
|
function(next) {
|
|
|
|
Topics.decreasePostCount(postData.tid, next);
|
|
|
|
Topics.decreasePostCount(postData.tid, next);
|
|
|
@ -102,9 +105,14 @@ module.exports = function(Topics) {
|
|
|
|
function(next) {
|
|
|
|
function(next) {
|
|
|
|
Topics.addPostToTopic(tid, pid, postData.timestamp, postData.votes, 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);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|