var startTime = Date.now(); var fs = require("fs"); var ueberDB = require("../src/node_modules/ueberDB"); var mysql = require("../src/node_modules/ueberDB/node_modules/mysql"); var async = require("../src/node_modules/async"); var Changeset = require("ep_etherpad-lite/static/js/Changeset"); var randomString = require('ep_etherpad-lite/static/js/pad_utils').randomString; var AttributePool = require("ep_etherpad-lite/static/js/AttributePool"); var settingsFile = process.argv[2]; var sqlOutputFile = process.argv[3]; //stop if the settings file is not set if(!settingsFile || !sqlOutputFile) { console.error("Use: node convert.js $SETTINGSFILE $SQLOUTPUT"); process.exit(1); } log("read settings file..."); //read the settings file and parse the json var settings = JSON.parse(fs.readFileSync(settingsFile, "utf8")); log("done"); log("open output file..."); var sqlOutput = fs.openSync(sqlOutputFile, "w"); var sql = "SET CHARACTER SET UTF8;\n" + "CREATE TABLE IF NOT EXISTS `store` ( \n" + "`key` VARCHAR( 100 ) NOT NULL , \n" + "`value` LONGTEXT NOT NULL , \n" + "PRIMARY KEY ( `key` ) \n" + ") ENGINE = INNODB;\n" + "START TRANSACTION;\n\n"; fs.writeSync(sqlOutput, sql); log("done"); var etherpadDB = mysql.createConnection({ host : settings.etherpadDB.host, user : settings.etherpadDB.user, password : settings.etherpadDB.password, database : settings.etherpadDB.database, port : settings.etherpadDB.port }); //get the timestamp once var timestamp = Date.now(); var padIDs; async.series([ //get all padids out of the database... function(callback) { log("get all padIds out of the database..."); etherpadDB.query("SELECT ID FROM PAD_META", [], function(err, _padIDs) { padIDs = _padIDs; callback(err); }); }, function(callback) { log("done"); //create a queue with a concurrency 100 var queue = async.queue(function (padId, callback) { convertPad(padId, function(err) { incrementPadStats(); callback(err); }); }, 100); //set the step callback as the queue callback queue.drain = callback; //add the padids to the worker queue for(var i=0,length=padIDs.length;i