generated from halo-dev/plugin-starter
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#### 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
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |