diff --git a/ghost/core/core/server/data/importer/importers/data/data-importer.js b/ghost/core/core/server/data/importer/importers/data/data-importer.js index a0c8aac09b..c80f3e895d 100644 --- a/ghost/core/core/server/data/importer/importers/data/data-importer.js +++ b/ghost/core/core/server/data/importer/importers/data/data-importer.js @@ -47,7 +47,7 @@ DataImporter = { doImport: async function doImport(importData, importOptions) { importOptions = importOptions || {}; - if (importOptions.importTag) { + if (importOptions.importTag && importData?.data?.posts) { const tagId = ObjectId().toHexString(); if (!('tags' in importData.data)) { importData.data.tags = []; @@ -60,7 +60,7 @@ DataImporter = { if (!('posts_tags' in importData.data)) { importData.data.posts_tags = []; } - for (const post of importData.data.posts || []) { + for (const post of importData.data.posts) { if (!('id' in post)) { // Make sure post has an id if it doesn't already post.id = ObjectId().toHexString(); diff --git a/ghost/core/test/unit/server/data/importer/index.test.js b/ghost/core/test/unit/server/data/importer/index.test.js index de457f848c..794daed55a 100644 --- a/ghost/core/test/unit/server/data/importer/index.test.js +++ b/ghost/core/test/unit/server/data/importer/index.test.js @@ -401,7 +401,7 @@ describe('Importer', function () { imageSpy.getCall(0).args[0].should.eql(expectedImages); // we stubbed this as a noop but ImportManager calls with sequence, so we should get an array - output.should.eql([expectedImages, expectedData]); + output.should.eql({images: expectedImages, data: expectedData}); done(); }).catch(done); });