mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-16 10:46:14 +01:00
when a category is deleted, set the children's parent to 0
This commit is contained in:
@@ -49,13 +49,30 @@ module.exports = function(Categories) {
|
|||||||
function removeFromParent(cid, callback) {
|
function removeFromParent(cid, callback) {
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function(next) {
|
function(next) {
|
||||||
|
async.parallel({
|
||||||
|
parentCid: function(next) {
|
||||||
Categories.getCategoryField(cid, 'parentCid', next);
|
Categories.getCategoryField(cid, 'parentCid', next);
|
||||||
},
|
},
|
||||||
function(parentCid, next) {
|
children: function(next) {
|
||||||
parentCid = parseInt(parentCid, 10) || 0;
|
db.getSortedSetRange('cid:' + cid + ':children', 0, -1, next);
|
||||||
db.sortedSetRemove('cid:' + parentCid + ':children', cid, next);
|
|
||||||
}
|
}
|
||||||
], callback);
|
}, next);
|
||||||
|
},
|
||||||
|
function(results, next) {
|
||||||
|
async.parallel([
|
||||||
|
function(next) {
|
||||||
|
results.parentCid = parseInt(results.parentCid, 10) || 0;
|
||||||
|
db.sortedSetRemove('cid:' + results.parentCid + ':children', cid, next);
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
|
async.each(results.children, function(cid, next) {
|
||||||
|
db.setObjectField('category:' + cid, 'parentCid', 0, next);
|
||||||
|
}, next);
|
||||||
|
}
|
||||||
|
], next);
|
||||||
|
}
|
||||||
|
], function(err, results) {
|
||||||
|
callback(err);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user