|
|
|
@ -1,19 +1,22 @@
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
var async = require('async'),
|
|
|
|
|
_ = require('underscore'),
|
|
|
|
|
var async = require('async');
|
|
|
|
|
var _ = require('underscore');
|
|
|
|
|
|
|
|
|
|
db = require('../database'),
|
|
|
|
|
topics = require('../topics'),
|
|
|
|
|
user = require('../user'),
|
|
|
|
|
plugins = require('../plugins');
|
|
|
|
|
var db = require('../database');
|
|
|
|
|
var topics = require('../topics');
|
|
|
|
|
var user = require('../user');
|
|
|
|
|
var plugins = require('../plugins');
|
|
|
|
|
|
|
|
|
|
module.exports = function(Posts) {
|
|
|
|
|
|
|
|
|
|
Posts.delete = function(pid, callback) {
|
|
|
|
|
Posts.delete = function(pid, uid, callback) {
|
|
|
|
|
var postData;
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
plugins.fireHook('filter:post.delete', {pid: pid, uid: uid}, next);
|
|
|
|
|
},
|
|
|
|
|
function (data, next) {
|
|
|
|
|
Posts.setPostField(pid, 'deleted', 1, next);
|
|
|
|
|
},
|
|
|
|
|
function (next) {
|
|
|
|
@ -24,8 +27,6 @@ module.exports = function(Posts) {
|
|
|
|
|
topics.getTopicField(_post.tid, 'cid', next);
|
|
|
|
|
},
|
|
|
|
|
function (cid, next) {
|
|
|
|
|
plugins.fireHook('action:post.delete', pid);
|
|
|
|
|
|
|
|
|
|
async.parallel([
|
|
|
|
|
function(next) {
|
|
|
|
|
updateTopicTimestamp(postData.tid, next);
|
|
|
|
@ -40,16 +41,20 @@ module.exports = function(Posts) {
|
|
|
|
|
topics.updateTeaser(postData.tid, next);
|
|
|
|
|
}
|
|
|
|
|
], function(err) {
|
|
|
|
|
plugins.fireHook('action:post.delete', pid);
|
|
|
|
|
next(err, postData);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
], callback);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Posts.restore = function(pid, callback) {
|
|
|
|
|
Posts.restore = function(pid, uid, callback) {
|
|
|
|
|
var postData;
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
plugins.fireHook('filter:post.restore', {pid: pid, uid: uid}, next);
|
|
|
|
|
},
|
|
|
|
|
function (data, next) {
|
|
|
|
|
Posts.setPostField(pid, 'deleted', 0, next);
|
|
|
|
|
},
|
|
|
|
|
function (next) {
|
|
|
|
@ -61,8 +66,6 @@ module.exports = function(Posts) {
|
|
|
|
|
},
|
|
|
|
|
function (cid, next) {
|
|
|
|
|
postData.cid = cid;
|
|
|
|
|
plugins.fireHook('action:post.restore', _.clone(postData));
|
|
|
|
|
|
|
|
|
|
async.parallel([
|
|
|
|
|
function(next) {
|
|
|
|
|
updateTopicTimestamp(postData.tid, next);
|
|
|
|
@ -74,6 +77,7 @@ module.exports = function(Posts) {
|
|
|
|
|
topics.updateTeaser(postData.tid, next);
|
|
|
|
|
}
|
|
|
|
|
], function(err) {
|
|
|
|
|
plugins.fireHook('action:post.restore', _.clone(postData));
|
|
|
|
|
next(err, postData);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
@ -99,12 +103,18 @@ module.exports = function(Posts) {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Posts.purge = function(pid, callback) {
|
|
|
|
|
Posts.exists(pid, function(err, exists) {
|
|
|
|
|
if (err || !exists) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
Posts.purge = function(pid, uid, callback) {
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
Posts.exists(pid, next);
|
|
|
|
|
},
|
|
|
|
|
function (exists, next) {
|
|
|
|
|
if (!exists) {
|
|
|
|
|
return callback();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
plugins.fireHook('filter:post.purge', {pid: pid, uid: uid}, next);
|
|
|
|
|
},
|
|
|
|
|
function (data, next) {
|
|
|
|
|
async.parallel([
|
|
|
|
|
function (next) {
|
|
|
|
|
deletePostFromTopicAndUser(pid, next);
|
|
|
|
@ -126,13 +136,13 @@ module.exports = function(Posts) {
|
|
|
|
|
}
|
|
|
|
|
], function(err) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
return next(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
plugins.fireHook('action:post.purge', pid);
|
|
|
|
|
db.delete('post:' + pid, callback);
|
|
|
|
|
});
|
|
|
|
|
db.delete('post:' + pid, next);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
], callback);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function deletePostFromTopicAndUser(pid, callback) {
|
|
|
|
|