This repository has been archived by the owner on Apr 21, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupgrade.js
62 lines (53 loc) · 1.7 KB
/
upgrade.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env node
'use strict';
// 1 - first version of parliament
// 2 - cluster.type instead of cluster.disabled/multiviewer
// 3 - more than one of each type of notifier
const version = 3;
module.exports = {
/**
* Upgrades the parliament object to the latest version
* @param {object} parliament the parliament object to upgrade
*/
upgrade: function (parliament, notifierDefs) {
// fix cluster types
if (parliament.groups) {
for (let group of parliament.groups) {
if (group.clusters) {
for (let cluster of group.clusters) {
if (cluster.multiviewer) {
delete cluster.multiviewer;
cluster.type = 'multiviewer';
} else if (cluster.disabled) {
delete cluster.disabled;
cluster.type = 'disabled';
}
}
}
}
}
// fix notifiers
if (parliament.settings && parliament.settings.notifiers) {
// only save the notifiers with values
for (let n in parliament.settings.notifiers) {
let notifier = parliament.settings.notifiers[n];
let hasValues = false;
// check for values in notifiers
for (let f in notifier.fields) {
if (notifier.fields[f].value) {
hasValues = true;
break;
}
}
// add or lowercase the type
if (notifier.type) { notifier.type = notifier.type.toLowerCase(); }
else { notifier.type = n; }
// if the notifier has no values, it's not being used, so remove it
if (!hasValues) { parliament.settings.notifiers[n] = undefined; }
}
}
// update version
parliament.version = version;
return parliament;
}
}