some checks for purge

v1.18.x
barisusakli 10 years ago
parent d43e8beb60
commit fcc42883ab

@ -102,6 +102,10 @@ var async = require('async'),
], callback); ], callback);
}; };
Posts.exists = function(pid, callback) {
db.isSortedSetMember('posts:pid', pid, callback);
};
Posts.getPostsByTid = function(tid, set, start, end, uid, reverse, callback) { Posts.getPostsByTid = function(tid, set, start, end, uid, reverse, callback) {
Posts.getPidsFromSet(set, start, end, reverse, function(err, pids) { Posts.getPidsFromSet(set, start, end, reverse, function(err, pids) {
if(err) { if(err) {

@ -102,6 +102,11 @@ module.exports = function(Posts) {
} }
Posts.purge = function(pid, callback) { Posts.purge = function(pid, callback) {
Posts.exists(pid, function(err, exists) {
if (err || !exists) {
return callback(err);
}
async.parallel([ async.parallel([
function(next) { function(next) {
deletePostFromTopicAndUser(pid, next); deletePostFromTopicAndUser(pid, next);
@ -126,6 +131,7 @@ module.exports = function(Posts) {
plugins.fireHook('action:post.delete', pid); plugins.fireHook('action:post.delete', pid);
db.delete('post:' + pid, callback); db.delete('post:' + pid, callback);
}); });
});
}; };
function deletePostFromTopicAndUser(pid, callback) { function deletePostFromTopicAndUser(pid, callback) {

@ -227,7 +227,7 @@ function deleteOrRestore(command, socket, data, callback) {
} }
SocketPosts.purge = function(socket, data, callback) { SocketPosts.purge = function(socket, data, callback) {
if(!data) { if(!data || !parseInt(data.pid, 10)) {
return callback(new Error('[[error:invalid-data]]')); return callback(new Error('[[error:invalid-data]]'));
} }
postTools.purge(socket.uid, data.pid, function(err) { postTools.purge(socket.uid, data.pid, function(err) {

@ -240,6 +240,9 @@ SocketTopics.unpin = function(socket, data, callback) {
}; };
function doTopicAction(action, socket, data, callback) { function doTopicAction(action, socket, data, callback) {
if (!socket.uid) {
return;
}
if(!data || !Array.isArray(data.tids) || !data.cid) { if(!data || !Array.isArray(data.tids) || !data.cid) {
return callback(new Error('[[error:invalid-tid]]')); return callback(new Error('[[error:invalid-tid]]'));
} }

@ -72,6 +72,11 @@ var winston = require('winston'),
} }
ThreadTools.purge = function(tid, uid, callback) { 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) { batch.processSortedSet('tid:' + tid + ':posts', function(pids, next) {
async.eachLimit(pids, 10, posts.purge, next); async.eachLimit(pids, 10, posts.purge, next);
}, {alwaysStartAt: 0}, function(err) { }, {alwaysStartAt: 0}, function(err) {
@ -91,6 +96,7 @@ var winston = require('winston'),
}); });
}); });
}); });
});
}; };
ThreadTools.lock = function(tid, uid, callback) { ThreadTools.lock = function(tid, uid, callback) {

Loading…
Cancel
Save