mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-28 17:46:16 +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,6 +102,11 @@ module.exports = function(Posts) {
|
||||
}
|
||||
|
||||
Posts.purge = function(pid, callback) {
|
||||
Posts.exists(pid, function(err, exists) {
|
||||
if (err || !exists) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
async.parallel([
|
||||
function(next) {
|
||||
deletePostFromTopicAndUser(pid, next);
|
||||
@@ -126,6 +131,7 @@ module.exports = function(Posts) {
|
||||
plugins.fireHook('action:post.delete', pid);
|
||||
db.delete('post:' + pid, callback);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
function deletePostFromTopicAndUser(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,6 +72,11 @@ var winston = require('winston'),
|
||||
}
|
||||
|
||||
ThreadTools.purge = function(tid, uid, callback) {
|
||||
ThreadTools.exists(tid, function(err, exists) {
|
||||
if (err || !exists) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
batch.processSortedSet('tid:' + tid + ':posts', function(pids, next) {
|
||||
async.eachLimit(pids, 10, posts.purge, next);
|
||||
}, {alwaysStartAt: 0}, function(err) {
|
||||
@@ -91,6 +96,7 @@ var winston = require('winston'),
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
ThreadTools.lock = function(tid, uid, callback) {
|
||||
|
||||
Reference in New Issue
Block a user