Skip to content

Commit 574ce11

Browse files
authored
fix: moment cannot be deleted (#88)
#### What type of PR is this? /kind bug #### What this PR does / why we need it: 解决由于 Finalizer 标记没有被清除导致无法删除数据的问题 #### Which issue(s) this PR fixes: Fixes #85 #### Does this PR introduce a user-facing change? ```release-note 解决无法删除瞬间的问题 ```
1 parent 2fa8a84 commit 574ce11

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package run.halo.moments;
2+
3+
4+
import java.util.Set;
5+
import lombok.RequiredArgsConstructor;
6+
import org.springframework.stereotype.Component;
7+
import run.halo.app.extension.ExtensionClient;
8+
import run.halo.app.extension.ExtensionUtil;
9+
import run.halo.app.extension.controller.Controller;
10+
import run.halo.app.extension.controller.ControllerBuilder;
11+
import run.halo.app.extension.controller.Reconciler;
12+
13+
/**
14+
* Compatible with the {@link TagReconciler#TAG_FINALIZER} added in old data to avoid the
15+
* problem of data not being able to be deleted due to uncleared
16+
* {@link TagReconciler#TAG_FINALIZER}.
17+
*/
18+
@Deprecated(forRemoval = true, since = "1.5.1")
19+
@Component
20+
@RequiredArgsConstructor
21+
public class TagReconciler implements Reconciler<Reconciler.Request> {
22+
23+
private static final String TAG_FINALIZER = "tag-moment-protection";
24+
private final ExtensionClient client;
25+
26+
@Override
27+
public Result reconcile(Request request) {
28+
client.fetch(Moment.class, request.name()).ifPresent(moment -> {
29+
if (ExtensionUtil.isDeleted(moment)) {
30+
if (ExtensionUtil.removeFinalizers(moment.getMetadata(), Set.of(TAG_FINALIZER))) {
31+
client.update(moment);
32+
}
33+
}
34+
});
35+
return Result.doNotRetry();
36+
}
37+
38+
@Override
39+
public Controller setupWith(ControllerBuilder builder) {
40+
final var moment = new Moment();
41+
return builder
42+
.extension(moment)
43+
.build();
44+
}
45+
}

0 commit comments

Comments
 (0)