mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2024-12-28 08:05:53 -05:00
Merge pull request #5334 from si458/fix-nedbtodb
Fix nedbtodb and sqlite
This commit is contained in:
commit
86ad4bc926
15
db.js
15
db.js
@ -1470,7 +1470,14 @@ module.exports.CreateDB = function (parent, func) {
|
||||
obj.StoreEvent = function (event, func) {
|
||||
obj.dbCounters.eventsSet++;
|
||||
sqlDbQuery('INSERT INTO events VALUES (NULL, $1, $2, $3, $4, $5, $6) RETURNING id', [event.time, ((typeof event.domain == 'string') ? event.domain : null), event.action, event.nodeid ? event.nodeid : null, event.userid ? event.userid : null, JSON.stringify(event)], function (err, docs) {
|
||||
if ((err == null) && (docs[0].id)) { for (var i in event.ids) { if (event.ids[i] != '*') { sqlDbQuery('INSERT INTO eventids VALUES ($1, $2)', [docs[0].id, event.ids[i]]); } } }
|
||||
if(func){ func(); }
|
||||
if ((err == null) && (docs[0].id)) {
|
||||
for (var i in event.ids) {
|
||||
if (event.ids[i] != '*') {
|
||||
sqlDbQuery('INSERT INTO eventids VALUES ($1, $2)', [docs[0].id, event.ids[i]], function(){ if(func){ func(); } });
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
obj.GetEvents = function (ids, domain, func) {
|
||||
@ -3181,7 +3188,10 @@ module.exports.CreateDB = function (parent, func) {
|
||||
|
||||
// Transfer NeDB data into the current database
|
||||
obj.nedbtodb = function (func) {
|
||||
var nedbDatastore = require('nedb');
|
||||
var nedbDatastore = null;
|
||||
try { nedbDatastore = require('@yetzt/nedb'); } catch (ex) { } // This is the NeDB with fixed security dependencies.
|
||||
if (nedbDatastore == null) { nedbDatastore = require('nedb'); } // So not to break any existing installations, if the old NeDB is present, use it.
|
||||
|
||||
var datastoreOptions = { filename: parent.getConfigFilePath('meshcentral.db'), autoload: true };
|
||||
|
||||
// If a DB encryption key is provided, perform database encryption
|
||||
@ -3236,6 +3246,7 @@ module.exports.CreateDB = function (parent, func) {
|
||||
for (var i in docs) {
|
||||
pendingTransfer++;
|
||||
eventRecordsTransferCount++;
|
||||
for (var b in docs[i].ids) { if (docs[i].ids[b] != '*') { pendingTransfer++; } }
|
||||
obj.StoreEvent(docs[i], function () { pendingTransfer--; });
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user