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

🚓 disqus comments (#8762)

closes #8760

- we have to remember the old post id's when migrating a blog from LTS to 1.0
- otherwise we would break disqus comments, because they rely on the post id
- this should fix the discovered situation
This commit is contained in:
Katharina Irrgang 2017-07-27 11:55:23 +04:00 committed by Kevin Ansfield
parent b11ffd976b
commit ce3830f8a9
4 changed files with 25 additions and 3 deletions

View file

@ -137,6 +137,11 @@ class PostsImporter extends BaseImporter {
});
}
}
// NOTE: we remember the old post id for disqus
if (model.id) {
model.amp = model.id.toString();
}
});
// NOTE: do after, because model properties are deleted e.g. post.id

View file

@ -494,7 +494,9 @@ Post = ghostBookshelf.Model.extend({
toJSON: function toJSON(options) {
options = options || {};
var attrs = ghostBookshelf.Model.prototype.toJSON.call(this, options);
var attrs = ghostBookshelf.Model.prototype.toJSON.call(this, options),
oldPostId = attrs.amp,
commentId;
attrs = this.formatsToJSON(attrs, options);
@ -507,6 +509,21 @@ Post = ghostBookshelf.Model.extend({
attrs.url = utils.url.urlPathForPost(attrs);
}
if (oldPostId) {
oldPostId = Number(oldPostId);
if (isNaN(oldPostId)) {
commentId = attrs.id;
} else {
commentId = oldPostId;
}
} else {
commentId = attrs.id;
}
// NOTE: we remember the old post id because of disqus
attrs.comment_id = commentId;
return attrs;
},
enforcedFilters: function enforcedFilters() {

View file

@ -104,7 +104,7 @@ describe('Schedules API', function () {
api.schedules.getScheduledPosts()
.then(function (result) {
result.posts.length.should.eql(5);
Object.keys(result.posts[0].toJSON()).should.eql(['id', 'published_at', 'created_at', 'author', 'url']);
Object.keys(result.posts[0].toJSON()).should.eql(['id', 'published_at', 'created_at', 'author', 'url', 'comment_id']);
done();
})
.catch(done);

View file

@ -24,7 +24,7 @@ var _ = require('lodash'),
// does not return all formats by default
.without('mobiledoc', 'amp', 'plaintext')
// swaps author_id to author, and always returns a computed 'url' property
.without('author_id').concat('author', 'url')
.without('author_id').concat('author', 'url', 'comment_id')
.value(),
// User API always removes the password field
user: _(schema.users).keys().without('password').without('ghost_auth_access_token').value(),