refactor: autofill if post is published but no publish time (#4775)

#### What type of PR is this?
/kind improvement
/area core
/milestone 2.10.x

#### What this PR does / why we need it:
如果文章是发布状态但没有发布时间则自动填充

#### Does this PR introduce a user-facing change?
```release-note
None
```
pull/4785/head
guqing 2023-10-27 17:37:54 +08:00 committed by GitHub
parent 3905ec8b8d
commit b5094d6e6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 0 deletions

View File

@ -113,6 +113,10 @@ public class PostReconciler implements Reconciler<Reconciler.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();

View File

@ -112,6 +112,10 @@ public class SinglePageReconciler implements Reconciler<Reconciler.Request> {
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);