diff --git a/public/src/forum/admin/categories.js b/public/src/forum/admin/categories.js
index 3c85a969d7..887ddabee7 100644
--- a/public/src/forum/admin/categories.js
+++ b/public/src/forum/admin/categories.js
@@ -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() + '"?
Warning! 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() {
diff --git a/src/categories.js b/src/categories.js
index 86b4f95ec8..10ff73f894 100644
--- a/src/categories.js
+++ b/src/categories.js
@@ -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);
diff --git a/src/categories/delete.js b/src/categories/delete.js
new file mode 100644
index 0000000000..8c4c0520f8
--- /dev/null
+++ b/src/categories/delete.js
@@ -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);
+ }
+};
\ No newline at end of file
diff --git a/src/socket.io/admin/categories.js b/src/socket.io/admin/categories.js
index 86e913af37..a17779cfae 100644
--- a/src/socket.io/admin/categories.js
+++ b/src/socket.io/admin/categories.js
@@ -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]]'));