Skip to content

Commit

Permalink
🐛 ensure import of scheduled posts works (#8454)
Browse files Browse the repository at this point in the history
closes #8354

- i thought about transforming scheduled posts into drafts on export, but this has two disadvantages:
  1. existing exports with scheduled posts won't import
  2. if you schedule a post for next week and you export/import earlier, the post is back to draft
- by this we ensure that we can simply import the post back to a scheduled post
- if the published_at is already in the past, the scheduler will care and instantly publish the post
  • Loading branch information
kirrg001 committed May 12, 2017
1 parent 524cc4c commit 9bea207
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
6 changes: 5 additions & 1 deletion core/server/models/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,11 @@ Post = ghostBookshelf.Model.extend({
message: i18n.t('errors.models.post.valueCannotBeBlank', {key: 'published_at'})
}));
// CASE: to schedule/reschedule a post, a minimum diff of x minutes is needed (default configured is 2minutes)
} else if (publishedAtHasChanged && moment(publishedAt).isBefore(moment().add(config.get('times').cannotScheduleAPostBeforeInMinutes, 'minutes'))) {
} else if (
publishedAtHasChanged &&
moment(publishedAt).isBefore(moment().add(config.get('times').cannotScheduleAPostBeforeInMinutes, 'minutes')) &&
!options.importing
) {
return Promise.reject(new errors.ValidationError({
message: i18n.t('errors.models.post.expectedPublishedAtInFuture', {
cannotScheduleAPostBeforeInMinutes: config.get('times').cannotScheduleAPostBeforeInMinutes
Expand Down
3 changes: 3 additions & 0 deletions core/test/integration/import_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,11 @@ describe('Import', function () {

// we always have 1 user, the owner user we added
users.length.should.equal(1, 'There should only be one user');

// import no longer requires all data to be dropped, and adds posts
posts.length.should.equal(exportData.data.posts.length, 'Wrong number of posts');
posts[0].status.should.eql('published');
posts[1].status.should.eql('scheduled');

// test settings
settings.length.should.be.above(0, 'Wrong number of settings');
Expand Down
22 changes: 22 additions & 0 deletions core/test/utils/fixtures/export/export-000.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,28 @@
"updated_by": 1,
"published_at": 1388318310783,
"published_by": 1
},
{
"id": 2,
"uuid": "8492fbba-1102-4b53-8e3e-abe207952f0c",
"title": "schedule-me",
"slug": "schedule-me",
"markdown": "You're live! Nice.",
"html": "<p>You're live! Nice.</p>",
"image": null,
"featured": 0,
"page": 0,
"status": "scheduled",
"language": "en_US",
"meta_title": null,
"meta_description": null,
"author_id": 1,
"created_at": 1388318310782,
"created_by": 1,
"updated_at": 1388318310782,
"updated_by": 1,
"published_at": 1388318310783,
"published_by": 1
}
],
"users": [],
Expand Down

0 comments on commit 9bea207

Please sign in to comment.