Skip to content

Commit 1eb0549

Browse files
kirrg001kevinansfield
authored andcommitted
🐛 ensure import of scheduled posts works (#8454)
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
1 parent caaa8d4 commit 1eb0549

3 files changed

Lines changed: 30 additions & 1 deletion

File tree

core/server/models/post.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,11 @@ Post = ghostBookshelf.Model.extend({
212212
i18n.t('errors.models.post.valueCannotBeBlank', {key: 'published_at'})
213213
));
214214
// CASE: to schedule/reschedule a post, a minimum diff of x minutes is needed (default configured is 2minutes)
215-
} else if (publishedAtHasChanged && moment(publishedAt).isBefore(moment().add(config.times.cannotScheduleAPostBeforeInMinutes, 'minutes'))) {
215+
} else if (
216+
publishedAtHasChanged &&
217+
moment(publishedAt).isBefore(moment().add(config.times.cannotScheduleAPostBeforeInMinutes, 'minutes')) &&
218+
!options.importing
219+
) {
216220
return Promise.reject(new errors.ValidationError(
217221
i18n.t('errors.models.post.expectedPublishedAtInFuture', {
218222
cannotScheduleAPostBeforeInMinutes: config.times.cannotScheduleAPostBeforeInMinutes

core/test/integration/import_spec.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,11 @@ describe('Import', function () {
145145

146146
// we always have 1 user, the owner user we added
147147
users.length.should.equal(1, 'There should only be one user');
148+
148149
// import no longer requires all data to be dropped, and adds posts
149150
posts.length.should.equal(exportData.data.posts.length, 'Wrong number of posts');
151+
posts[0].status.should.eql('published');
152+
posts[1].status.should.eql('scheduled');
150153

151154
// test settings
152155
settings.length.should.be.above(0, 'Wrong number of settings');

core/test/utils/fixtures/export/export-000.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,28 @@
2626
"updated_by": 1,
2727
"published_at": 1388318310783,
2828
"published_by": 1
29+
},
30+
{
31+
"id": 2,
32+
"uuid": "8492fbba-1102-4b53-8e3e-abe207952f0c",
33+
"title": "schedule-me",
34+
"slug": "schedule-me",
35+
"markdown": "You're live! Nice.",
36+
"html": "<p>You're live! Nice.</p>",
37+
"image": null,
38+
"featured": 0,
39+
"page": 0,
40+
"status": "scheduled",
41+
"language": "en_US",
42+
"meta_title": null,
43+
"meta_description": null,
44+
"author_id": 1,
45+
"created_at": 1388318310782,
46+
"created_by": 1,
47+
"updated_at": 1388318310782,
48+
"updated_by": 1,
49+
"published_at": 1388318310783,
50+
"published_by": 1
2951
}
3052
],
3153
"users": [],

0 commit comments

Comments
 (0)