From dd4c8dc3aaa3b556bce4ff519eb98dd8cb53333c Mon Sep 17 00:00:00 2001 From: Peter 'Pita' Martischka Date: Thu, 18 Aug 2011 20:58:56 +0100 Subject: [PATCH] added a convert script from old etherpad to etherpad lite, instructions will follow --- .gitignore | 1 + bin/convert.js | 449 ++++++++++++++++++++++++++++++ bin/convertSettings.json.template | 21 ++ 3 files changed, 471 insertions(+) create mode 100644 bin/convert.js create mode 100644 bin/convertSettings.json.template diff --git a/.gitignore b/.gitignore index 29835e6f..ab91434b 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ bin/abiword.exe bin/node.exe etherpad-lite-win.zip var/dirty.db +bin/convertSettings.json \ No newline at end of file diff --git a/bin/convert.js b/bin/convert.js new file mode 100644 index 00000000..94e9877a --- /dev/null +++ b/bin/convert.js @@ -0,0 +1,449 @@ +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 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 LIMIT", [], 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