category purge, deletes all topics and posts in the category
This commit is contained in:
barisusakli
2014-06-10 17:48:48 -04:00
parent 311a7ad5b9
commit 4fa79dc821
4 changed files with 70 additions and 2 deletions

45
src/categories/delete.js Normal file
View File

@@ -0,0 +1,45 @@
'use strict';
var async = require('async'),
db = require('../database'),
threadTools = require('../threadTools');
module.exports = function(Categories) {
Categories.purge = function(cid, callback) {
Categories.getTopicIds(cid, 0, -1, function(err, tids) {
if (err) {
return callback(err);
}
async.each(tids, function(tid, next) {
threadTools.purge(tid, 0, next);
}, function(err) {
if (err) {
return callback(err);
}
purgeCategory(cid, callback);
});
});
};
function purgeCategory(cid, callback) {
async.parallel([
function(next) {
db.sortedSetRemove('categories:cid', cid, next);
},
function(next) {
db.delete('categories:' + cid + ':tid', next);
},
function(next) {
db.delete('categories:recent_posts:cid:' + cid, next);
},
function(next) {
db.delete('category:' + cid, next);
}
], callback);
}
};