mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-01 13:54:35 +03:00
🐛 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:
parent
29e143fa9a
commit
02bd71d0f5
@ -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) {
|
||||||
|
@ -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);
|
||||||
});
|
});
|
||||||
|
@ -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');
|
||||||
|
Loading…
Reference in New Issue
Block a user