v1.18.x
barisusakli 10 years ago
parent 8c2fdcc77c
commit 8af64ba984

@ -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) {

@ -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();
}

@ -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)) {

@ -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);
};

@ -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) {

Loading…
Cancel
Save