added init method to database, progress made

v1.18.x
Baris Usakli 11 years ago
parent 91d6f83de4
commit e862a1c4cc

112
app.js

@ -60,7 +60,7 @@
nconf.file({ nconf.file({
file: __dirname + '/config.json' file: __dirname + '/config.json'
}); });
meta = require('./src/meta.js'); meta = require('./src/meta');
nconf.set('url', nconf.get('base_url') + (nconf.get('use_port') ? ':' + nconf.get('port') : '') + nconf.get('relative_path') + '/'); nconf.set('url', nconf.get('base_url') + (nconf.get('use_port') ? ':' + nconf.get('port') : '') + nconf.get('relative_path') + '/');
nconf.set('upload_url', nconf.get('url') + 'uploads/'); nconf.set('upload_url', nconf.get('url') + 'uploads/');
@ -73,60 +73,62 @@
winston.info('Base Configuration OK.'); winston.info('Base Configuration OK.');
} }
meta.configs.init(function () { require('./src/database').init(function(err) {
meta.configs.init(function () {
//
// TODO : figure out reds search after dbal is complete //
// // TODO : figure out reds search after dbal is complete
//var reds = require('reds'), //
// db = require('./src/database'); //var reds = require('reds'),
/*reds.createClient = function () { // db = require('./src/database');
return reds.client || (reds.client = db); /*reds.createClient = function () {
};*/ return reds.client || (reds.client = db);
};*/
var templates = require('./public/src/templates'),
translator = require('./public/src/translator'), var templates = require('./public/src/templates'),
webserver = require('./src/webserver'), translator = require('./public/src/translator'),
SocketIO = require('socket.io').listen(global.server, { log: false, transports: ['websocket', 'xhr-polling', 'jsonp-polling', 'flashsocket'], 'browser client minification': true}), webserver = require('./src/webserver'),
websockets = require('./src/websockets'), SocketIO = require('socket.io').listen(global.server, { log: false, transports: ['websocket', 'xhr-polling', 'jsonp-polling', 'flashsocket'], 'browser client minification': true}),
plugins = require('./src/plugins'), websockets = require('./src/websockets'),
notifications = require('./src/notifications'), plugins = require('./src/plugins'),
upgrade = require('./src/upgrade'); notifications = require('./src/notifications'),
upgrade = require('./src/upgrade');
upgrade.check(function(schema_ok) {
if (schema_ok || nconf.get('check-schema') === false) { upgrade.check(function(schema_ok) {
websockets.init(SocketIO); if (schema_ok || nconf.get('check-schema') === false) {
console.log('calling plugins init'); websockets.init(SocketIO);
plugins.init();
global.templates = {}; plugins.init();
global.translator = translator; global.templates = {};
global.translator = translator;
translator.loadServer();
translator.loadServer();
var customTemplates = meta.config['theme:templates'] ? path.join(__dirname, 'node_modules', meta.config['theme:id'], meta.config['theme:templates']) : false;
var customTemplates = meta.config['theme:templates'] ? path.join(__dirname, 'node_modules', meta.config['theme:id'], meta.config['theme:templates']) : false;
// todo: replace below with read directory code, derp.
templates.init([ // todo: replace below with read directory code, derp.
'header', 'footer', 'logout', 'outgoing', 'admin/header', 'admin/footer', 'admin/index', templates.init([
'emails/reset', 'emails/reset_plaintext', 'emails/email_confirm', 'emails/email_confirm_plaintext', 'header', 'footer', 'logout', 'outgoing', 'admin/header', 'admin/footer', 'admin/index',
'emails/header', 'emails/footer', 'emails/reset', 'emails/reset_plaintext', 'emails/email_confirm', 'emails/email_confirm_plaintext',
'emails/header', 'emails/footer',
'noscript/header', 'noscript/home', 'noscript/category', 'noscript/topic'
], customTemplates); 'noscript/header', 'noscript/home', 'noscript/category', 'noscript/topic'
], customTemplates);
plugins.ready(function() {
templates.ready(webserver.init); plugins.ready(function() {
}); templates.ready(webserver.init);
});
notifications.init();
} else { notifications.init();
winston.warn('Your NodeBB schema is out-of-date. Please run the following command to bring your dataset up to spec:'); } else {
winston.warn(' node app --upgrade'); winston.warn('Your NodeBB schema is out-of-date. Please run the following command to bring your dataset up to spec:');
winston.warn('To ignore this error (not recommended):'); winston.warn(' node app --upgrade');
winston.warn(' node app --no-check-schema') winston.warn('To ignore this error (not recommended):');
process.exit(); winston.warn(' node app --no-check-schema')
} process.exit();
}
});
}); });
}); });
} else if (nconf.get('setup') || nconf.get('install') || !fs.existsSync(__dirname + '/config.json')) { } else if (nconf.get('setup') || nconf.get('install') || !fs.existsSync(__dirname + '/config.json')) {

@ -2,9 +2,7 @@
(function(module) { (function(module) {
'use strict'; 'use strict';
var Db = require('mongodb').Db, var mongoClient = require('mongodb').MongoClient,
mongoClient = require('mongodb').MongoClient,
Server = require('mongodb').Server,
winston = require('winston'), winston = require('winston'),
nconf = require('nconf'), nconf = require('nconf'),
express = require('express'), express = require('express'),
@ -12,45 +10,36 @@
mongoHost = nconf.get('mongo:host'), mongoHost = nconf.get('mongo:host'),
db; db;
module.init = function(callback) {
mongoClient.connect('mongodb://'+ mongoHost + ':' + nconf.get('mongo:port') + '/' + nconf.get('mongo:database'), function(err, _db) {
db = _db;
console.log('WE ARE CONNECTED');
var db = new Db(nconf.get('mongo:database'), new Server(mongoHost, nconf.get('mongo:port')), {w:1}); if(err) {
//console.log(db.collection); winston.error("NodeBB could not connect to your Mongo database. Mongo returned the following error: " + err.message);
process.exit();
}
db.open(function(err, _db) { // TODO: fill out settings.db
//mongoClient.connect('mongodb://'+ mongoHost + ':' + nconf.get('mongo:port') + '/' + nconf.get('mongo:database'), function(err, _db) { module.sessionStore = new mongoStore({
console.log('WE ARE CONNECTED'); db: db
if(err) { });
winston.error("NodeBB could not connect to your Mongo database. Mongo returned the following error: " + err.message);
process.exit();
}
// TODO: fill out settings.db
module.sessionStore = new mongoStore({
db: db
});
db.collection('objects').findOne({_key:'config'}, {timeout:true}, function(err, item) {
console.log('fail');
console.log(item);
callback(err, item);
});
});
db.createCollection('objects', function(err, collection) {
console.log('collection created', err, collection);
});
db.createCollection('sets', function(err, collection) { db.createCollection('objects', function(err, collection) {
});
}); db.createCollection('sets', function(err, collection) {
});
callback(err);
// look up how its done in mongo });
/*if (nconf.get('mongo:password')) { // look up how its done in mongo
redisClient.auth(nconf.get('mongo:password')); /*if (nconf.get('mongo:password')) {
redisClient.auth(nconf.get('mongo:password'));
}
*/
} }
*/
// //
@ -97,18 +86,46 @@
module.getObject = function(key, callback) { module.getObject = function(key, callback) {
console.log('calling findOne'); console.log('calling findOne');
db.collection('objects').findOne({_key:key}, {timeout:true},function(err, item) { db.collection('objects').findOne({_key:key}, function(err, item) {
console.log(item); console.log(item);
callback(err, item); callback(err, item);
}); });
} }
module.getObjectField = function(key, field, callback) { module.getObjectField = function(key, field, callback) {
throw new Error('not-implemented'); module.getObjectFields(key, [field], function(err, data) {
if(err) {
return callback(err);
}
callback(null, data[field]);
})
} }
module.getObjectFields = function(key, fields, callback) { module.getObjectFields = function(key, fields, callback) {
throw new Error('not-implemented');
var _fields = {};
for(var i=0; i<fields.length; ++i) {
_fields[fields[i]] = 1;
}
db.collection('objects').findOne({_key:key}, {fields:_fields}, function(err, item) {
if(err) {
return callback(err);
}
var data = {};
if(item === null) {
for(var i=0; i<fields.length; ++i) {
data[fields[i]] = null;
}
console.log('getObjectFields', data);
return callback(null, data);
}
console.log('getObjectFields', item);
callback(err, item);
});
} }
module.getObjectValues = function(key, callback) { module.getObjectValues = function(key, callback) {

@ -12,6 +12,7 @@
redis_socket_or_host = nconf.get('redis:host'), redis_socket_or_host = nconf.get('redis:host'),
utils = require('./../../public/src/utils.js'); utils = require('./../../public/src/utils.js');
if (redis_socket_or_host && redis_socket_or_host.indexOf('/')>=0) { if (redis_socket_or_host && redis_socket_or_host.indexOf('/')>=0) {
/* If redis.host contains a path name character, use the unix dom sock connection. ie, /tmp/redis.sock */ /* If redis.host contains a path name character, use the unix dom sock connection. ie, /tmp/redis.sock */
redisClient = redis.createClient(nconf.get('redis:host')); redisClient = redis.createClient(nconf.get('redis:host'));
@ -20,14 +21,13 @@
redisClient = redis.createClient(nconf.get('redis:port'), nconf.get('redis:host')); redisClient = redis.createClient(nconf.get('redis:port'), nconf.get('redis:host'));
} }
module.client = redisClient;
module.sessionStore = new connectRedis({ module.sessionStore = new connectRedis({
client: redisClient, client: redisClient,
ttl: 60 * 60 * 24 * 30 ttl: 60 * 60 * 24 * 30
}); });
module.client = redisClient;
module.type = 'redis';
if (nconf.get('redis:password')) { if (nconf.get('redis:password')) {
redisClient.auth(nconf.get('redis:password')); redisClient.auth(nconf.get('redis:password'));
} }
@ -43,6 +43,11 @@
}); });
} }
module.init = function(callback) {
callback(null);
}
/* /*
* A possibly more efficient way of doing multiple sismember calls * A possibly more efficient way of doing multiple sismember calls
*/ */

@ -18,7 +18,6 @@ var fs = require('fs'),
Plugins.readyEvent = new eventEmitter; Plugins.readyEvent = new eventEmitter;
Plugins.init = function() { Plugins.init = function() {
console.log('plugins init called');
if (Plugins.initialized) { if (Plugins.initialized) {
return; return;
} }
@ -39,7 +38,7 @@ var fs = require('fs'),
winston.info('[plugins] Plugins OK'); winston.info('[plugins] Plugins OK');
} }
Plugins.initialized = true; Plugins.initialized = true;
plugins.readyEvent.emit('ready'); Plugins.readyEvent.emit('ready');
}); });
}; };

@ -1,10 +1,9 @@
"use strict"; "use strict";
var db = require('./database'), var //db = require('./database'),
// TODO: temp until upgrade is figured out with dbal, // TODO: temp until upgrade is figured out with dbal,
// db.client is redisClient for now RDB = require('./database/redis').client,
RDB = db.client,
async = require('async'), async = require('async'),
winston = require('winston'), winston = require('winston'),

Loading…
Cancel
Save