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,29 +102,35 @@ module.exports = function(Posts) {
} }
Posts.purge = function(pid, callback) { Posts.purge = function(pid, callback) {
async.parallel([ Posts.exists(pid, function(err, exists) {
function(next) { if (err || !exists) {
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); return callback(err);
} }
plugins.fireHook('action:post.delete', pid); async.parallel([
db.delete('post:' + pid, callback); 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) { 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,22 +72,28 @@ var winston = require('winston'),
} }
ThreadTools.purge = function(tid, uid, callback) { ThreadTools.purge = function(tid, uid, callback) {
batch.processSortedSet('tid:' + tid + ':posts', function(pids, next) { ThreadTools.exists(tid, function(err, exists) {
async.eachLimit(pids, 10, posts.purge, next); if (err || !exists) {
}, {alwaysStartAt: 0}, function(err) {
if (err) {
return callback(err); 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) { if (err) {
return callback(err); return callback(err);
} }
posts.purge(mainPid, function(err) {
topics.getTopicField(tid, 'mainPid', function(err, mainPid) {
if (err) { if (err) {
return callback(err); return callback(err);
} }
topics.purge(tid, callback); posts.purge(mainPid, function(err) {
if (err) {
return callback(err);
}
topics.purge(tid, callback);
});
}); });
}); });
}); });

Loading…
Cancel
Save