2011-11-27 05:32:31 +00:00
|
|
|
/*
|
2019-02-08 22:20:57 +00: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 05:32:31 +00:00
|
|
|
|
2019-02-08 22:20:57 +00:00
|
|
|
if (process.argv.length != 3) {
|
2020-11-23 18:21:51 +00:00
|
|
|
console.error('Use: node extractPadData.js $PADID');
|
2011-11-27 05:32:31 +00:00
|
|
|
process.exit(1);
|
|
|
|
}
|
2019-02-08 22:20:57 +00:00
|
|
|
|
|
|
|
// get the padID
|
2020-11-23 18:21:51 +00:00
|
|
|
const padId = process.argv[2];
|
2011-11-27 05:32:31 +00:00
|
|
|
|
2020-11-23 18:21:51 +00:00
|
|
|
const npm = require('../src/node_modules/npm');
|
2011-11-27 05:32:31 +00:00
|
|
|
|
2020-11-23 18:21:51 +00:00
|
|
|
npm.load({}, async (er) => {
|
2019-01-26 23:52:02 +00:00
|
|
|
if (er) {
|
2020-11-23 18:21:51 +00:00
|
|
|
console.error(`Could not load NPM: ${er}`);
|
2019-01-26 23:52:02 +00:00
|
|
|
process.exit(1);
|
|
|
|
}
|
2013-01-06 18:25:32 +00:00
|
|
|
|
2019-01-26 23:52:02 +00:00
|
|
|
try {
|
|
|
|
// initialize database
|
2020-11-23 18:21:51 +00:00
|
|
|
const settings = require('../src/node/utils/Settings');
|
|
|
|
const db = require('../src/node/db/DB');
|
2019-01-26 23:52:02 +00:00
|
|
|
await db.init();
|
2019-02-08 22:20:57 +00:00
|
|
|
|
2019-01-26 23:52:02 +00:00
|
|
|
// load extra modules
|
2020-11-23 18:21:51 +00:00
|
|
|
const dirtyDB = require('../src/node_modules/dirty');
|
|
|
|
const padManager = require('../src/node/db/PadManager');
|
|
|
|
const util = require('util');
|
2019-02-08 22:20:57 +00:00
|
|
|
|
2019-01-26 23:52:02 +00:00
|
|
|
// initialize output database
|
2020-11-23 18:21:51 +00:00
|
|
|
const dirty = dirtyDB(`${padId}.db`);
|
2019-02-08 22:20:57 +00:00
|
|
|
|
2019-01-26 23:52:02 +00:00
|
|
|
// Promise wrapped get and set function
|
2020-11-23 18:21:51 +00:00
|
|
|
const wrapped = db.db.db.wrappedDB;
|
|
|
|
const get = util.promisify(wrapped.get.bind(wrapped));
|
|
|
|
const set = util.promisify(dirty.set.bind(dirty));
|
2019-02-08 22:20:57 +00:00
|
|
|
|
2019-01-26 23:52:02 +00:00
|
|
|
// array in which required key values will be accumulated
|
2020-11-23 18:21:51 +00:00
|
|
|
const neededDBValues = [`pad:${padId}`];
|
2019-01-26 23:52:02 +00:00
|
|
|
|
|
|
|
// get the actual pad object
|
2020-11-23 18:21:51 +00:00
|
|
|
const pad = await padManager.getPad(padId);
|
2019-02-08 22:20:57 +00:00
|
|
|
|
|
|
|
// add all authors
|
2020-11-23 18:21:51 +00:00
|
|
|
neededDBValues.push(...pad.getAllAuthors().map((author) => `globalAuthor:${author}`));
|
2019-02-08 22:20:57 +00:00
|
|
|
|
|
|
|
// add all revisions
|
2019-01-26 23:52:02 +00:00
|
|
|
for (let rev = 0; rev <= pad.head; ++rev) {
|
2020-11-23 18:21:51 +00:00
|
|
|
neededDBValues.push(`pad:${padId}:revs:${rev}`);
|
2011-11-27 05:32:31 +00:00
|
|
|
}
|
2019-02-08 22:20:57 +00:00
|
|
|
|
2019-01-26 23:52:02 +00:00
|
|
|
// add all chat values
|
|
|
|
for (let chat = 0; chat <= pad.chatHead; ++chat) {
|
2020-11-23 18:21:51 +00:00
|
|
|
neededDBValues.push(`pad:${padId}:chat:${chat}`);
|
2011-11-27 05:32:31 +00:00
|
|
|
}
|
2013-02-18 20:38:32 +00:00
|
|
|
|
2020-11-23 18:21:51 +00:00
|
|
|
for (const dbkey of neededDBValues) {
|
2019-01-26 23:52:02 +00:00
|
|
|
let dbvalue = await get(dbkey);
|
|
|
|
if (dbvalue && typeof dbvalue !== 'object') {
|
|
|
|
dbvalue = JSON.parse(dbvalue);
|
|
|
|
}
|
|
|
|
await set(dbkey, dbvalue);
|
|
|
|
}
|
2019-02-08 22:20:57 +00:00
|
|
|
|
2019-01-26 23:52:02 +00:00
|
|
|
console.log('finished');
|
|
|
|
process.exit(0);
|
|
|
|
} catch (er) {
|
|
|
|
console.error(er);
|
|
|
|
process.exit(1);
|
2011-11-27 05:32:31 +00:00
|
|
|
}
|
|
|
|
});
|