🐛 Fixed disqus comment id when exporting/importing 1.x content

no issue

- while i was testing random failures, i discovered an edge case for disqus
- you start a new 1.0 blog, you add disqus, the unique identifer is the post id (object id)
- now you export your content and import it on a new instance
- the importer detects that the amp field is null and imports the old object id as comment id
- but the post model is not prepared for this case
- see next commit for tests

**NOTE**: The comment id had two different data types (Number or String). Disqus expects a string. So this should not change any behaviour, now that the comment_id is always a string.
This commit is contained in:
kirrg001 2017-09-12 17:03:47 +02:00 committed by Hannah Wolfe
parent 4a1f1f5a9f
commit c99557d9a3

View File

@ -3,6 +3,7 @@ var _ = require('lodash'),
uuid = require('uuid'),
moment = require('moment'),
Promise = require('bluebird'),
ObjectId = require('bson-objectid'),
sequence = require('../utils/sequence'),
errors = require('../errors'),
htmlToText = require('html-to-text'),
@ -518,12 +519,19 @@ Post = ghostBookshelf.Model.extend({
}
if (oldPostId) {
oldPostId = Number(oldPostId);
if (isNaN(oldPostId)) {
commentId = attrs.id;
} else {
// 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;