v1.18.x
barisusakli
parent 18bc7713ef
commit 46c8101c5c

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

@ -1,8 +1,8 @@
'use strict'; 'use strict';
var cache = require('./cache'), var cache = require('./cache');
plugins = require('../plugins'); var plugins = require('../plugins');
module.exports = function(Posts) { module.exports = function(Posts) {

@ -1,9 +1,9 @@
'use strict'; 'use strict';
var async = require('async'), var async = require('async');
privileges = require('../privileges'), var privileges = require('../privileges');
cache = require('./cache'); var cache = require('./cache');
module.exports = function(Posts) { module.exports = function(Posts) {
Posts.tools = {}; Posts.tools = {};
@ -40,25 +40,20 @@ module.exports = function(Posts) {
if (!canEdit) { if (!canEdit) {
return next(new Error('[[error:no-privileges]]')); return next(new Error('[[error:no-privileges]]'));
} }
next();
}
], function (err) {
if (err) {
return callback(err);
}
if (isDelete) { if (isDelete) {
cache.del(pid); cache.del(pid);
Posts.delete(pid, callback); Posts.delete(pid, uid, next);
} else { } else {
Posts.restore(pid, function(err, postData) { Posts.restore(pid, uid, function(err, postData) {
if (err) { if (err) {
return callback(err); return next(err);
} }
Posts.parsePost(postData, callback); Posts.parsePost(postData, next);
}); });
} }
}); }
], callback);
} }
Posts.tools.purge = function(uid, pid, callback) { Posts.tools.purge = function(uid, pid, callback) {
@ -71,7 +66,7 @@ module.exports = function(Posts) {
return next(new Error('[[error:no-privileges]]')); return next(new Error('[[error:no-privileges]]'));
} }
cache.del(pid); cache.del(pid);
Posts.purge(pid, next); Posts.purge(pid, uid, next);
} }
], callback); ], callback);
}; };

Loading…
Cancel
Save