2016-02-11 15:32:59 -05:00
|
|
|
// Updates all sessions for a given level and classroom to match the classroom language setting.
|
|
|
|
// Usage:
|
|
|
|
// mongo <address>:<port>/<database> <script file> -u <username> -p <password>
|
|
|
|
|
2016-02-19 16:13:45 -05:00
|
|
|
print('Loading levels...');
|
|
|
|
var levels = [db.levels.findOne({slug: 'wakka-maul'}), db.levels.findOne({slug: 'cross-bones'})];
|
|
|
|
print('Loaded');
|
2016-02-11 15:32:59 -05:00
|
|
|
|
2016-02-19 16:13:45 -05:00
|
|
|
db.classrooms.find({'aceConfig.language': 'javascript'}).forEach(function(classroom) {
|
|
|
|
for (var l in levels) {
|
|
|
|
var level = levels[l];
|
|
|
|
print('----------------------------');
|
|
|
|
print('Classroom:', classroom.name);
|
|
|
|
print('Members:', classroom.members.length);
|
|
|
|
print('Level:', level.name);
|
2016-02-11 15:32:59 -05:00
|
|
|
|
2016-02-19 16:13:45 -05:00
|
|
|
for (var i in classroom.members) {
|
|
|
|
var member = classroom.members[i];
|
|
|
|
var sessions = db.level.sessions.find({'level.original': level.original+'', 'creator': member+''}).toArray();
|
|
|
|
print(' user:', member);
|
|
|
|
for (var j in sessions) {
|
|
|
|
var session = sessions[j];
|
|
|
|
print(' session:', session._id, 'has language', session.codeLanguage);
|
|
|
|
if (session.codeLanguage === classroom.aceConfig.language) {
|
|
|
|
print(' all is well');
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
print(' updating language...');
|
|
|
|
print(' ', db.level.sessions.update({_id: session._id}, {$set: {codeLanguage: classroom.aceConfig.language}}));
|
|
|
|
}
|
|
|
|
}
|
2016-02-11 15:32:59 -05:00
|
|
|
}
|
2016-02-19 16:13:45 -05:00
|
|
|
});
|
|
|
|
|