mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Fixed import test: post duplication detection within a file to import
no issue
- with 29e143fa9a
import queries no longer run in parallel
- this commit simply adds a small code snippet to reflect the importer behaviour
1) duplicate slugs *within* a file are getting ignored
2) existing posts in the database and posts to import with the same slug, result in duplicates
Further improvements regarding duplication detection will happen via #8717.
This commit is contained in:
parent
428008e63d
commit
eb0a11d53a
3 changed files with 25 additions and 1 deletions
|
@ -147,6 +147,26 @@ class PostsImporter extends BaseImporter {
|
|||
}
|
||||
});
|
||||
|
||||
// NOTE: We only support removing duplicate posts within the file to import.
|
||||
// For any further future duplication detection, see https://github.com/TryGhost/Ghost/issues/8717.
|
||||
let slugs = [];
|
||||
this.dataToImport = _.filter(this.dataToImport, function (post) {
|
||||
if (slugs.indexOf(post.slug) !== -1) {
|
||||
self.problems.push({
|
||||
message: 'Entry was not imported and ignored. Detected duplicated entry.',
|
||||
help: self.modelName,
|
||||
context: JSON.stringify({
|
||||
post: post
|
||||
})
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
slugs.push(post.slug);
|
||||
return true;
|
||||
});
|
||||
|
||||
// NOTE: do after, because model properties are deleted e.g. post.id
|
||||
return super.beforeImport();
|
||||
}
|
||||
|
|
|
@ -31,6 +31,8 @@ class TagsImporter extends BaseImporter {
|
|||
* - the tag model is smart enough to regenerate unique fields
|
||||
* - so if you import a tag name "test" and the same tag name exists, it would add "test-2"
|
||||
* - that's we add a protection here to first find the tag
|
||||
*
|
||||
* @TODO: Add a flag to the base implementation e.g. `fetchBeforeAdd`
|
||||
*/
|
||||
doImport(options) {
|
||||
debug('doImport', this.modelName, this.dataToImport.length);
|
||||
|
|
|
@ -387,13 +387,15 @@ describe('Import', function () {
|
|||
}).catch(done);
|
||||
});
|
||||
|
||||
it('handles database errors nicely: duplicated tag slugs', function (done) {
|
||||
it('handles database errors nicely: duplicated tag and posts slugs', function (done) {
|
||||
var exportData;
|
||||
|
||||
testUtils.fixtures.loadExportFixture('export-003-dbErrors', {lts:true}).then(function (exported) {
|
||||
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');
|
||||
|
|
Loading…
Add table
Reference in a new issue