-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'remotes/Alys/eyewear1' into develop
Conflicts: database_reports/count_users_who_own_specified_gear.js
- Loading branch information
Showing
5 changed files
with
97 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// node .migrations/20140829_change_headAccessory_to_eyewear.js | ||
|
||
var migrationName = '20140829_change_headAccessory_to_eyewear'; | ||
var authorName = 'Alys'; // in case script author needs to know when their ... | ||
var authorUuid = 'd904bd62-da08-416b-a816-ba797c9ee265'; //... own data is done | ||
|
||
/** | ||
* https://github.com/HabitRPG/habitrpg/issues/3645 | ||
*/ | ||
var mongo = require('mongoskin'); | ||
var _ = require('lodash'); | ||
|
||
|
||
/////////////////// UNCOMMENT *ONE* OF THESE LINES: /////////////////// | ||
// var liveUsers = mongo.db('lefnire:[email protected]:10015/habitrpg_large?auto_reconnect').collection('users'); // @lefnire production? | ||
// var liveUsers = mongo.db('localhost:27017/habitrpg_old?auto_reconnect').collection('users'); // @lefnire habitrpg_old | ||
// var liveUsers = mongo.db('localhost:27017/habitrpg?auto_reconnect').collection('users'); // for local testing by script author (e.g., vagrant install) | ||
|
||
|
||
var fields = {'migration':1, | ||
'items.gear.costume.headAccessory':1, | ||
'items.gear.equipped.headAccessory':1, | ||
'items.gear.owned.headAccessory_special_wondercon_black':1, | ||
'items.gear.owned.headAccessory_special_wondercon_red':1, | ||
'items.gear.owned.headAccessory_special_summerRogue':1, | ||
'items.gear.owned.headAccessory_special_summerWarrior':1 | ||
}; | ||
|
||
var progressCount = 1000; | ||
var count = 0; | ||
liveUsers.findEach({ $and: [ | ||
{ migration: {$ne:migrationName} }, | ||
{ $or: [ | ||
{'items.gear.owned.headAccessory_special_summerRogue': {'$exists':true}}, | ||
{'items.gear.owned.headAccessory_special_summerWarrior':{'$exists':true}}, | ||
{'items.gear.owned.headAccessory_special_wondercon_red':{'$exists':true}}, | ||
{'items.gear.owned.headAccessory_special_wondercon_black':{'$exists':true}} | ||
]} | ||
]}, fields, {batchSize:250}, function(err, user){ | ||
count++; | ||
if (!user) err = '!user'; | ||
if (err) {return console.error(err);} | ||
|
||
var set = {'migration': migrationName}; | ||
var unset = {}; | ||
|
||
var oldToNew = { | ||
'headAccessory_special_summerRogue': 'eyewear_special_summerRogue', | ||
'headAccessory_special_summerWarrior': 'eyewear_special_summerWarrior', | ||
'headAccessory_special_wondercon_red': 'eyewear_special_wondercon_red', | ||
'headAccessory_special_wondercon_black':'eyewear_special_wondercon_black' | ||
}; | ||
|
||
// items.gear.costume, items.gear.equipped: | ||
_.each(['costume','equipped'],function(type){ | ||
_.each(oldToNew,function(newName,oldName){ | ||
if (user.items.gear[type].headAccessory === oldName) { | ||
unset['items.gear.'+type+'.headAccessory'] = ""; | ||
set['items.gear.'+type+'.eyewear'] = newName; | ||
} | ||
}); | ||
}); | ||
|
||
// items.gear.owned: | ||
_.each(oldToNew,function(newName,oldName){ | ||
if (oldName in user.items.gear.owned) { | ||
unset['items.gear.owned.'+oldName] = ""; | ||
set['items.gear.owned.'+newName] = user.items.gear.owned[oldName]; | ||
} | ||
}); | ||
|
||
//console.log(JSON.stringify(user, null, " ")); | ||
//console.log("set: " + JSON.stringify(set, null, " ")); | ||
//console.log("unset: " + JSON.stringify(unset, null, " ")); | ||
|
||
liveUsers.update({_id:user._id}, {$unset:unset, $inc:{_v:1}}); | ||
liveUsers.update({_id:user._id}, {$set:set, $inc:{_v:1}}); | ||
|
||
if (count%progressCount == 0) console.log(count + ' ' + user._id); | ||
if (user._id == '9') console.log('lefnire processed'); | ||
if (user._id == authorUuid) console.log(authorName + ' processed'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters