Last active
August 29, 2015 14:04
-
-
Save pajtai/09e63afc50c05fd340e8 to your computer and use it in GitHub Desktop.
gh core user migration to using identities
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
/* jshint node:true */ | |
'use strict'; | |
var _ = require('lodash'), | |
fs = require('fs'); | |
migrateUsers(); | |
migrateContentTypes(); | |
function migrateUsers() { | |
var files = fs.readdirSync('./fixtures/grasshopper/users'); | |
console.log('======= Migrating Users ======='); | |
_.each(files, function(fileName) { | |
var fileJSON = fs.readFileSync('./fixtures/grasshopper/users/'+ fileName), | |
fileData = JSON.parse(fileJSON); | |
fileData.identities = { | |
basic : {} | |
}; | |
fileData.displayName = fileData.login; | |
fileData.linkedIdentities = ['basic']; | |
fileData.identities.basic.username = fileData.login; | |
delete fileData.login; | |
fileData.identities.basic.hash = fileData.pass_hash; | |
delete fileData.pass_hash; | |
fileData.identities.basic.salt = fileData.salt; | |
delete fileData.salt; | |
fs.writeFileSync('./fixtures/grasshopper/users/'+ fileName, JSON.stringify(fileData, null, 4)); | |
}); | |
} | |
function migrateContentTypes() { | |
var files = fs.readdirSync('./fixtures/grasshopper/contenttypes'); | |
console.log('======= Migrating ContentTypes ======='); | |
_.each(files, function(fileName) { | |
var fileJSON = fs.readFileSync('./fixtures/grasshopper/contenttypes/'+ fileName), | |
fileData = JSON.parse(fileJSON); | |
_.each(fileData.fields, function(field) { | |
if(_.has(field, 'validation') && _.isArray(field.validation)) { | |
_.each(field.validation, function(validation) { | |
validation.type = validation._id; | |
delete validation._id; | |
}); | |
} | |
}); | |
fs.writeFileSync('./fixtures/grasshopper/contenttypes/'+ fileName, JSON.stringify(fileData, null, 4)); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment