From 8af64ba98415447ac9fa31f105af216ee0ef3799 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Thu, 17 Sep 2015 13:37:04 -0400 Subject: [PATCH] closes #3626 --- src/categories/delete.js | 5 ++--- src/controllers/categories.js | 5 +---- src/controllers/topics.js | 5 +++++ src/threadTools.js | 20 ++++++-------------- src/topics/delete.js | 24 +++++++++++++++++++++++- 5 files changed, 37 insertions(+), 22 deletions(-) diff --git a/src/categories/delete.js b/src/categories/delete.js index 7bfe03a005..431b3f8b40 100644 --- a/src/categories/delete.js +++ b/src/categories/delete.js @@ -4,15 +4,14 @@ var async = require('async'), db = require('../database'), batch = require('../batch'), plugins = require('../plugins'), - threadTools = require('../threadTools'); - + topics = require('../topics'); module.exports = function(Categories) { Categories.purge = function(cid, callback) { batch.processSortedSet('cid:' + cid + ':tids', function(tids, next) { async.eachLimit(tids, 10, function(tid, next) { - threadTools.purge(tid, 0, next); + topics.purgePostsAndTopic(tid, next); }, next); }, {alwaysStartAt: 0}, function(err) { if (err) { diff --git a/src/controllers/categories.js b/src/controllers/categories.js index 438e970c99..32553088a1 100644 --- a/src/controllers/categories.js +++ b/src/controllers/categories.js @@ -91,9 +91,6 @@ categoriesController.get = function(req, res, callback) { async.waterfall([ function(next) { async.parallel({ - exists: function(next) { - categories.exists(cid, next); - }, categoryData: function(next) { categories.getCategoryFields(cid, ['slug', 'disabled', 'topic_count'], next); }, @@ -108,7 +105,7 @@ categoriesController.get = function(req, res, callback) { function(results, next) { userPrivileges = results.privileges; - if (!results.exists || (results.categoryData && parseInt(results.categoryData.disabled, 10) === 1)) { + if (!results.categoryData.slug || (results.categoryData && parseInt(results.categoryData.disabled, 10) === 1)) { return callback(); } diff --git a/src/controllers/topics.js b/src/controllers/topics.js index 93ab192823..75f8a92b9d 100644 --- a/src/controllers/topics.js +++ b/src/controllers/topics.js @@ -40,6 +40,11 @@ topicsController.get = function(req, res, callback) { }, next); }, function (results, next) { + + if (!results.topic.slug) { + return callback(); + } + userPrivileges = results.privileges; if (!userPrivileges.read || (parseInt(results.topic.deleted, 10) && !userPrivileges.view_deleted)) { diff --git a/src/threadTools.js b/src/threadTools.js index 9ae4e3d921..37a2b1b721 100644 --- a/src/threadTools.js +++ b/src/threadTools.js @@ -66,7 +66,7 @@ var async = require('async'), } ThreadTools.purge = function(tid, uid, callback) { - var topic; + var cid; async.waterfall([ function(next) { topics.exists(tid, next); @@ -82,23 +82,15 @@ var async = require('async'), return next(new Error('[[error:no-privileges]]')); } - topics.getTopicFields(tid, ['mainPid', 'cid'], next); + topics.getTopicField(tid, 'cid', next); }, - function (_topic, next) { - topic = _topic; + function (_cid, next) { + cid = _cid; - batch.processSortedSet('tid:' + tid + ':posts', function(pids, next) { - async.eachLimit(pids, 10, posts.purge, next); - }, {alwaysStartAt: 0}, next); - }, - function (next) { - posts.purge(topic.mainPid, next); - }, - function (next) { - topics.purge(tid, next); + topics.purgePostsAndTopic(tid, next); }, function (next) { - next(null, {tid: tid, cid: topic.cid, uid: uid}); + next(null, {tid: tid, cid: cid, uid: uid}); } ], callback); }; diff --git a/src/topics/delete.js b/src/topics/delete.js index 30c926e1e5..e194d9cd23 100644 --- a/src/topics/delete.js +++ b/src/topics/delete.js @@ -5,7 +5,8 @@ var async = require('async'), user = require('../user'), posts = require('../posts'), - plugins = require('../plugins'); + plugins = require('../plugins'), + batch = require('../batch'); module.exports = function(Topics) { @@ -80,6 +81,27 @@ module.exports = function(Topics) { }); }; + Topics.purgePostsAndTopic = function(tid, callback) { + var mainPid; + async.waterfall([ + function (next) { + Topics.getTopicField(tid, 'mainPid', next); + }, + function (_mainPid, next) { + mainPid = _mainPid; + batch.processSortedSet('tid:' + tid + ':posts', function(pids, next) { + async.eachLimit(pids, 10, posts.purge, next); + }, {alwaysStartAt: 0}, next); + }, + function (next) { + posts.purge(mainPid, next); + }, + function (next) { + Topics.purge(tid, next); + } + ], callback); + }; + Topics.purge = function(tid, callback) { async.parallel([ function(next) {