Skip to content

Commit

Permalink
make it work with man-made exports
Browse files Browse the repository at this point in the history
  • Loading branch information
Etienne Laurent committed Oct 23, 2024
1 parent 5a25ea0 commit c146506
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions lib/methods/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,30 +258,32 @@ module.exports = self => {

// Get only the published docs and convert them into draft.
// If a doc is a draft and has no published version, we keep it.
// If a doc has no aposMode, we keep it.
getPublishedDocsAsDraft(docs) {
return docs
.filter(isPublishedOrDraftAlone)
.map(convertToDraft);

function isPublishedOrDraftAlone(doc) {
return doc.aposMode === 'published' ||
(
doc.aposMode === 'draft' &&
!docs.find(item => item.aposDocId === doc.aposDocId && item.aposMode === 'published')
);
// i.e "is draft without a published version"
const isDraftAlone =
doc.aposMode === 'draft' &&
!docs.find(item => item.aposDocId === doc.aposDocId && item.aposMode === 'published');

return !doc.aposMode || doc.aposMode === 'published' || isDraftAlone;
}

function convertToDraft(doc) {
if (doc.aposMode === 'draft') {
return doc;
if (doc.aposMode === 'published') {
return {
...doc,
_id: doc._id?.replace('published', 'draft'),
aposLocale: doc.aposLocale?.replace('published', 'draft'),
aposMode: 'draft'
};
}

return {
...doc,
_id: doc._id.replace('published', 'draft'),
aposLocale: doc.aposLocale.replace('published', 'draft'),
aposMode: 'draft'
};
return doc;
}
},

Expand Down

0 comments on commit c146506

Please sign in to comment.