From 20705486419787e02f965a28ae59141bbe231e8f Mon Sep 17 00:00:00 2001 From: Halo Dev Bot <87291978+halo-dev-bot@users.noreply.github.com> Date: Fri, 27 Oct 2023 17:47:48 +0800 Subject: [PATCH] [release-2.10] refactor: autofill if post is published but no publish time (#4781) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is an automated cherry-pick of #4775 /assign ruibaby ```release-note 修复文章可能因为没有发布时间导致发布失败的问题。 ``` --- .../halo/app/core/extension/reconciler/PostReconciler.java | 4 ++++ .../app/core/extension/reconciler/SinglePageReconciler.java | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/application/src/main/java/run/halo/app/core/extension/reconciler/PostReconciler.java b/application/src/main/java/run/halo/app/core/extension/reconciler/PostReconciler.java index eb182a51a7..fafdd67a2c 100644 --- a/application/src/main/java/run/halo/app/core/extension/reconciler/PostReconciler.java +++ b/application/src/main/java/run/halo/app/core/extension/reconciler/PostReconciler.java @@ -113,6 +113,10 @@ public Result reconcile(Request request) { post.setStatus(status); } + if (post.isPublished() && post.getSpec().getPublishTime() == null) { + post.getSpec().setPublishTime(Instant.now()); + } + // calculate the sha256sum var configSha256sum = Hashing.sha256().hashString(post.getSpec().toString(), UTF_8) .toString(); diff --git a/application/src/main/java/run/halo/app/core/extension/reconciler/SinglePageReconciler.java b/application/src/main/java/run/halo/app/core/extension/reconciler/SinglePageReconciler.java index 441d95dae6..ad46213b5e 100644 --- a/application/src/main/java/run/halo/app/core/extension/reconciler/SinglePageReconciler.java +++ b/application/src/main/java/run/halo/app/core/extension/reconciler/SinglePageReconciler.java @@ -112,6 +112,10 @@ void subscribeNewCommentNotification(SinglePage page) { private void reconcileSpec(String name) { client.fetch(SinglePage.class, name).ifPresent(page -> { + if (page.isPublished() && page.getSpec().getPublishTime() == null) { + page.getSpec().setPublishTime(Instant.now()); + } + // un-publish if necessary if (page.isPublished() && Objects.equals(false, page.getSpec().getPublish())) { unPublish(name);