closed #733 - after upgrade script, all users will be in a system "registered users" group

v1.18.x
Julian Lam 11 years ago
parent 619fe74fc0
commit 97cc6cde67

@ -7,6 +7,7 @@ var db = require('./database'),
User = require('./user'),
Topics = require('./topics'),
Posts = require('./posts'),
Groups = require('./groups'),
Utils = require('../public/src/utils'),
Upgrade = {},
@ -15,7 +16,7 @@ var db = require('./database'),
Upgrade.check = function(callback) {
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema
var latestSchema = new Date(2014, 0, 7).getTime();
var latestSchema = new Date(2014, 0, 13, 12, 0).getTime();
db.get('schemaDate', function(err, value) {
if (parseInt(value, 10) >= latestSchema) {
@ -198,7 +199,7 @@ Upgrade.upgrade = function(callback) {
async.each(cids, upgradeCategory, function(err) {
if(err) {
return next(err)
return next(err);
}
winston.info('[2014/1/5] Upgraded categories active users');
next();
@ -246,7 +247,7 @@ Upgrade.upgrade = function(callback) {
});
});
}
})
});
} else {
winston.info('[2014/1/5] Re-slugify usernames (again) skipped');
next();
@ -275,7 +276,7 @@ Upgrade.upgrade = function(callback) {
}
db.delete('uid:' + uid + ':posts', function(err) {
for(var i = 0; i< pids.length; ++i) {
for(var i = 0; i< pids.length; ++i) {
addPostToUser(pids[i]);
}
next();
@ -301,7 +302,7 @@ Upgrade.upgrade = function(callback) {
}
db.delete('uid:' + uid + ':topics', function(err) {
for(var i = 0; i< tids.length; ++i) {
for(var i = 0; i< tids.length; ++i) {
addTopicToUser(tids[i]);
}
next();
@ -344,7 +345,7 @@ Upgrade.upgrade = function(callback) {
}
db.delete('tid:' + tid + ':posts', function(err) {
for(var i = 0; i< pids.length; ++i) {
for(var i = 0; i< pids.length; ++i) {
addPostToTopic(pids[i]);
}
next();
@ -377,6 +378,30 @@ Upgrade.upgrade = function(callback) {
winston.info('[2014/1/7] Update to topic and user posts to sorted set skipped');
next();
}
},
function(next) {
thisSchemaDate = new Date(2014, 0, 13, 12, 0).getTime();
if (schemaDate < thisSchemaDate) {
updatesMade = true;
db.getObjectValues('username:uid', function(err, uids) {
console.log(uids);
async.eachSeries(uids, function(uid, next) {
Groups.joinByGroupName('registered-users', uid, next);
}, function(err) {
if(err) {
winston.err('Error upgrading '+ err.message);
process.exit();
} else {
winston.info('[2014/1/13] Set up "Registered Users" user group');
next();
}
});
});
} else {
winston.info('[2014/1/13] Set up "Registered Users" user group - skipped');
next();
}
}
// Add new schema updates here
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema IN LINE 17!!!

@ -114,6 +114,9 @@ var bcrypt = require('bcrypt'),
db.searchIndex('user', username, uid);
// Join the "registered-users" meta group
groups.joinByGroupName('registered-users', uid);
if (password !== undefined) {
User.hashPassword(password, function(err, hash) {
User.setUserField(uid, 'password', hash);

Loading…
Cancel
Save