From a43ab8445d8caf2425821cd0317cc0264735fc76 Mon Sep 17 00:00:00 2001 From: Matt Hanley Date: Fri, 6 May 2022 16:18:56 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fixed=20importing=20posts=20with?= =?UTF-8?q?=20a=20newsletter=20assigned?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit refs https://github.com/TryGhost/Team/issues/1595 - Since adding multiple newsletters, posts may be linked to a related newsletter - We don't export newsletters, so the related newsletter_id doesn't exist and fails the FK check on import --- core/server/data/importer/importers/data/posts.js | 5 +++++ .../data/importer/importers/data/posts.test.js | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/core/server/data/importer/importers/data/posts.js b/core/server/data/importer/importers/data/posts.js index b751f16561..bf9f2fff1e 100644 --- a/core/server/data/importer/importers/data/posts.js +++ b/core/server/data/importer/importers/data/posts.js @@ -6,6 +6,7 @@ const mobiledocLib = require('../../../../lib/mobiledoc'); const validator = require('@tryghost/validator'); const postsMetaSchema = require('../../../schema').tables.posts_meta; const metaAttrs = _.keys(_.omit(postsMetaSchema, ['id'])); +const ignoredColumns = ['newsletter_id']; class PostsImporter extends BaseImporter { constructor(allDataFromFile) { @@ -42,6 +43,10 @@ class PostsImporter extends BaseImporter { } delete obj.send_email_when_published; } + + ignoredColumns.forEach((column) => { + delete obj[column]; + }); }); } diff --git a/test/unit/server/data/importer/importers/data/posts.test.js b/test/unit/server/data/importer/importers/data/posts.test.js index abfb454ea4..92264bb9dc 100644 --- a/test/unit/server/data/importer/importers/data/posts.test.js +++ b/test/unit/server/data/importer/importers/data/posts.test.js @@ -87,5 +87,20 @@ describe('PostsImporter', function () { should.exist(pageTrueTypePost); pageTrueTypePost.type.should.equal('post', 'pageTrueTypePost.type'); }); + + it('Removes the newsletter_id column', function () { + const fakePosts = [{ + slug: 'post-with-newsletter', + newsletter_id: 'bananas' + }]; + + const importer = new PostsImporter({posts: fakePosts}); + + importer.beforeImport(); + + const postWithoutNewsletter = find(importer.dataToImport, {slug: 'post-with-newsletter'}); + should.exist(postWithoutNewsletter); + should.not.exist(postWithoutNewsletter.newsletter_id); + }); }); });