0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

🐛 Fixed duplication error when importing posts without slugs

refs #8717

-  The posts without slugs should not be taken into account when detecting duplicates as slug field is not required when importing.
- Ideal solution would require generating slug before duplicate detection phase. This would cause duplicate detection to take 'title' into account which didn't happen before.
This commit is contained in:
Nazar Gargol 2019-08-09 12:53:20 +02:00 committed by Hannah Wolfe
parent e89a2074b8
commit 3bd3570592
2 changed files with 26 additions and 1 deletions

View file

@ -200,7 +200,7 @@ class PostsImporter extends BaseImporter {
// For any further future duplication detection, see https://github.com/TryGhost/Ghost/issues/8717.
let slugs = [];
this.dataToImport = _.filter(this.dataToImport, (post) => {
if (slugs.indexOf(post.slug) !== -1) {
if (!!post.slug && slugs.indexOf(post.slug) !== -1) {
this.problems.push({
message: 'Entry was not imported and ignored. Detected duplicated entry.',
help: this.modelName,

View file

@ -252,6 +252,31 @@ describe('Integration: Importer', function () {
});
});
it('does not treat posts without slug as duplicate', function () {
let exportData = exportedLatestBody().db[0];
exportData.data.posts[0] = {
title: "duplicate title"
};
exportData.data.posts[1] = {
title: "duplicate title"
};
return dataImporter.doImport(exportData, importOptions)
.then(function (importResult) {
should.exist(importResult.data.posts);
importResult.data.posts.length.should.equal(2);
importResult.problems.length.should.eql(0);
importResult.data.posts[0].title.should.equal('duplicate title');
importResult.data.posts[1].title.should.equal('duplicate title');
importResult.data.posts[0].slug.should.equal('duplicate-title');
importResult.data.posts[1].slug.should.equal('duplicate-title-2');
});
});
it('can import user with missing allowed fields', function () {
let exportData = exportedLatestBody().db[0];