Skip to content

Instantly share code, notes, and snippets.

@jimmed
Created July 10, 2013 19:38
Show Gist options
  • Save jimmed/5969515 to your computer and use it in GitHub Desktop.
Save jimmed/5969515 to your computer and use it in GitHub Desktop.
Signup Form Migration
/*
* Self_configs migration tool
* ==
* 1. Visit the site you wish to migrate.
* 2. Run this script in the Chrome/Firebug console
* 3. You will receive some delicious SQL to run on your customer DB
*/
(function(undefined) {
console.info('Calling APIs...');
$.when(
FS.API.get('self-homepagecontent'),
FS.API.get('/domain/' + window.location.hostname),
FS.API.get('self-autologout'),
FS.API.get('self-signupform'),
FS.API.get('getcoaformid')
)
.then(
function transformResult(hcResult, dResult, auResult, signupResult, coaResult) {
console.info('\tResponses received');
var homepageContent = hcResult[0] || {},
domain = dResult[0] || {},
autologout = auResult[0] || {},
signup = signupResult[0] || {},
coa = coaResult[0] || {};
return {
SiteTitle: domain.name || 'Self',
SiteLogo: (domain.logo || {}).url,
HomepageAnon: homepageContent.anon,
HomepageAuth: homepageContent.auth,
Footer: homepageContent.footer,
HeaderExtension: homepageContent.header,
AutoLogout: autologout.idleSeconds || 0,
SignupFormId: signup.form_id || '',
SignupFormTitle: signup.link || 'Services signup unavailable',
ChangeOfAddress: coa.coaFormId || ''
};
}
)
.then(
function generateSql(config) {
console.info('Generating SQL...');
return _.flatten([
'INSERT INTO `self_configs` ',
'(`Name`, `Value`) ',
'VALUES (',
_.map(config, function(value, key) {
return _.map([key, value || ''], JSON.stringify)
.join(', ');
}).join('),('),
');'
]).join('');
}
)
.then(
function outputConfiguration(sql) {
console.info('Finished!');
console.info(sql);
}
);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment