Skip to content

Node.js based forum software built for the modern web

some checks for purge

barisusaklifcc42883ab59
diff --git a/src/posts.js b/src/posts.js
index 7eac14c3d0..f856e711f2 100644
--- a/src/posts.js
+++ b/src/posts.js
@@ -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) {
diff --git a/src/posts/delete.js b/src/posts/delete.js
index 821b23454f..e48dda467f 100644
--- a/src/posts/delete.js
+++ b/src/posts/delete.js
@@ -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);
+ });
});
};
diff --git a/src/socket.io/posts.js b/src/socket.io/posts.js
index b445a3eefe..e08e52808c 100644
--- a/src/socket.io/posts.js
+++ b/src/socket.io/posts.js
@@ -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) {
diff --git a/src/socket.io/topics.js b/src/socket.io/topics.js
index 0c367c5d91..80025e64bd 100644
--- a/src/socket.io/topics.js
+++ b/src/socket.io/topics.js
@@ -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]]'));
}
diff --git a/src/threadTools.js b/src/threadTools.js
index ef5763e540..1d192f7090 100644
--- a/src/threadTools.js
+++ b/src/threadTools.js
@@ -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);
+ });
});
});
});