Skip to content

Commit

Permalink
🐛 only save imported post ids if amp field is empty
Browse files Browse the repository at this point in the history
closes TryGhost#8963
- if an LTS export is imported into a 1.0 blog, then the 1.0 blog is
exported and re-imported into another 1.0 blog, any post ids from the
lts import were getting clobbered. This only saves the post id if the
amp field does not already exist
- add failing test that passes w/change
  • Loading branch information
acburdine committed Sep 2, 2017
1 parent 2ecf06d commit fce3bd9
Show file tree
Hide file tree
Showing 3 changed files with 1,564 additions and 1 deletion.
5 changes: 4 additions & 1 deletion core/server/data/importer/importers/data/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ class PostsImporter extends BaseImporter {
}

// NOTE: we remember the old post id for disqus
if (model.id) {
// We also check if amp already exists to prevent
// overwriting any comment ids from a 1.0 export
// (see https://github.com/TryGhost/Ghost/issues/8963)
if (model.id && !model.amp) {
model.amp = model.id.toString();
}
});
Expand Down
28 changes: 28 additions & 0 deletions core/test/integration/data/importer/importers/data_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1450,6 +1450,8 @@ describe('Import (new test structure)', function () {

// Check post language is null
should(firstPost.locale).equal(null);
// Check post id has been inserted into amp column
should(firstPost.amp).equal(exportData.data.posts[0].id.toString());
// Check user language is null
should(users[1].locale).equal(null);

Expand Down Expand Up @@ -1658,4 +1660,30 @@ describe('Import (new test structure)', function () {
}).catch(done);
});
});

describe('1.0: basic import test', function () {
var exportData;

before(function doImport() {
// initialize the blog with some data
return testUtils.initFixtures('roles', 'owner', 'settings').then(function () {
return testUtils.fixtures.loadExportFixture('export-basic-test');
}).then(function (exported) {
exportData = exported.db[0];
return dataImporter.doImport(exportData);
});
});

after(testUtils.teardown);

it('keeps the value of the amp field', function () {
return knex('posts').select().then(function (posts) {
should.exist(posts);

posts.length.should.eql(exportData.data.posts.length);
posts[0].amp.should.eql(exportData.data.posts[0].amp);
posts[1].amp.should.eql(exportData.data.posts[1].id);
});
});
});
});
Loading

0 comments on commit fce3bd9

Please sign in to comment.