diff --git a/core/server/data/importer/importers/data/posts.js b/core/server/data/importer/importers/data/posts.js index 5a98ad74f0..a0e7f0a555 100644 --- a/core/server/data/importer/importers/data/posts.js +++ b/core/server/data/importer/importers/data/posts.js @@ -185,8 +185,16 @@ class PostsImporter extends BaseImporter { // 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(); + + // CASE 1: you import a 1.0 export (amp field contains the correct disqus id) + // CASE 2: you import a 2.0 export (we have to ensure we use the original post id as disqus id) + if (model.id && model.amp) { + model.comment_id = model.amp; + delete model.amp; + } else { + if (!model.comment_id) { + model.comment_id = model.id; + } } }); diff --git a/core/server/data/schema/schema.js b/core/server/data/schema/schema.js index d63a722d41..2dc4b614c7 100644 --- a/core/server/data/schema/schema.js +++ b/core/server/data/schema/schema.js @@ -6,7 +6,7 @@ module.exports = { slug: {type: 'string', maxlength: 191, nullable: false, unique: true}, mobiledoc: {type: 'text', maxlength: 1000000000, fieldtype: 'long', nullable: true}, html: {type: 'text', maxlength: 1000000000, fieldtype: 'long', nullable: true}, - amp: {type: 'text', maxlength: 1000000000, fieldtype: 'long', nullable: true}, + comment_id: {type: 'string', maxlength: 50, nullable: true}, plaintext: {type: 'text', maxlength: 1000000000, fieldtype: 'long', nullable: true}, feature_image: {type: 'string', maxlength: 2000, nullable: true}, featured: {type: 'bool', nullable: false, defaultTo: false}, diff --git a/core/server/models/post.js b/core/server/models/post.js index 3e35fabddd..777cc45472 100644 --- a/core/server/models/post.js +++ b/core/server/models/post.js @@ -3,7 +3,6 @@ var _ = require('lodash'), uuid = require('uuid'), moment = require('moment'), Promise = require('bluebird'), - ObjectId = require('bson-objectid'), sequence = require('../lib/promise/sequence'), common = require('../lib/common'), htmlToText = require('html-to-text'), @@ -212,6 +211,12 @@ Post = ghostBookshelf.Model.extend({ })); } + if (options.method === 'insert') { + if (!this.get('comment_id')) { + this.set('comment_id', this.id); + } + } + // CASE: both page and post can get scheduled if (newStatus === 'scheduled') { if (!publishedAt) { @@ -455,9 +460,7 @@ Post = ghostBookshelf.Model.extend({ toJSON: function toJSON(unfilteredOptions) { var options = Post.filterOptions(unfilteredOptions, 'toJSON'), - attrs = ghostBookshelf.Model.prototype.toJSON.call(this, options), - oldPostId = attrs.amp, - commentId; + attrs = ghostBookshelf.Model.prototype.toJSON.call(this, options); attrs = this.formatsToJSON(attrs, options); @@ -475,28 +478,6 @@ Post = ghostBookshelf.Model.extend({ attrs.url = urlService.getUrlByResourceId(attrs.id); } - if (oldPostId) { - // CASE: You create a new post on 1.X, you enable disqus. You export your content, you import your content on a different instance. - // This time, the importer remembers your old post id in the amp field as ObjectId. - if (ObjectId.isValid(oldPostId)) { - commentId = oldPostId; - } else { - oldPostId = Number(oldPostId); - - // CASE: You import an old post id from your LTS blog. Stored in the amp field. - if (!isNaN(oldPostId)) { - commentId = oldPostId.toString(); - } else { - commentId = attrs.id; - } - } - } else { - commentId = attrs.id; - } - - // NOTE: we remember the old post id because of disqus - attrs.comment_id = commentId; - return attrs; }, enforcedFilters: function enforcedFilters(options) { @@ -510,7 +491,7 @@ Post = ghostBookshelf.Model.extend({ return options.context && options.context.public ? 'page:false' : 'page:false+status:published'; } }, { - allowedFormats: ['mobiledoc', 'html', 'plaintext', 'amp'], + allowedFormats: ['mobiledoc', 'html', 'plaintext'], orderDefaultOptions: function orderDefaultOptions() { return { diff --git a/core/test/functional/routes/api/posts_spec.js b/core/test/functional/routes/api/posts_spec.js index 486a331abe..988cbe7d45 100644 --- a/core/test/functional/routes/api/posts_spec.js +++ b/core/test/functional/routes/api/posts_spec.js @@ -81,7 +81,7 @@ describe('Post API', function () { }); it('can retrieve multiple post formats', function (done) { - request.get(testUtils.API.getApiQuery('posts/?formats=plaintext,mobiledoc,amp')) + request.get(testUtils.API.getApiQuery('posts/?formats=plaintext,mobiledoc')) .set('Authorization', 'Bearer ' + ownerAccessToken) .expect('Content-Type', /json/) .expect('Cache-Control', testUtils.cacheRules.private) @@ -96,7 +96,7 @@ describe('Post API', function () { should.exist(jsonResponse.posts); testUtils.API.checkResponse(jsonResponse, 'posts'); jsonResponse.posts.should.have.length(11); - testUtils.API.checkResponse(jsonResponse.posts[0], 'post', ['mobiledoc', 'plaintext', 'amp'], ['html']); + testUtils.API.checkResponse(jsonResponse.posts[0], 'post', ['mobiledoc', 'plaintext'], ['html']); testUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination'); _.isBoolean(jsonResponse.posts[0].featured).should.eql(true); _.isBoolean(jsonResponse.posts[0].page).should.eql(true); @@ -354,7 +354,7 @@ describe('Post API', function () { it('can retrieve multiple post formats', function (done) { request - .get(testUtils.API.getApiQuery('posts/' + testUtils.DataGenerator.Content.posts[0].id + '/?formats=plaintext,mobiledoc,amp')) + .get(testUtils.API.getApiQuery('posts/' + testUtils.DataGenerator.Content.posts[0].id + '/?formats=plaintext,mobiledoc')) .set('Authorization', 'Bearer ' + ownerAccessToken) .expect('Content-Type', /json/) .expect('Cache-Control', testUtils.cacheRules.private) @@ -370,7 +370,7 @@ describe('Post API', function () { jsonResponse.posts.should.have.length(1); jsonResponse.posts[0].id.should.equal(testUtils.DataGenerator.Content.posts[0].id); - testUtils.API.checkResponse(jsonResponse.posts[0], 'post', ['mobiledoc', 'plaintext', 'amp'], ['html']); + testUtils.API.checkResponse(jsonResponse.posts[0], 'post', ['mobiledoc', 'plaintext'], ['html']); done(); }); diff --git a/core/test/unit/data/schema/integrity_spec.js b/core/test/unit/data/schema/integrity_spec.js index 6c209fc4a0..7bd076e6de 100644 --- a/core/test/unit/data/schema/integrity_spec.js +++ b/core/test/unit/data/schema/integrity_spec.js @@ -19,7 +19,7 @@ var should = require('should'), */ describe('DB version integrity', function () { // Only these variables should need updating - var currentSchemaHash = '2073bee126f6e419ef86196f719caea6', + var currentSchemaHash = '22d24b1de23d118b90e9547fefae5ad7', currentFixturesHash = 'e4e64e97d509c61df818bf4d8e46c4c2'; // If this test is failing, then it is likely a change has been made that requires a DB version bump, diff --git a/core/test/utils/api.js b/core/test/utils/api.js index 0c3e243575..9792af2e34 100644 --- a/core/test/utils/api.js +++ b/core/test/utils/api.js @@ -21,9 +21,9 @@ var _ = require('lodash'), post: _(schema.posts) .keys() // by default we only return html - .without('mobiledoc', 'amp', 'plaintext') + .without('mobiledoc', 'plaintext') // swaps author_id to author, and always returns computed properties: url, comment_id, primary_tag, primary_author - .without('author_id').concat('author', 'url', 'comment_id', 'primary_tag', 'primary_author') + .without('author_id').concat('author', 'url', 'primary_tag', 'primary_author') .value(), user: { default: _(schema.users).keys().without('password').without('ghost_auth_access_token').value(),