Skip to content

Commit

Permalink
fix: unable to display if the logo changes after the plugin upgrade (h…
Browse files Browse the repository at this point in the history
…alo-dev#4657)

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

#### What this PR does / why we need it:
修复当插件升级后 Logo 改变会无法显示的问题

how to test it?
1. 使用生产模式运行插件
2. 使用 sitemap 插件 1.0.1版本,https://www.halo.run/store/apps/app-QDFMI?tab=releases
3. 升级 sitemap 插件到 1.1.0, https://www.halo.run/store/apps/app-QDFMI?tab=releases
4. 期望 logo 由原先的 halo 图标变为新图标

#### Which issue(s) this PR fixes:
Fixes halo-dev#4646

#### Does this PR introduce a user-facing change?
```release-note
修复当插件升级后 Logo 改变会无法显示的问题
```
  • Loading branch information
guqing authored Sep 25, 2023
1 parent a29c608 commit 5fa0056
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ boolean readinessDetection(String name) {
if (waitForSettingCreation(plugin)) {
return true;
}
createInitialReverseProxyIfNotPresent(plugin);
recreateDefaultReverseProxy(plugin);

updateStatus(name, status -> {
String logoUrl = generateAccessibleLogoUrl(plugin);
Expand Down Expand Up @@ -764,7 +764,7 @@ Path determinePluginLocation(Plugin plugin) {
return Paths.get(pluginLocation);
}

void createInitialReverseProxyIfNotPresent(Plugin plugin) {
void recreateDefaultReverseProxy(Plugin plugin) {
String pluginName = plugin.getMetadata().getName();
String reverseProxyName = initialReverseProxyName(pluginName);
ReverseProxy reverseProxy = new ReverseProxy();
Expand All @@ -785,11 +785,9 @@ void createInitialReverseProxyIfNotPresent(Plugin plugin) {

client.fetch(ReverseProxy.class, reverseProxyName)
.ifPresentOrElse(persisted -> {
if (isDevelopmentMode(pluginName)) {
reverseProxy.getMetadata()
.setVersion(persisted.getMetadata().getVersion());
client.update(reverseProxy);
}
reverseProxy.getMetadata()
.setVersion(persisted.getMetadata().getVersion());
client.update(reverseProxy);
}, () -> client.create(reverseProxy));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import org.pf4j.PluginDescriptor;
import org.pf4j.PluginState;
import org.pf4j.PluginWrapper;
import org.pf4j.RuntimeMode;
import org.skyscreamer.jsonassert.JSONAssert;
import org.springframework.context.ApplicationEventPublisher;
import run.halo.app.core.extension.Plugin;
Expand Down Expand Up @@ -233,14 +232,14 @@ void shouldReconcileStopWhenEnabledIsFalseAndPhaseIsStartedButStopFailed() {
}

@Test
void createInitialReverseProxyWhenNotExistAndLogoIsPath() throws JSONException {
void recreateDefaultReverseProxyWhenNotExistAndLogoIsPath() throws JSONException {
Plugin plugin = need2ReconcileForStopState();
String reverseProxyName = initialReverseProxyName(plugin.getMetadata().getName());
when(extensionClient.fetch(eq(ReverseProxy.class), eq(reverseProxyName)))
.thenReturn(Optional.empty());

plugin.getSpec().setLogo("/logo.png");
pluginReconciler.createInitialReverseProxyIfNotPresent(plugin);
pluginReconciler.recreateDefaultReverseProxy(plugin);
ArgumentCaptor<ReverseProxy> captor = ArgumentCaptor.forClass(ReverseProxy.class);
verify(extensionClient, times(1)).create(captor.capture());
ReverseProxy value = captor.getValue();
Expand Down Expand Up @@ -269,22 +268,22 @@ void createInitialReverseProxyWhenNotExistAndLogoIsPath() throws JSONException {
}

@Test
void createInitialReverseProxyWhenNotExistAndLogoIsAbsolute() {
void recreateDefaultReverseProxyWhenNotExistAndLogoIsAbsolute() {
Plugin plugin = need2ReconcileForStopState();
String reverseProxyName = initialReverseProxyName(plugin.getMetadata().getName());
when(extensionClient.fetch(eq(ReverseProxy.class), eq(reverseProxyName)))
.thenReturn(Optional.empty());

plugin.getSpec().setLogo("http://example.com/logo");
pluginReconciler.createInitialReverseProxyIfNotPresent(plugin);
pluginReconciler.recreateDefaultReverseProxy(plugin);
ArgumentCaptor<ReverseProxy> captor = ArgumentCaptor.forClass(ReverseProxy.class);
verify(extensionClient, times(1)).create(captor.capture());
ReverseProxy value = captor.getValue();
assertThat(value.getRules()).isEmpty();
}

@Test
void createInitialReverseProxyWhenExist() {
void recreateDefaultReverseProxyWhenExist() {
Plugin plugin = need2ReconcileForStopState();
plugin.getSpec().setLogo("/logo.png");

Expand All @@ -296,14 +295,9 @@ void createInitialReverseProxyWhenExist() {

when(extensionClient.fetch(eq(ReverseProxy.class), eq(reverseProxyName)))
.thenReturn(Optional.of(reverseProxy));
when(pluginWrapper.getRuntimeMode()).thenReturn(RuntimeMode.DEPLOYMENT);

pluginReconciler.createInitialReverseProxyIfNotPresent(plugin);
verify(extensionClient, times(0)).update(any());

when(pluginWrapper.getRuntimeMode()).thenReturn(RuntimeMode.DEVELOPMENT);
pluginReconciler.createInitialReverseProxyIfNotPresent(plugin);
verify(extensionClient, times(1)).update(any());
pluginReconciler.recreateDefaultReverseProxy(plugin);
verify(extensionClient).update(any());
}

@Nested
Expand Down

0 comments on commit 5fa0056

Please sign in to comment.