checkPadDeltas: version by JohnMcLear

From https://github.com/ether/etherpad-lite/pull/3717#issuecomment-602179127

> Afaik I used async / await that's pretty much all, I think I had to do some
> polish because something was broken, remember stuff like pad.getPadAuthors was
> b0rked in 1.7 or so
pull/3766/head
John McLear 2020-03-15 20:33:33 +00:00 committed by muxator
parent 90f9b8a3bd
commit 14ae2ee950
1 changed files with 67 additions and 101 deletions

View File

@ -1,77 +1,44 @@
/*
This is a debug tool. It checks all revisions for data corruption
* This is a debug tool. It checks all revisions for data corruption
*/
if(process.argv.length != 3)
{
console.error("Use: node bin/checkPad.js $PADID");
if (process.argv.length != 3) {
console.error("Use: node bin/checkPadDeltas.js $PADID");
process.exit(1);
}
// get the padID
var padId = process.argv[2];
const padId = process.argv[2];
//initalize the variables
var db, settings, padManager;
var npm = require("ep_etherpad-lite/node_modules/npm");
var async = require("ep_etherpad-lite/node_modules/async");
var Changeset = require("ep_etherpad-lite/static/js/Changeset");
// external dependencies
// load and initialize NPM;
var expect = require('expect.js')
var diff = require('diff')
var async = require('async')
let npm = require('../src/node_modules/npm');
var async = require("ep_etherpad-lite/node_modules/async");
var Changeset = require("ep_etherpad-lite/static/js/Changeset");
npm.load({}, async function() {
try {
// initialize database
let settings = require('../src/node/utils/Settings');
let db = require('../src/node/db/DB');
await db.init();
async.series([
//load npm
function(callback) {
npm.load({}, function(er) {
callback(er);
})
},
// load modules
function(callback) {
settings = require('ep_etherpad-lite/node/utils/Settings');
db = require('ep_etherpad-lite/node/db/DB');
let Changeset = require('ep_etherpad-lite/static/js/Changeset');
let padManager = require('../src/node/db/PadManager');
//intallize the database
db.init(callback);
},
//get the pad
function (callback)
{
padManager = require('ep_etherpad-lite/node/db/PadManager');
padManager.doesPadExists(padId, function(err, exists)
{
if(!exists)
{
let exists = await padManager.doesPadExists(padId);
if (!exists) {
console.error("Pad does not exist");
process.exit(1);
}
padManager.getPad(padId, function(err, _pad)
{
pad = _pad;
callback(err);
});
});
},
function (callback)
{
//check if the pad has a pool
if(pad.pool === undefined )
{
console.error("Attribute pool is missing");
process.exit(1);
}
//check if the pad has atext
if(pad.atext === undefined )
{
console.error("AText is missing");
process.exit(1);
}
// get the pad
let pad = await padManager.getPad(padId);
//create an array with key revisions
//key revisions always save the full pad atext
@ -142,13 +109,12 @@ async.series([
}
callback(er)
});
}
], function (err)
{
if(err) throw err;
else
{
console.log("finished");
process.exit(0);
} catch (e) {
console.trace(e);
process.exit(1);
}
});