From 401c3c79cea595c7eda2bb1cc3a2367667f4dc07 Mon Sep 17 00:00:00 2001 From: guqing <38999863+guqing@users.noreply.github.com> Date: Fri, 25 Aug 2023 23:36:14 +0800 Subject: [PATCH] fix: newly added setting item are not taking effect (#4486) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### What type of PR is this? /kind improvement /area core /milestone 2.9.x #### What this PR does / why we need it: 修复新增加的配置项默认值没有填充的问题 how to test it? 测试插件和主题新增加的配置项(带默认值)在升级后是否具有默认值 #### Which issue(s) this PR fixes: Fixes #4377 #### Does this PR introduce a user-facing change? ```release-note 修复新增加的配置项默认值没有填充的问题 ``` --- .../reconciler/PluginReconciler.java | 7 ------- .../extension/theme/ThemeServiceImpl.java | 19 +++++++++++++++---- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/application/src/main/java/run/halo/app/core/extension/reconciler/PluginReconciler.java b/application/src/main/java/run/halo/app/core/extension/reconciler/PluginReconciler.java index 9744c7930..2e2f8161e 100644 --- a/application/src/main/java/run/halo/app/core/extension/reconciler/PluginReconciler.java +++ b/application/src/main/java/run/halo/app/core/extension/reconciler/PluginReconciler.java @@ -184,13 +184,6 @@ public class PluginReconciler implements Reconciler { Assert.notNull(name, "Plugin name must not be null"); Assert.notNull(settingName, "Setting name must not be null"); PluginWrapper pluginWrapper = getPluginWrapper(name); - // If it already exists, do not look for setting - if (RuntimeMode.DEPLOYMENT.equals(pluginWrapper.getRuntimeMode())) { - Optional existing = client.fetch(Setting.class, settingName); - if (existing.isPresent()) { - return existing; - } - } var resourceLoader = new DefaultResourceLoader(pluginWrapper.getPluginClassLoader()); diff --git a/application/src/main/java/run/halo/app/core/extension/theme/ThemeServiceImpl.java b/application/src/main/java/run/halo/app/core/extension/theme/ThemeServiceImpl.java index df519bd8a..a3abfed08 100644 --- a/application/src/main/java/run/halo/app/core/extension/theme/ThemeServiceImpl.java +++ b/application/src/main/java/run/halo/app/core/extension/theme/ThemeServiceImpl.java @@ -166,14 +166,25 @@ public class ThemeServiceImpl implements ThemeService { }) .doOnNext(unstructured -> populateThemeNameLabel(unstructured, theme.getMetadata().getName())) - .flatMap(unstructured -> client.create(unstructured) - .retryWhen(Retry.backoff(5, Duration.ofMillis(100)) - .filter(OptimisticLockingFailureException.class::isInstance)) - ) + .flatMap(this::createOrUpdate) .then(Mono.just(theme)); }); } + Mono createOrUpdate(Unstructured unstructured) { + return Mono.defer(() -> client.fetch(unstructured.groupVersionKind(), + unstructured.getMetadata().getName()) + .flatMap(existUnstructured -> { + existUnstructured.getMetadata() + .setVersion(unstructured.getMetadata().getVersion()); + return client.update(existUnstructured); + }) + .switchIfEmpty(Mono.defer(() -> client.create(unstructured))) + ) + .retryWhen(Retry.backoff(5, Duration.ofMillis(100)) + .filter(OptimisticLockingFailureException.class::isInstance)); + } + @Override public Mono reloadTheme(String name) { return client.fetch(Theme.class, name)