mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-14 09:55:47 +01:00
closes #1281
category purge, deletes all topics and posts in the category
This commit is contained in:
@@ -216,6 +216,23 @@ define('forum/admin/categories', ['uploader'], function(uploader) {
|
||||
$('[data-name="bgColor"], [data-name="color"]').each(enableColorPicker);
|
||||
|
||||
$('.admin-categories').on('click', '.save', save);
|
||||
$('.admin-categories').on('click', '.purge', function() {
|
||||
var categoryRow = $(this).parents('li[data-cid]');
|
||||
var cid = categoryRow.attr('data-cid');
|
||||
|
||||
bootbox.confirm('Do you really want to purge this category "' + categoryRow.find('#cid-' + cid + '-name').val() + '"?<br/><strong class="text-danger">Warning!</strong> All topics and posts in this category will be purged!', function(confirm) {
|
||||
if (!confirm) {
|
||||
return;
|
||||
}
|
||||
socket.emit('admin.categories.purge', cid, function(err) {
|
||||
if (err) {
|
||||
return app.alertError(err.message);
|
||||
}
|
||||
app.alertSuccess('Category purged!');
|
||||
categoryRow.remove();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Permissions modal
|
||||
$('.admin-categories').on('click', '.permissions', function() {
|
||||
|
||||
@@ -19,6 +19,7 @@ var db = require('./database'),
|
||||
|
||||
(function(Categories) {
|
||||
|
||||
require('./categories/delete')(Categories);
|
||||
require('./categories/activeusers')(Categories);
|
||||
require('./categories/recentreplies')(Categories);
|
||||
require('./categories/update')(Categories);
|
||||
|
||||
45
src/categories/delete.js
Normal file
45
src/categories/delete.js
Normal 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);
|
||||
}
|
||||
};
|
||||
@@ -1,10 +1,11 @@
|
||||
"use strict";
|
||||
|
||||
var groups = require('../../groups'),
|
||||
var async = require('async'),
|
||||
|
||||
groups = require('../../groups'),
|
||||
user = require('../../user'),
|
||||
categories = require('../../categories'),
|
||||
privileges = require('../../privileges'),
|
||||
async = require('async'),
|
||||
Categories = {};
|
||||
|
||||
Categories.create = function(socket, data, callback) {
|
||||
@@ -15,6 +16,10 @@ Categories.create = function(socket, data, callback) {
|
||||
categories.create(data, callback);
|
||||
};
|
||||
|
||||
Categories.purge = function(socket, cid, callback) {
|
||||
categories.purge(cid, callback);
|
||||
};
|
||||
|
||||
Categories.update = function(socket, data, callback) {
|
||||
if(!data) {
|
||||
return callback(new Error('[[error:invalid-data]]'));
|
||||
|
||||
Reference in New Issue
Block a user