diff --git a/bin/importSqlFile.js b/bin/importSqlFile.js index 4e9b1f3ed..b1642288b 100644 --- a/bin/importSqlFile.js +++ b/bin/importSqlFile.js @@ -1,44 +1,46 @@ var startTime = new Date().getTime(); -var fs = require("fs"); -var db = require("../src/node/db/DB"); -//var async = require("../src/node_modules/async"); -var sqlFile = process.argv[2]; +require("ep_etherpad-lite/node_modules/npm").load({}, function(er,npm) { -//stop if the settings file is not set -if(!sqlFile) -{ - console.error("Use: node importSqlIntoRedis.js $SQLFILE"); - process.exit(1); -} + var fs = require("fs"); + var db = require("ep_etherpad-lite/node/db/DB");; -log("initializing db"); -db.init(function(){ - log("done"); + var sqlFile = process.argv[2]; - log("open output file..."); - var file = fs.readFileSync(sqlFile, 'utf8'); + //stop if the settings file is not set + if(!sqlFile) + { + console.error("Use: node importSqlFile.js $SQLFILE"); + process.exit(1); + } - var keyNo = 0; + log("initializing db"); + db.init(function(){ + log("done"); - file.split("\n").forEach(function(l) { - if (l.substr(0, 27) == "REPLACE INTO store VALUES (") { - var pos = l.indexOf("', '"); - var key = l.substr(28, pos - 28); - var value = l.substr(pos + 4); - value = value.substr(0, value.length - 3); - db.db.set(key, value, null); - keyNo++; - } - }); + log("open output file..."); + var file = fs.readFileSync(sqlFile, 'utf8'); - db.db.doShutdown(function() { - log("finished, imported " + keyNo + " keys."); - process.exit(0); + var keyNo = 0; + + file.split("\n").forEach(function(l) { + if (l.substr(0, 27) == "REPLACE INTO store VALUES (") { + var pos = l.indexOf("', '"); + var key = l.substr(28, pos - 28); + var value = l.substr(pos + 4); + value = value.substr(0, value.length - 3); + db.db.set(key, value, null); + keyNo++; + } + }); + + db.db.doShutdown(function() { + log("finished, imported " + keyNo + " keys."); + process.exit(0); + }); }); }); - function log(str) { console.log((new Date().getTime() - startTime)/1000 + "\t" + str);