framework
framework copied to clipboard
[2.x] fix(tags): update tag metadata when a pending discussion is approved
Fixes #4776
Problem
With flarum/approval active, a discussion/post created pending approval is treated as is_private, so UpdateTagMetadata correctly skips it on Started/Posted. But nothing updates the tag once the content is approved, so the tag's discussion_count and last_posted_discussion_id are left permanently stale (e.g. the /tags tile shows a wrong count and no latest discussion).
Fix
UpdateTagMetadata now also handles approval's PostWasApproved:
- First post approved →
+1(the discussion becomes counted); otherwise0(refresh last-posted for an approved reply). - Registered by class-string, so there is no hard dependency on
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):
- A member without
startWithoutApprovalstarts a discussion → pending (is_private = true); tag stayscount=0,last_posted_discussion_id=null(correct while pending). - Admin approves → discussion is visible, and the tag now shows
count=1and the correctlast_posted_discussion_id.
Before this change both stayed 0 / null after approval. An admin's auto-approved discussion (control) is unaffected.