Skip to content

Commit

Permalink
fix: moment cannot be deleted (#88)
Browse files Browse the repository at this point in the history
#### 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
解决无法删除瞬间的问题
```
  • Loading branch information
LIlGG authored Mar 1, 2024
1 parent 2fa8a84 commit 574ce11
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/main/java/run/halo/moments/TagReconciler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package run.halo.moments;


import java.util.Set;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import run.halo.app.extension.ExtensionClient;
import run.halo.app.extension.ExtensionUtil;
import run.halo.app.extension.controller.Controller;
import run.halo.app.extension.controller.ControllerBuilder;
import run.halo.app.extension.controller.Reconciler;

/**
* Compatible with the {@link TagReconciler#TAG_FINALIZER} added in old data to avoid the
* problem of data not being able to be deleted due to uncleared
* {@link TagReconciler#TAG_FINALIZER}.
*/
@Deprecated(forRemoval = true, since = "1.5.1")
@Component
@RequiredArgsConstructor
public class TagReconciler implements Reconciler<Reconciler.Request> {

private static final String TAG_FINALIZER = "tag-moment-protection";
private final ExtensionClient client;

@Override
public Result reconcile(Request request) {
client.fetch(Moment.class, request.name()).ifPresent(moment -> {
if (ExtensionUtil.isDeleted(moment)) {
if (ExtensionUtil.removeFinalizers(moment.getMetadata(), Set.of(TAG_FINALIZER))) {
client.update(moment);
}
}
});
return Result.doNotRetry();
}

@Override
public Controller setupWith(ControllerBuilder builder) {
final var moment = new Moment();
return builder
.extension(moment)
.build();
}
}

0 comments on commit 574ce11

Please sign in to comment.