[2.x] fix(tags): update tag metadata when a pending discussion is approved#4777
Open
linkrobins wants to merge 1 commit into
Open
[2.x] fix(tags): update tag metadata when a pending discussion is approved#4777linkrobins wants to merge 1 commit into
linkrobins wants to merge 1 commit into
Conversation
When approval marks new content is_private, UpdateTagMetadata correctly skips it on Started/Posted, but nothing refreshed the tag once the content was approved, leaving discussion_count and last_posted_discussion_id stale. Listen for Approval's PostWasApproved (by class-string, so there is no hard dependency) and refresh, deferring to the discussion's save when approval hasn't persisted the visibility change yet.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4776
Problem
With
flarum/approvalactive, a discussion/post created pending approval is treated asis_private, soUpdateTagMetadatacorrectly skips it onStarted/Posted. But nothing updates the tag once the content is approved, so the tag'sdiscussion_countandlast_posted_discussion_idare left permanently stale (e.g. the/tagstile shows a wrong count and no latest discussion).Fix
UpdateTagMetadatanow also handles approval'sPostWasApproved:+1(the discussion becomes counted); otherwise0(refresh last-posted for an approved reply).flarum/approval— if it isn't installed the event simply never fires.PostWasApprovedis also handled by approval's ownUpdateDiscussionAfterPostApproval, which is what flipsis_private. To stay independent of listener order, this acts immediately when the discussion is already visible, otherwise defers viaafterSaveso the refresh runs once approval persists the change.Verification
Clean Flarum 2.0.0-rc.4 (only core + tags + approval):
startWithoutApprovalstarts a discussion → pending (is_private = true); tag stayscount=0,last_posted_discussion_id=null(correct while pending).count=1and the correctlast_posted_discussion_id.Before this change both stayed
0/nullafter approval. An admin's auto-approved discussion (control) is unaffected.