From 9bea2077cffb1cc6fc69fb1f5b2b806918ea5263 Mon Sep 17 00:00:00 2001 From: Katharina Irrgang Date: Fri, 12 May 2017 14:56:40 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=20ensure=20import=20of=20schedu?= =?UTF-8?q?led=20posts=20works=20(#8454)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- core/server/models/post.js | 6 ++++- core/test/integration/import_spec.js | 3 +++ .../utils/fixtures/export/export-000.json | 22 +++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/core/server/models/post.js b/core/server/models/post.js index 52a4876e22..3138499056 100644 --- a/core/server/models/post.js +++ b/core/server/models/post.js @@ -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 diff --git a/core/test/integration/import_spec.js b/core/test/integration/import_spec.js index aa1d3f968c..4b98314910 100644 --- a/core/test/integration/import_spec.js +++ b/core/test/integration/import_spec.js @@ -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'); diff --git a/core/test/utils/fixtures/export/export-000.json b/core/test/utils/fixtures/export/export-000.json index 1e95233511..9d92880c71 100644 --- a/core/test/utils/fixtures/export/export-000.json +++ b/core/test/utils/fixtures/export/export-000.json @@ -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": "

You're live! Nice.

", + "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": [],