🐛 Fixed importer duplicate detection for posts

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
This commit is contained in:
kirrg001 2018-01-03 00:07:41 +01:00
parent 29e143fa9a
commit 02bd71d0f5
3 changed files with 9 additions and 0 deletions

View File

@ -42,6 +42,7 @@ DataImporter = {
if (importOptions && importOptions.importPersistUser) { if (importOptions && importOptions.importPersistUser) {
modelOptions.importPersistUser = importOptions.importPersistUser; modelOptions.importPersistUser = importOptions.importPersistUser;
} }
this.init(importData); this.init(importData);
return models.Base.transaction(function (transacting) { return models.Base.transaction(function (transacting) {

View File

@ -774,6 +774,12 @@ ghostBookshelf.Model = ghostBookshelf.Model.extend({
if (!slug) { if (!slug) {
slug = baseName; 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. // Test for duplicate slugs.
return checkIfSlugExists(slug); return checkIfSlugExists(slug);
}); });

View File

@ -394,6 +394,8 @@ describe('Import', function () {
exportData = exported; exportData = exported;
return dataImporter.doImport(exportData); return dataImporter.doImport(exportData);
}).then(function (importedData) { }).then(function (importedData) {
importedData.data.posts.length.should.eql(1);
importedData.problems.length.should.eql(3); importedData.problems.length.should.eql(3);
importedData.problems[0].message.should.eql('Entry was not imported and ignored. Detected duplicated entry.'); importedData.problems[0].message.should.eql('Entry was not imported and ignored. Detected duplicated entry.');
importedData.problems[0].help.should.eql('Tag'); importedData.problems[0].help.should.eql('Tag');