Skip to content

Commit

Permalink
Use the correct IDs for doc._id and doc.internalId
Browse files Browse the repository at this point in the history
  • Loading branch information
alxndrsn committed Jun 2, 2017
1 parent 052d4aa commit 4b7e973
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "medic-configurer-beta",
"version": "1.0.41",
"version": "1.0.42",
"description": "Configure Medic Mobile deployments",
"main": "index.js",
"scripts": {
Expand Down
17 changes: 10 additions & 7 deletions src/lib/upload-forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,20 @@ module.exports = (project, couchUrl, subDirectory, options) => {
const baseFileName = fs.withoutExtension(fileName);
const mediaDir = `${formsDir}/${baseFileName}-media`;
const xformPath = `${formsDir}/${baseFileName}.xml`;
const expectedId = (options.id_prefix || '') + baseFileName.replace(/-/g, ':');
const baseDocId = (options.id_prefix || '') + baseFileName.replace(/-/g, ':');

if(!fs.exists(mediaDir)) info(`No media directory found at ${mediaDir} for form ${xformPath}`);

const xml = fs.read(xformPath);

const id = readIdFrom(xml);
if(id !== expectedId) warn('DEPRECATED', 'Form:', fileName, '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 internalId = readIdFrom(xml);
if(internalId !== baseDocId) warn('DEPRECATED', 'Form:', fileName, 'Bad ID set in XML. Expected:', baseDocId, 'but saw:', internalId, ' Support for setting these values differently will be dropped. Please see https://github.com/medic/medic-webapp/issues/3342.');

const docId = `form:${baseDocId}`;
const doc = {
_id: `form:${id}`,
_id: docId,
type: 'form',
internalId: id,
internalId: internalId,
title: readTitleFrom(xml),
};

Expand All @@ -46,10 +47,12 @@ module.exports = (project, couchUrl, subDirectory, options) => {
doc._attachments = fs.exists(mediaDir) ? attachmentsFromDir(mediaDir) : {};
doc._attachments.xml = attachmentFromFile(xformPath);

const docUrl = `${couchUrl}/${docId}`;

return Promise.resolve()
.then(() => trace('Uploading form', `${formsDir}/${fileName}`, 'to', id))
.then(() => trace('Uploading form', `${formsDir}/${fileName}`, 'to', docUrl))
.then(() => insertOrReplace(db, doc))
.then(() => info('Uploaded form', `${formsDir}/${fileName}`, 'to', id));
.then(() => info('Uploaded form', `${formsDir}/${fileName}`, 'to', docUrl));
}));
};

Expand Down

0 comments on commit 4b7e973

Please sign in to comment.