Skip to content

Instantly share code, notes, and snippets.

@atlc
Last active February 22, 2020 02:38
Show Gist options
  • Save atlc/069a7fc5e4274aed39bee06092ffa064 to your computer and use it in GitHub Desktop.
Save atlc/069a7fc5e4274aed39bee06092ffa064 to your computer and use it in GitHub Desktop.
IIFE that pulls the firmID and support status from the admin console, to create a SQL statement to import into the new database
(function() {
let users = [...$('#usersTable')[0].firstElementChild.children];
users.splice(0,1);
let queryString = "INSERT INTO users (firmid, password, onSupport) values ";
function parseBoolFrom(text) { return text === "Yes" ? true : false; }
users.forEach(usr => {
firmId = usr.firstElementChild.innerText;
supportStatus = parseBoolFrom(usr.children[1].firstElementChild.firstElementChild.innerText);
// Same hash since we're enforcing all clients to reset upon first login
queryString += ` ("${firmId}", "c837c635e514468b3de70ab83ac221a2", ${supportStatus}),`;
});
queryString = queryString.replace(/,$/,";");
function copyToClipboard(text) {
let tempElement = document.createElement("textarea");
document.body.appendChild(tempElement);
tempElement.value = text;
tempElement.select();
document.execCommand("copy");
tempElement.parentNode.removeChild(tempElement);
}
if (confirm(`Copy to clipboard?\n\n${queryString}`)) {
copyToClipboard(queryString);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment