0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00

Renamed amp post column to column_id

refs 9742

- when we've introduced Ghost 1.0, we have noticed that we broke Disqus comments
- Disqus comments use a unique identifier, which is the post id
- that means if you have exported your LTS content and imported it into 1.0, all resource identifiers are regenerated
- but the Disqus must use the original post resource id
- that's why we have imported the old post id and remembered it in the `amp` field 🤠
- that was the only field which was available and un-used
- now in Ghost 2.0, we would like to rename the `amp` field to `comment_id`
- string length: 50 (i thought it might be safer to not use 24 characters, because who knows if support other comment id's in the future)
This commit is contained in:
kirrg001 2018-07-19 11:35:55 +02:00 committed by Katharina Irrgang
parent f6a45b6ade
commit 7db0739296
6 changed files with 26 additions and 37 deletions

View file

@ -185,8 +185,16 @@ class PostsImporter extends BaseImporter {
// We also check if amp already exists to prevent // We also check if amp already exists to prevent
// overwriting any comment ids from a 1.0 export // overwriting any comment ids from a 1.0 export
// (see https://github.com/TryGhost/Ghost/issues/8963) // (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;
}
} }
}); });

View file

@ -6,7 +6,7 @@ module.exports = {
slug: {type: 'string', maxlength: 191, nullable: false, unique: true}, slug: {type: 'string', maxlength: 191, nullable: false, unique: true},
mobiledoc: {type: 'text', maxlength: 1000000000, fieldtype: 'long', nullable: true}, mobiledoc: {type: 'text', maxlength: 1000000000, fieldtype: 'long', nullable: true},
html: {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}, plaintext: {type: 'text', maxlength: 1000000000, fieldtype: 'long', nullable: true},
feature_image: {type: 'string', maxlength: 2000, nullable: true}, feature_image: {type: 'string', maxlength: 2000, nullable: true},
featured: {type: 'bool', nullable: false, defaultTo: false}, featured: {type: 'bool', nullable: false, defaultTo: false},

View file

@ -3,7 +3,6 @@ var _ = require('lodash'),
uuid = require('uuid'), uuid = require('uuid'),
moment = require('moment'), moment = require('moment'),
Promise = require('bluebird'), Promise = require('bluebird'),
ObjectId = require('bson-objectid'),
sequence = require('../lib/promise/sequence'), sequence = require('../lib/promise/sequence'),
common = require('../lib/common'), common = require('../lib/common'),
htmlToText = require('html-to-text'), 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 // CASE: both page and post can get scheduled
if (newStatus === 'scheduled') { if (newStatus === 'scheduled') {
if (!publishedAt) { if (!publishedAt) {
@ -455,9 +460,7 @@ Post = ghostBookshelf.Model.extend({
toJSON: function toJSON(unfilteredOptions) { toJSON: function toJSON(unfilteredOptions) {
var options = Post.filterOptions(unfilteredOptions, 'toJSON'), var options = Post.filterOptions(unfilteredOptions, 'toJSON'),
attrs = ghostBookshelf.Model.prototype.toJSON.call(this, options), attrs = ghostBookshelf.Model.prototype.toJSON.call(this, options);
oldPostId = attrs.amp,
commentId;
attrs = this.formatsToJSON(attrs, options); attrs = this.formatsToJSON(attrs, options);
@ -475,28 +478,6 @@ Post = ghostBookshelf.Model.extend({
attrs.url = urlService.getUrlByResourceId(attrs.id); 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; return attrs;
}, },
enforcedFilters: function enforcedFilters(options) { enforcedFilters: function enforcedFilters(options) {
@ -510,7 +491,7 @@ Post = ghostBookshelf.Model.extend({
return options.context && options.context.public ? 'page:false' : 'page:false+status:published'; return options.context && options.context.public ? 'page:false' : 'page:false+status:published';
} }
}, { }, {
allowedFormats: ['mobiledoc', 'html', 'plaintext', 'amp'], allowedFormats: ['mobiledoc', 'html', 'plaintext'],
orderDefaultOptions: function orderDefaultOptions() { orderDefaultOptions: function orderDefaultOptions() {
return { return {

View file

@ -81,7 +81,7 @@ describe('Post API', function () {
}); });
it('can retrieve multiple post formats', function (done) { 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) .set('Authorization', 'Bearer ' + ownerAccessToken)
.expect('Content-Type', /json/) .expect('Content-Type', /json/)
.expect('Cache-Control', testUtils.cacheRules.private) .expect('Cache-Control', testUtils.cacheRules.private)
@ -96,7 +96,7 @@ describe('Post API', function () {
should.exist(jsonResponse.posts); should.exist(jsonResponse.posts);
testUtils.API.checkResponse(jsonResponse, 'posts'); testUtils.API.checkResponse(jsonResponse, 'posts');
jsonResponse.posts.should.have.length(11); 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'); testUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
_.isBoolean(jsonResponse.posts[0].featured).should.eql(true); _.isBoolean(jsonResponse.posts[0].featured).should.eql(true);
_.isBoolean(jsonResponse.posts[0].page).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) { it('can retrieve multiple post formats', function (done) {
request 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) .set('Authorization', 'Bearer ' + ownerAccessToken)
.expect('Content-Type', /json/) .expect('Content-Type', /json/)
.expect('Cache-Control', testUtils.cacheRules.private) .expect('Cache-Control', testUtils.cacheRules.private)
@ -370,7 +370,7 @@ describe('Post API', function () {
jsonResponse.posts.should.have.length(1); jsonResponse.posts.should.have.length(1);
jsonResponse.posts[0].id.should.equal(testUtils.DataGenerator.Content.posts[0].id); 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(); done();
}); });

View file

@ -19,7 +19,7 @@ var should = require('should'),
*/ */
describe('DB version integrity', function () { describe('DB version integrity', function () {
// Only these variables should need updating // Only these variables should need updating
var currentSchemaHash = '2073bee126f6e419ef86196f719caea6', var currentSchemaHash = '22d24b1de23d118b90e9547fefae5ad7',
currentFixturesHash = 'e4e64e97d509c61df818bf4d8e46c4c2'; currentFixturesHash = 'e4e64e97d509c61df818bf4d8e46c4c2';
// If this test is failing, then it is likely a change has been made that requires a DB version bump, // If this test is failing, then it is likely a change has been made that requires a DB version bump,

View file

@ -21,9 +21,9 @@ var _ = require('lodash'),
post: _(schema.posts) post: _(schema.posts)
.keys() .keys()
// by default we only return html // 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 // 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(), .value(),
user: { user: {
default: _(schema.users).keys().without('password').without('ghost_auth_access_token').value(), default: _(schema.users).keys().without('password').without('ghost_auth_access_token').value(),