diff options
author | Peter 'Pita' Martischka <petermartischka@googlemail.com> | 2011-08-16 20:02:30 +0100 |
---|---|---|
committer | Peter 'Pita' Martischka <petermartischka@googlemail.com> | 2011-08-16 20:02:30 +0100 |
commit | d2c502e2bef4257d75d95765a6eb6e42b1c05f93 (patch) | |
tree | 39b1298d6e9afc3ed86505921e5c63198a24e4a5 /node/db/Pad.js | |
parent | 783c192726cf8998a445849e110839eb51cd3be4 (diff) | |
download | etherpad-lite-d2c502e2bef4257d75d95765a6eb6e42b1c05f93.zip |
added deletePad API function
Diffstat (limited to 'node/db/Pad.js')
-rw-r--r-- | node/db/Pad.js | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/node/db/Pad.js b/node/db/Pad.js index 3511728f..c36361c7 100644 --- a/node/db/Pad.js +++ b/node/db/Pad.js @@ -8,6 +8,9 @@ var db = require("./DB").db; var async = require("async"); var settings = require('../utils/Settings'); var authorManager = require("./AuthorManager"); +var padManager = require("./PadManager"); +var padMessageHandler = require("../handler/PadMessageHandler"); +var readOnlyManager = require("./ReadOnlyManager"); var crypto = require("crypto"); /** @@ -382,6 +385,97 @@ Class('Pad', { callback(null); }); }, + remove: function(callback) + { + var padID = this.id; + var _this = this; + + //kick everyone from this pad + padMessageHandler.kickSessionsFromPad(padID); + + async.series([ + //delete all relations + function(callback) + { + async.parallel([ + //is it a group pad? -> delete the entry of this pad in the group + function(callback) + { + //is it a group pad? + if(padID.indexOf("$")!=-1) + { + var groupID = padID.substring(0,padID.indexOf("$")); + + db.get("group:" + groupID, function (err, group) + { + if(err) {callback(err); return} + + //remove the pad entry + delete group.pads[padID]; + + //set the new value + db.set("group:" + groupID, group); + + callback(); + }); + } + //its no group pad, nothing to do here + else + { + callback(); + } + }, + //remove the readonly entries + function(callback) + { + readOnlyManager.getReadOnlyId(padID, function(err, readonlyID) + { + if(err) {callback(err); return} + + db.remove("pad2readonly:" + padID); + db.remove("readonly2pad:" + readonlyID); + + callback(); + }); + }, + //delete all chat messages + function(callback) + { + var chatHead = _this.chatHead; + + for(var i=0;i<=chatHead;i++) + { + db.remove("pad:"+padID+":chat:"+i); + } + + callback(); + }, + //delete all revisions + function(callback) + { + var revHead = _this.head; + + for(var i=0;i<=revHead;i++) + { + db.remove("pad:"+padID+":revs:"+i); + } + + callback(); + } + ], callback); + }, + //delete the pad entry and delete pad from padManager + function(callback) + { + db.remove("pad:"+padID); + padManager.unloadPad(padID); + callback(); + } + ], function(err) + { + callback(err); + }) + }, //set in db setPublicStatus: function(publicStatus) { |