2014-05-19 16:18:01 +00:00
|
|
|
/*
|
2019-01-30 10:47:50 +00:00
|
|
|
* This is a repair tool. It extracts all datas of a pad, removes and inserts them again.
|
|
|
|
*/
|
2014-05-19 16:18:01 +00:00
|
|
|
|
|
|
|
console.warn("WARNING: This script must not be used while etherpad is running!");
|
|
|
|
|
2019-01-30 10:47:50 +00:00
|
|
|
if (process.argv.length != 3) {
|
2014-05-19 16:18:01 +00:00
|
|
|
console.error("Use: node bin/repairPad.js $PADID");
|
|
|
|
process.exit(1);
|
|
|
|
}
|
2019-01-30 10:47:50 +00:00
|
|
|
|
|
|
|
// get the padID
|
2014-05-19 16:18:01 +00:00
|
|
|
var padId = process.argv[2];
|
|
|
|
|
2019-01-30 10:47:50 +00:00
|
|
|
let npm = require("../src/node_modules/npm");
|
|
|
|
npm.load({}, async function(er) {
|
|
|
|
if (er) {
|
|
|
|
console.error("Could not load NPM: " + er)
|
|
|
|
process.exit(1);
|
|
|
|
}
|
2014-05-19 16:18:01 +00:00
|
|
|
|
2019-01-30 10:47:50 +00:00
|
|
|
try {
|
|
|
|
// intialize database
|
|
|
|
let settings = require('../src/node/utils/Settings');
|
|
|
|
let db = require('../src/node/db/DB');
|
|
|
|
await db.init();
|
2014-05-19 16:18:01 +00:00
|
|
|
|
2019-01-30 10:47:50 +00:00
|
|
|
// get the pad
|
|
|
|
let padManager = require('../src/node/db/PadManager');
|
|
|
|
let pad = await padManager.getPad(padId);
|
|
|
|
|
|
|
|
// accumulate the required keys
|
|
|
|
let neededDBValues = ["pad:" + padId];
|
|
|
|
|
|
|
|
// add all authors
|
|
|
|
neededDBValues.push(...pad.getAllAuthors().map(author => "globalAuthor:"));
|
|
|
|
|
|
|
|
// add all revisions
|
|
|
|
for (let rev = 0; rev <= pad.head; ++rev) {
|
|
|
|
neededDBValues.push("pad:" + padId + ":revs:" + rev);
|
2014-05-19 16:18:01 +00:00
|
|
|
}
|
2019-01-30 10:47:50 +00:00
|
|
|
|
|
|
|
// add all chat values
|
|
|
|
for (let chat = 0; chat <= pad.chatHead; ++chat) {
|
|
|
|
neededDBValues.push("pad:" + padId + ":chat:" + chat);
|
2014-05-19 16:18:01 +00:00
|
|
|
}
|
2019-01-30 10:47:50 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// NB: this script doesn't actually does what's documented
|
|
|
|
// since the `value` fields in the following `.forEach`
|
|
|
|
// block are just the array index numbers
|
|
|
|
//
|
|
|
|
// the script therefore craps out now before it can do
|
|
|
|
// any damage.
|
|
|
|
//
|
|
|
|
// See gitlab issue #3545
|
|
|
|
//
|
|
|
|
console.info("aborting [gitlab #3545]");
|
|
|
|
process.exit(1);
|
|
|
|
|
|
|
|
// now fetch and reinsert every key
|
2014-05-19 16:18:01 +00:00
|
|
|
neededDBValues.forEach(function(key, value) {
|
2019-01-30 10:47:50 +00:00
|
|
|
console.log("Key: " + key+ ", value: " + value);
|
2014-05-19 16:18:01 +00:00
|
|
|
db.remove(key);
|
|
|
|
db.set(key, value);
|
|
|
|
});
|
2019-01-30 10:47:50 +00:00
|
|
|
|
2014-05-19 16:18:01 +00:00
|
|
|
console.info("finished");
|
2019-01-30 10:47:50 +00:00
|
|
|
process.exit(0);
|
|
|
|
|
|
|
|
} catch (er) {
|
|
|
|
if (er.name === "apierror") {
|
|
|
|
console.error(er);
|
|
|
|
} else {
|
|
|
|
console.trace(er);
|
|
|
|
}
|
2014-05-19 16:18:01 +00:00
|
|
|
}
|
|
|
|
});
|