var startTime = new Date().getTime(); var fs = require("fs"); var ueberDB = require("ueberDB"); var mysql = require("mysql"); var async = require("async"); var Changeset = require("../node/utils/Changeset"); var randomString = require("../node/utils/randomstring"); var AttributePoolFactory = require("../node/utils/AttributePoolFactory"); 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"); //set setings for ep db var etherpadDB= new mysql.Client(); etherpadDB.host = settings.etherpadDB.host; etherpadDB.port = settings.etherpadDB.port; etherpadDB.database = settings.etherpadDB.database; etherpadDB.user = settings.etherpadDB.user; etherpadDB.password = settings.etherpadDB.password; //get the timestamp once var timestamp = new Date().getTime(); 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