Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.then(allUsersDoc => {
if (allUsersDoc) {
// userIDsFlat may contain "free text" users that are not in DB
// We create a dict to look up which collected userIDs are really from DB
let userIDsFromDB = {};
allUsersDoc.map(usr => {
userIDsFromDB[usr._id] = 1;
});
const usrFile = msID + ExpImpUsers.FILENAME_POSTFIX;
fs.writeFileSync(usrFile, EJSON.stringify(allUsersDoc,null,2));
console.log('Saved: '+usrFile + ' with '+allUsersDoc.length+' users');
// Save mapping file old => new user ID
// But only with REAL DB users (skip free text users)
userIDsFlat.map(usrID => {
if (userIDsFromDB[usrID]) {
// default: newID === oldID
// This means, users are copied(!) from source DB to destination DB
// If newID is changed to an existing id from destination ID, this target user is used
let thisUser = ExpImpUsers.searchUser(allUsersDoc, usrID);
userIDsOuputMap[usrID] = {
'newID': usrID,
'hint': thisUser.username +" "+thisUser.profile.name
};
}
});
.then(allMinutesDoc => {
if (allMinutesDoc) {
const minFile = msID + ExpImpMinutes.FILENAME_POSTFIX;
fs.writeFileSync(minFile, EJSON.stringify(allMinutesDoc,null,2));
console.log('Saved: '+minFile + ' with '+allMinutesDoc.length+' minutes');
// Collect additional invited / informed users from older minutes
allMinutesDoc.map(min => {
min.visibleFor && min.visibleFor.map(userID => { // should be identical to meeting series
userIDs[userID] = 1;
});
min.informedUsers && min.informedUsers.map(userID => { // should be identical to meeting series
userIDs[userID] = 1;
});
min.participants && min.participants.map(part => { // might differ from meeting series users!
userIDs[part.userId] = 1;
});
min.topics && min.topics.map(top => { // iterate topics
top.responsibles && top.responsibles.map(resp => { // topic-responsibles
userIDs[resp] = 1;
var respCallback = function(json) {
// Convert JSON object to MongoDB-Extended JSON
var e = EJSON.stringify(json);
var j = JSON.parse(e);
return res.json(j);
};
//console.log(JSON.stringify(query));
gateway.sendDeviceState = function(deviceId, state, cb) {
var topic = util.format(config.topicFormatState, deviceId);
var payload = { time: new Date(), data: state };
// May not be connected. Skip publish if not.
if(mqttClient) {
mqttClient.publish(topic, EJSON.stringify(payload), cb);
}
};
.then(doc => {
if (doc) {
const attFile = msID + ExpImpFilesAttachments.FILENAME_POSTFIX;
fs.writeFileSync(attFile, EJSON.stringify(doc,null,2));
console.log('Saved: '+attFile + ' with '+doc.length+' file attachments');
if (doc[0]) {
console.log(' *** Hint *** Please manually copy all files below:');
console.log(' '+doc[0]._storagePath);
}
resolve({db, userIDs});
} else {
return reject ('Unknown meeting series ID: '+ msID);
}
});
});
.then(doc => {
if (doc) {
const protFile = msID + ExpImpFilesDocuments.FILENAME_POSTFIX;
fs.writeFileSync(protFile, EJSON.stringify(doc,null,2));
console.log('Saved: '+protFile + ' with '+doc.length+' protocol documents');
if (doc[0]) {
console.log(' *** Hint *** Please manually copy all files below:');
console.log(' '+doc[0]._storagePath.substr(0, doc[0]._storagePath.lastIndexOf('/')));
}
resolve({db, userIDs});
} else {
return reject ('Unknown meeting series ID: '+ msID);
}
});
});
.then(doc => {
if (doc) {
console.log("DB Schema Version: "+doc.version);
if (ExpImpSchema.MADE_FOR_SCHEMA !== doc.version) {
console.log("*** WARNING *** Schema mismatch!");
console.log(" This exporter is made for database schema version: "+ExpImpSchema.MADE_FOR_SCHEMA);
console.log(" But your database has schema version : "+doc.version);
console.log(" Alyways migrate to the most recent DB schema before export!");
console.log(" Alyways use matching exporter!");
console.log(" Exported data may be corrupt. Continue at your own risk.");
}
const schemaFile = msID + ExpImpSchema.FILENAME_POSTFIX;
fs.writeFileSync(schemaFile, EJSON.stringify(doc,null,2));
console.log("Saved: "+schemaFile);
resolve(db);
} else {
return reject ("No migrations schema version found in your DB! Unable to export.");
}
});
});
.then(doc => {
if (doc) {
const topFile = msID + ExpImpTopics.FILENAME_POSTFIX;
fs.writeFileSync(topFile, EJSON.stringify(doc,null,2));
console.log('Saved: '+topFile + ' with '+doc.length+' topics');
resolve({db, userIDs});
} else {
return reject ('Unknown meeting series ID: '+ msID);
}
});
});
exports.toJsonString = function (doc) {
return ESJON.stringify(doc);
};
data.on('data', d => {
fs.appendFileSync(file, EJSON.stringify(d) + '\n');
}).on('end', () => {
return resolve();