Skip to content
11 changes: 9 additions & 2 deletions api/parts/jobs/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -1068,9 +1068,16 @@ class IPCFaçadeJob extends ResourcefulJob {
this.ipcChannel.remove();
}, (error) => {
this.ipcChannel.remove();
log.e('[%s] Error in IPCFaçadeJob %s: %j / %j', this.job.channel, this.resourceFaçade._id, error, error.stack);
if (error) {
log.e('[%s] Error in IPCFaçadeJob %s: %j / %j', this.job.channel, this.resourceFaçade._id, error, error.stack);
}
else {
log.e('[%s] Error in IPCFaçadeJob %s: Unknown error', this.job.channel, this.resourceFaçade._id);
}
this.job._finish(error || 'Aborted').catch(()=>{});
throw error;
if (error) {
throw error;
}
});
}

Expand Down
1 change: 1 addition & 0 deletions api/parts/mgmt/apps.js
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,7 @@ appsApi.updateAppPlugins = function(params) {
* @returns {boolean} true if operation successful
**/
appsApi.deleteApp = function(params) {
params = params || {};
var argProps = {
'app_id': {
'required': true,
Expand Down
132 changes: 67 additions & 65 deletions bin/scripts/drill_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,75 +32,77 @@ Promise.all([plugins.dbConnection("countly"), plugins.dbConnection("countly_dril
countlyDb.close();
console.log("Error occured:", error);
}
var cnt = 0;
results = results.filter(collection => collection && collection.collectionName && collection.collectionName.startsWith("drill_events"));
async.eachSeries(results, function(collection, done) {
cnt++;
console.log("Processing", cnt, "of", results.length, collection.collectionName);
var col = db.collection(collection.collectionName);
col.createIndex({uid: 1}, {background: true}, function() {
console.log("Done", {uid: 1});
if (hashes[collection.collectionName] === "[CLY]_session") {
col.createIndex({ts: 1, "up.cc": 1, uid: 1}, {background: true}, function() {
console.log("Done", "[CLY]_session", {ts: 1, "up.cc": 1, uid: 1});
done();
});
}
else if (hashes[collection.collectionName] === "[CLY]_view") {
col.createIndex({ts: 1, "sg.name": 1}, {background: true}, function() {
console.log("Done", "[CLY]_view", {ts: 1, "sg.name": 1});
done();
});
}
else if (hashes[collection.collectionName] === "[CLY]_crash") {
col.createIndex({ts: 1, "sg.crash": 1}, {background: true}, function() {
console.log("Done", "[CLY]_crash", {ts: 1, "sg.crash": 1});
done();
});
}
else if (hashes[collection.collectionName] === "[CLY]_push_action") {
col.createIndex({ts: 1, "sg.i": 1, uid: 1}, {background: true}, function() {
console.log("Done", "[CLY]_push_action", {ts: 1, "sg.i": 1});
done();
});
}
else if (hashes[collection.collectionName] === "[CLY]_star_rating") {
col.createIndex({ts: 1, "sg.widget_id": 1, "sg.rating": 1, uid: 1}, {background: true}, function() {
console.log("Done", "[CLY]_star_rating", {ts: 1, "sg.widget_id": 1, "sg.rating": 1});
done();
});
}
else if (hashes[collection.collectionName] === "[CLY]_nps") {
col.createIndex({ts: 1, "sg.widget_id": 1, "sg.rating": 1, uid: 1}, {background: true}, function() {
console.log("Done", "[CLY]_nps", {ts: 1, "sg.widget_id": 1, "sg.rating": 1});
done();
});
}
else if (hashes[collection.collectionName] === "[CLY]_survey") {
col.createIndex({ts: 1, "sg.widget_id": 1, uid: 1}, {background: true}, function() {
console.log("Done", "[CLY]_survey", {ts: 1, "sg.widget_id": 1});
done();
});
}
else {
col.createIndex({ts: 1}, {background: true}, function() {
console.log("Done", {ts: 1});
else {
var cnt = 0;
results = results.filter(collection => collection && collection.collectionName && collection.collectionName.startsWith("drill_events"));
async.eachSeries(results, function(collection, done) {
cnt++;
console.log("Processing", cnt, "of", results.length, collection.collectionName);
var col = db.collection(collection.collectionName);
col.createIndex({uid: 1}, {background: true}, function() {
console.log("Done", {uid: 1});
if (hashes[collection.collectionName] === "[CLY]_session") {
col.createIndex({ts: 1, "up.cc": 1, uid: 1}, {background: true}, function() {
console.log("Done", "[CLY]_session", {ts: 1, "up.cc": 1, uid: 1});
done();
});
}
else if (hashes[collection.collectionName] === "[CLY]_view") {
col.createIndex({ts: 1, "sg.name": 1}, {background: true}, function() {
console.log("Done", "[CLY]_view", {ts: 1, "sg.name": 1});
done();
});
}
else if (hashes[collection.collectionName] === "[CLY]_crash") {
col.createIndex({ts: 1, "sg.crash": 1}, {background: true}, function() {
console.log("Done", "[CLY]_crash", {ts: 1, "sg.crash": 1});
done();
});
}
else if (hashes[collection.collectionName] === "[CLY]_push_action") {
col.createIndex({ts: 1, "sg.i": 1, uid: 1}, {background: true}, function() {
console.log("Done", "[CLY]_push_action", {ts: 1, "sg.i": 1});
done();
});
}
else if (hashes[collection.collectionName] === "[CLY]_star_rating") {
col.createIndex({ts: 1, "sg.widget_id": 1, "sg.rating": 1, uid: 1}, {background: true}, function() {
console.log("Done", "[CLY]_star_rating", {ts: 1, "sg.widget_id": 1, "sg.rating": 1});
done();
});
}
else if (hashes[collection.collectionName] === "[CLY]_nps") {
col.createIndex({ts: 1, "sg.widget_id": 1, "sg.rating": 1, uid: 1}, {background: true}, function() {
console.log("Done", "[CLY]_nps", {ts: 1, "sg.widget_id": 1, "sg.rating": 1});
done();
});
}
else if (hashes[collection.collectionName] === "[CLY]_survey") {
col.createIndex({ts: 1, "sg.widget_id": 1, uid: 1}, {background: true}, function() {
console.log("Done", "[CLY]_survey", {ts: 1, "sg.widget_id": 1});
done();
});
}
else {
col.createIndex({ts: 1}, {background: true}, function() {
console.log("Done", {ts: 1});
done();
});
}
});
}, function() {
console.log("Fixing indexes on eventTimes collections");
async.eachSeries(apps, function(app, done) {
countlyDb.collection('eventTimes' + app._id).ensureIndex({"uid": 1}, function() {
done();
});
}
});
}, function() {
console.log("Fixing indexes on eventTimes collections");
async.eachSeries(apps, function(app, done) {
countlyDb.collection('eventTimes' + app._id).ensureIndex({"uid": 1}, function() {
done();
}, function() {
db.close();
countlyDb.close();
console.log("Drill index finished");
});
}, function() {
db.close();
countlyDb.close();
console.log("Drill index finished");
});
});
}
});
});
});
4 changes: 3 additions & 1 deletion bin/scripts/fix-data/recheck_merges_new.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ Promise.all([pluginManager.dbConnection("countly"), pluginManager.dbConnection("
}
totalProcessedUsers[app._id]++;
}
await addRecheckedFlag(app._id, user.uid);
if (user && user.uid) {
await addRecheckedFlag(app._id, user.uid);
}
}
console.log("Processed users for app", app.name, ": ", totalProcessedUsers[app._id]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,26 +381,28 @@
},
dataType: "json",
success: function(data) {
data.locked = false;
countlyGlobal.apps[data._id] = data;
countlyGlobal.admin_apps[data._id] = data;
Backbone.history.appIds.push(data._id + "");
countlyGlobal.apps[data._id].image = "appimages/" + data._id + ".png?" + Date.now().toString();
self.appList.push({
value: data._id + "",
label: data.name
});
self.$store.dispatch("countlyCommon/addToAllApps", data);
if (self.firstApp) {
countlyCommon.ACTIVE_APP_ID = data._id + "";
app.onAppManagementSwitch(data._id + "", data && data.type || "mobile");
self.$store.dispatch("countlyCommon/updateActiveApp", data._id + "");
app.initSidebar();
if (data && data._id) {
data.locked = false;
countlyGlobal.apps[data._id] = data;
countlyGlobal.admin_apps[data._id] = data;
Backbone.history.appIds.push(data._id + "");
countlyGlobal.apps[data._id].image = "appimages/" + data._id + ".png?" + Date.now().toString();
self.appList.push({
value: data._id + "",
label: data.name
});
self.$store.dispatch("countlyCommon/addToAllApps", data);
if (self.firstApp) {
countlyCommon.ACTIVE_APP_ID = data._id + "";
app.onAppManagementSwitch(data._id + "", data && data.type || "mobile");
self.$store.dispatch("countlyCommon/updateActiveApp", data._id + "");
app.initSidebar();
}
self.firstApp = self.checkIfFirst();
setTimeout(function() {
self.selectedSearchBar = data._id + "";
}, 1);
}
self.firstApp = self.checkIfFirst();
setTimeout(function() {
self.selectedSearchBar = data._id + "";
}, 1);
},
error: function(xhr, status, error) {
CountlyHelpers.notify({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1414,7 +1414,7 @@ var AppRouter = Backbone.Router.extend({
* <span>{{#limitString value 15}}{{/limitString}}</span>
*/
Handlebars.registerHelper('limitString', function(string, limit) {
if (string.length > limit) {
if (string && string.length > limit) {
return (string || '').substr(0, limit) + "..";
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@
* Delete the hover key as its set by the data table on hovering a row
* and we don't want to pass it to the drawer.
*/
delete initialEditedObject.hover;
if (initialEditedObject && initialEditedObject.hover !== undefined) {
delete initialEditedObject.hover;
}
this.drawers[name].initialEditedObject = initialEditedObject || {};
},
closeDrawer: function(name) {
Expand Down
4 changes: 3 additions & 1 deletion plugins/alerts/api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,9 @@ const PERIOD_TO_TEXT_EXPRESSION_MAPPER = {
{$set: alertConfig},
function(err, result) {
if (!err) {
plugins.dispatch("/updateAlert", { method: "alertTrigger", alert: result.value });
if (result && result.value) {
plugins.dispatch("/updateAlert", { method: "alertTrigger", alert: result.value });
}
plugins.dispatch("/updateAlert", { method: "alertTrigger" });

common.returnOutput(params, result && result.value);
Expand Down
3 changes: 2 additions & 1 deletion plugins/alerts/frontend/public/javascripts/countly.models.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,15 @@
},
dataType: "json",
success: function(res) {
if (res && res.aaData && res.aaData.length > 0 && callback) {
if (res && res.aaData && res.aaData.length > 0) {
var data = [];
for (var i = 0; i < res.aaData.length; i++) {
data.push({
value: res.aaData[i]._id,
name: res.aaData[i].view,
});
}

return callback(data);
}

Expand Down
14 changes: 9 additions & 5 deletions plugins/crashes/api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ plugins.setConfigs("crashes", {
report.group = hash;
report.uid = dbAppUser.uid;
report.ts = params.time.timestamp;
var updateUser = {};
let updateUser = {};
if (!report.nonfatal) {
if (!dbAppUser.hadFatalCrash) {
updateUser.hadFatalCrash = "true";
Expand All @@ -464,20 +464,24 @@ plugins.setConfigs("crashes", {
}
updateUser.hadAnyNonfatalCrash = report.ts;
}
let updateData = {$inc: {}};
let updateData = { $inc: {} };
updateData.$inc["data.crashes"] = 1;
if (Object.keys(updateUser).length) {
updateData.$set = updateUser;
}
ob.updates.push(updateData);

var set = {group: hash, 'uid': report.uid, last: report.ts};
if (dbAppUser && dbAppUser.sc) {
var set = {
group: hash,
uid: report.uid,
last: report.ts,
};
if (dbAppUser.sc) {
set.sessions = dbAppUser.sc;
}
common.db.collection('app_crashusers' + params.app_id).findAndModify({group: hash, 'uid': report.uid}, {}, {$set: set, $inc: {reports: 1}}, {upsert: true, new: false}, function(err, user) {
user = user && user.ok ? user.value : null;
if (user && user.sessions && dbAppUser && dbAppUser.sc && dbAppUser.sc > user.sessions) {
if (user && user.sessions && dbAppUser.sc && dbAppUser.sc > user.sessions) {
report.session = dbAppUser.sc - user.sessions;
}
common.db.collection('app_crashes' + params.app_id).insert(report, function(crashErr, res) {
Expand Down
3 changes: 3 additions & 0 deletions plugins/dashboards/frontend/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ var countlyFs = require('../../../api/utils/countlyFs.js');

plugin.staticPaths = function(app/*, countlyDb*/) {
app.get(countlyConfig.path + "/dashboards/images/screenshots/*", function(req, res) {
if (!req || !req.params) {
return res.send(false);
}
var requestPath = req.path;
var reqArray = requestPath.split("/");
var fileName = "";
Expand Down
4 changes: 1 addition & 3 deletions plugins/data-manager/api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,7 @@ plugins.register("/i/data-manager/event/change-category", function(ob) {

const eventsData = await common.db.collection('events').findOne({'_id': common.db.ObjectID(appId)});

if (!eventsData.map) {
eventsData.map = {};
}
eventsData.map = eventsData.map || {};

events.forEach(e=>{
if (eventsData.map && eventsData.map[e]) {
Expand Down
4 changes: 2 additions & 2 deletions plugins/hooks/api/parts/triggers/api_endpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ class APIEndPointTrigger {
*/
async process(ob) {
// log.d(JSON.stringify(ob), "[hook trigger api_endpoint]");
const {params} = ob;
const {paths} = params;
const {params} = ob || {};
const {paths} = params || {};
const hookPath = paths.length >= 4 ? paths[3] : null;
const {qstring} = params || {};

Expand Down
1 change: 1 addition & 0 deletions plugins/logger/api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ plugins.setConfigs("logger", {
};

var processSDKRequest = function(params) {
params = params || {};
log.d("Explicitly set logging_is_allowed => ", params.logging_is_allowed);
const requestLoggerConfiguration = getRequestLoggerConfiguration(params);
log.d("Logging config => ", requestLoggerConfiguration);
Expand Down
Loading