Skip to content

Commit

Permalink
Read form ID from XML
Browse files Browse the repository at this point in the history
  • Loading branch information
alxndrsn committed May 31, 2017
1 parent 255ba7b commit 24b27c0
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/fn/upload-forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = (project, couchUrl) => {

const xml = fs.read(`${formDir}/xml`);

const id = expectedId; // TODO read this name from the form XML
const id = readIdFrom(xml);
if(id !== expectedId) warn('DEPRECATED', 'Form:', xls, 'Bad ID set in XML. Expected:', expectedId, 'but saw:', id, ' Support for setting these values differently will be dropped. Please see https://github.com/medic/medic-webapp/issues/3342.');

const doc = {
Expand Down Expand Up @@ -54,3 +54,8 @@ module.exports = (project, couchUrl) => {

// TODO this isn't really how to parse XML
const readTitleFrom = xml => xml.substring(xml.indexOf('<h:title>') + 9, xml.indexOf('</h:title>'));
const readIdFrom = xml =>
xml.split('\n').join('')
.match(/<model>.*<\/model>/)[0]
.match(/<instance>.*<\/instance>/)[0]
.match(/id="([^"]*)"/)[1];

0 comments on commit 24b27c0

Please sign in to comment.