Skip to content

[2.x] fix(tags): update tag metadata when a pending discussion is approved#4777

Open
linkrobins wants to merge 1 commit into
flarum:2.xfrom
linkrobins:fix/tags-metadata-on-approval
Open

[2.x] fix(tags): update tag metadata when a pending discussion is approved#4777
linkrobins wants to merge 1 commit into
flarum:2.xfrom
linkrobins:fix/tags-metadata-on-approval

Conversation

@linkrobins

Copy link
Copy Markdown
Contributor

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); otherwise 0 (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.
  • PostWasApproved is also handled by approval's own UpdateDiscussionAfterPostApproval, which is what flips is_private. To stay independent of listener order, this acts immediately when the discussion is already visible, otherwise defers via afterSave so the refresh runs once approval persists the change.

Verification

Clean Flarum 2.0.0-rc.4 (only core + tags + approval):

  1. A member without startWithoutApproval starts a discussion → pending (is_private = true); tag stays count=0, last_posted_discussion_id=null (correct while pending).
  2. Admin approves → discussion is visible, and the tag now shows count=1 and the correct last_posted_discussion_id.

Before this change both stayed 0 / null after approval. An admin's auto-approved discussion (control) is unaffected.

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.
@linkrobins linkrobins requested a review from a team as a code owner June 20, 2026 23:31
@linkrobins linkrobins changed the title fix(tags): update tag metadata when a pending discussion is approved [2.x] fix(tags): update tag metadata when a pending discussion is approved Jun 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[2.x] Tags: discussion_count / last_posted_discussion_id not updated when a pending discussion is approved

1 participant