mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-29 01:56:12 +01:00
some checks for purge
This commit is contained in:
@@ -102,6 +102,10 @@ var async = require('async'),
|
||||
], callback);
|
||||
};
|
||||
|
||||
Posts.exists = function(pid, callback) {
|
||||
db.isSortedSetMember('posts:pid', pid, callback);
|
||||
};
|
||||
|
||||
Posts.getPostsByTid = function(tid, set, start, end, uid, reverse, callback) {
|
||||
Posts.getPidsFromSet(set, start, end, reverse, function(err, pids) {
|
||||
if(err) {
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -227,7 +227,7 @@ function deleteOrRestore(command, socket, data, callback) {
|
||||
}
|
||||
|
||||
SocketPosts.purge = function(socket, data, callback) {
|
||||
if(!data) {
|
||||
if(!data || !parseInt(data.pid, 10)) {
|
||||
return callback(new Error('[[error:invalid-data]]'));
|
||||
}
|
||||
postTools.purge(socket.uid, data.pid, function(err) {
|
||||
|
||||
@@ -240,6 +240,9 @@ SocketTopics.unpin = function(socket, data, callback) {
|
||||
};
|
||||
|
||||
function doTopicAction(action, socket, data, callback) {
|
||||
if (!socket.uid) {
|
||||
return;
|
||||
}
|
||||
if(!data || !Array.isArray(data.tids) || !data.cid) {
|
||||
return callback(new Error('[[error:invalid-tid]]'));
|
||||
}
|
||||
|
||||
@@ -72,22 +72,28 @@ var winston = require('winston'),
|
||||
}
|
||||
|
||||
ThreadTools.purge = function(tid, uid, callback) {
|
||||
batch.processSortedSet('tid:' + tid + ':posts', function(pids, next) {
|
||||
async.eachLimit(pids, 10, posts.purge, next);
|
||||
}, {alwaysStartAt: 0}, function(err) {
|
||||
if (err) {
|
||||
ThreadTools.exists(tid, function(err, exists) {
|
||||
if (err || !exists) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
topics.getTopicField(tid, 'mainPid', function(err, mainPid) {
|
||||
batch.processSortedSet('tid:' + tid + ':posts', function(pids, next) {
|
||||
async.eachLimit(pids, 10, posts.purge, next);
|
||||
}, {alwaysStartAt: 0}, function(err) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
posts.purge(mainPid, function(err) {
|
||||
|
||||
topics.getTopicField(tid, 'mainPid', function(err, mainPid) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
topics.purge(tid, callback);
|
||||
posts.purge(mainPid, function(err) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
topics.purge(tid, callback);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user