forked from softwerkskammer/Agora
-
Notifications
You must be signed in to change notification settings - Fork 0
/
changeGroupname.js
83 lines (72 loc) · 2.36 KB
/
changeGroupname.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
'use strict';
require('./configure'); // initializing parameters
var async = require('async');
var beans = require('nconf').get('beans');
var mailsPersistence = beans.get('mailsPersistence');
var groupsPersistence = beans.get('groupsPersistence');
var activitiesPersistence = beans.get('activitiesPersistence');
var Git = beans.get('gitmech');
var really = process.argv[2];
if (!really || really !== 'really') {
console.log('If you really want to rename the group, append "really" to the command line.');
process.exit();
}
var oldId = 'socrates2014';
var newId = 'socrates-orga';
var newPrefix = 'SoCraTes Orga';
function closeDBsAndExit() {
groupsPersistence.closeDB();
activitiesPersistence.closeDB();
mailsPersistence.closeDB();
process.exit();
}
function handle(err) {
if (err) {
console.log(err);
closeDBsAndExit();
}
}
// change the group's id:
groupsPersistence.getById(oldId, function (err, group) {
handle(err);
group.id = newId;
group.emailPrefix = newPrefix;
groupsPersistence.update(group, oldId, function (err) {
handle(err);
// change each activity that belongs to the group:
activitiesPersistence.listByField({assignedGroup: oldId}, {}, function (err, results) {
handle(err);
async.each(results,
function (each, callback) {
each.assignedGroup = newId;
activitiesPersistence.save(each, callback);
},
function (err) {
handle(err);
// change each archived email that belongs to the group:
mailsPersistence.listByField({group: oldId}, {}, function (err, results) {
async.each(results,
function (each, callback) {
each.group = newId;
mailsPersistence.save(each, callback);
},
function (err) {
handle(err);
Git.mv(oldId, newId, 'Group rename: ' + oldId + ' -> ' + newId, 'Nicole <[email protected]>', function (err) {
handle(err);
closeDBsAndExit();
});
});
});
});
});
});
});
/*
What else must be done when renaming a group?
- rename the group in sympa:
- Rename List
- Edit List Config -> List Definition -> Subject of the list
- Edit List Config -> Sending/Receiving Setup -> Subject tagging (custom_subject)
- adapt all wiki-links??
*/