From 02bd71d0f5ac853bb307e3030d70394534556d95 Mon Sep 17 00:00:00 2001 From: kirrg001 Date: Wed, 3 Jan 2018 00:07:41 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=20Fixed=20importer=20duplicate?= =?UTF-8?q?=20detection=20for=20posts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes #8717 - this is now required, because we run import queries sequentiell - this code protects two cases: - you have duplicate slugs in the JSON file (the first get's inserted, the second get's ignored) - you have an existing slug in the database and you try to import the same slug, get's ignored --- core/server/data/importer/importers/data/index.js | 1 + core/server/models/base/index.js | 6 ++++++ core/test/integration/data/importer/importers/data_spec.js | 2 ++ 3 files changed, 9 insertions(+) diff --git a/core/server/data/importer/importers/data/index.js b/core/server/data/importer/importers/data/index.js index 3fbe61e2c3..4d3a93bc68 100644 --- a/core/server/data/importer/importers/data/index.js +++ b/core/server/data/importer/importers/data/index.js @@ -42,6 +42,7 @@ DataImporter = { if (importOptions && importOptions.importPersistUser) { modelOptions.importPersistUser = importOptions.importPersistUser; } + this.init(importData); return models.Base.transaction(function (transacting) { diff --git a/core/server/models/base/index.js b/core/server/models/base/index.js index 4c34db16c6..ecfb243707 100644 --- a/core/server/models/base/index.js +++ b/core/server/models/base/index.js @@ -774,6 +774,12 @@ ghostBookshelf.Model = ghostBookshelf.Model.extend({ if (!slug) { slug = baseName; } + + // CASE: no slug generation on import, see https://github.com/TryGhost/Ghost/issues/8717 + if (options.importing) { + return slug; + } + // Test for duplicate slugs. return checkIfSlugExists(slug); }); diff --git a/core/test/integration/data/importer/importers/data_spec.js b/core/test/integration/data/importer/importers/data_spec.js index fad272df02..cd88e5df14 100644 --- a/core/test/integration/data/importer/importers/data_spec.js +++ b/core/test/integration/data/importer/importers/data_spec.js @@ -394,6 +394,8 @@ describe('Import', function () { exportData = exported; return dataImporter.doImport(exportData); }).then(function (importedData) { + importedData.data.posts.length.should.eql(1); + importedData.problems.length.should.eql(3); importedData.problems[0].message.should.eql('Entry was not imported and ignored. Detected duplicated entry.'); importedData.problems[0].help.should.eql('Tag');