2011-11-27 06:32:31 +01:00
|
|
|
/*
|
2019-02-08 23:20:57 +01:00
|
|
|
* This is a debug tool. It helps to extract all datas of a pad and move it from
|
|
|
|
* a productive environment and to a develop environment to reproduce bugs
|
|
|
|
* there. It outputs a dirtydb file
|
|
|
|
*/
|
2011-11-27 06:32:31 +01:00
|
|
|
|
2019-02-08 23:20:57 +01:00
|
|
|
if (process.argv.length != 3) {
|
2011-11-27 06:32:31 +01:00
|
|
|
console.error("Use: node extractPadData.js $PADID");
|
|
|
|
process.exit(1);
|
|
|
|
}
|
2019-02-08 23:20:57 +01:00
|
|
|
|
|
|
|
// get the padID
|
2019-01-27 00:52:02 +01:00
|
|
|
let padId = process.argv[2];
|
2011-11-27 06:32:31 +01:00
|
|
|
|
2019-01-27 00:52:02 +01:00
|
|
|
let npm = require('../src/node_modules/npm');
|
2011-11-27 06:32:31 +01:00
|
|
|
|
2019-01-27 00:52:02 +01:00
|
|
|
npm.load({}, async function(er) {
|
|
|
|
if (er) {
|
|
|
|
console.error("Could not load NPM: " + er)
|
|
|
|
process.exit(1);
|
|
|
|
}
|
2013-01-06 19:25:32 +01:00
|
|
|
|
2019-01-27 00:52:02 +01:00
|
|
|
try {
|
|
|
|
// initialize database
|
|
|
|
let settings = require('../src/node/utils/Settings');
|
|
|
|
let db = require('../src/node/db/DB');
|
|
|
|
await db.init();
|
2019-02-08 23:20:57 +01:00
|
|
|
|
2019-01-27 00:52:02 +01:00
|
|
|
// load extra modules
|
|
|
|
let dirtyDB = require('../src/node_modules/dirty');
|
|
|
|
let padManager = require('../src/node/db/PadManager');
|
|
|
|
let util = require('util');
|
2019-02-08 23:20:57 +01:00
|
|
|
|
2019-01-27 00:52:02 +01:00
|
|
|
// initialize output database
|
|
|
|
let dirty = dirtyDB(padId + '.db');
|
2019-02-08 23:20:57 +01:00
|
|
|
|
2019-01-27 00:52:02 +01:00
|
|
|
// Promise wrapped get and set function
|
|
|
|
let wrapped = db.db.db.wrappedDB;
|
|
|
|
let get = util.promisify(wrapped.get.bind(wrapped));
|
|
|
|
let set = util.promisify(dirty.set.bind(dirty));
|
2019-02-08 23:20:57 +01:00
|
|
|
|
2019-01-27 00:52:02 +01:00
|
|
|
// array in which required key values will be accumulated
|
|
|
|
let neededDBValues = ['pad:' + padId];
|
|
|
|
|
|
|
|
// get the actual pad object
|
|
|
|
let pad = await padManager.getPad(padId);
|
2019-02-08 23:20:57 +01:00
|
|
|
|
|
|
|
// add all authors
|
2019-01-27 00:52:02 +01:00
|
|
|
neededDBValues.push(...pad.getAllAuthors().map(author => 'globalAuthor:' + author));
|
2019-02-08 23:20:57 +01:00
|
|
|
|
|
|
|
// add all revisions
|
2019-01-27 00:52:02 +01:00
|
|
|
for (let rev = 0; rev <= pad.head; ++rev) {
|
|
|
|
neededDBValues.push('pad:' + padId + ':revs:' + rev);
|
2011-11-27 06:32:31 +01:00
|
|
|
}
|
2019-02-08 23:20:57 +01:00
|
|
|
|
2019-01-27 00:52:02 +01:00
|
|
|
// add all chat values
|
|
|
|
for (let chat = 0; chat <= pad.chatHead; ++chat) {
|
|
|
|
neededDBValues.push('pad:' + padId + ':chat:' + chat);
|
2011-11-27 06:32:31 +01:00
|
|
|
}
|
2013-02-18 21:38:32 +01:00
|
|
|
|
2019-01-27 00:52:02 +01:00
|
|
|
for (let dbkey of neededDBValues) {
|
|
|
|
let dbvalue = await get(dbkey);
|
|
|
|
if (dbvalue && typeof dbvalue !== 'object') {
|
|
|
|
dbvalue = JSON.parse(dbvalue);
|
|
|
|
}
|
|
|
|
await set(dbkey, dbvalue);
|
|
|
|
}
|
2019-02-08 23:20:57 +01:00
|
|
|
|
2019-01-27 00:52:02 +01:00
|
|
|
console.log('finished');
|
|
|
|
process.exit(0);
|
|
|
|
} catch (er) {
|
|
|
|
console.error(er);
|
|
|
|
process.exit(1);
|
2011-11-27 06:32:31 +01:00
|
|
|
}
|
|
|
|
});
|