some checks for purge

This commit is contained in:
barisusakli
2014-10-31 22:04:09 -04:00
parent d43e8beb60
commit fcc42883ab
5 changed files with 47 additions and 28 deletions

View File

@@ -102,29 +102,35 @@ module.exports = function(Posts) {
}
Posts.purge = function(pid, callback) {
async.parallel([
function(next) {
deletePostFromTopicAndUser(pid, next);
},
function(next) {
deletePostFromCategoryRecentPosts(pid, next);
},
function(next) {
deletePostFromUsersFavourites(pid, next);
},
function(next) {
deletePostFromUsersVotes(pid, next);
},
function(next) {
db.sortedSetsRemove(['posts:pid', 'posts:flagged'], pid, next);
},
], function(err) {
if (err) {
Posts.exists(pid, function(err, exists) {
if (err || !exists) {
return callback(err);
}
plugins.fireHook('action:post.delete', pid);
db.delete('post:' + pid, callback);
async.parallel([
function(next) {
deletePostFromTopicAndUser(pid, next);
},
function(next) {
deletePostFromCategoryRecentPosts(pid, next);
},
function(next) {
deletePostFromUsersFavourites(pid, next);
},
function(next) {
deletePostFromUsersVotes(pid, next);
},
function(next) {
db.sortedSetsRemove(['posts:pid', 'posts:flagged'], pid, next);
},
], function(err) {
if (err) {
return callback(err);
}
plugins.fireHook('action:post.delete', pid);
db.delete('post:' + pid, callback);
});
});
};