PhoenixKit.Modules.Publishing.StaleFixer (PhoenixKitPublishing v0.1.7)

Copy Markdown View Source

Fixes stale or invalid values on publishing records.

Validates and corrects fields like mode, type, language, and timestamps across groups, posts, versions, and content. Also reconciles active_version_uuid consistency between posts and versions.

Summary

Functions

Fixes stale values across all groups, posts, versions, and content. Also reconciles active_version_uuid consistency and ensures single published version. Callable via internal API or IEx.

Ensures only one version is published per post.

Fixes stale or invalid values on a publishing group record.

Fixes stale or invalid values on a publishing post record.

Functions

fix_all_stale_values()

@spec fix_all_stale_values() :: :ok

Fixes stale values across all groups, posts, versions, and content. Also reconciles active_version_uuid consistency and ensures single published version. Callable via internal API or IEx.

Streams the per-group post listing inside a Repo.checkout/1 so the BEAM doesn't have to hold every post in memory at once for large catalogues (PR #9 follow-up — Pincer review). Group fix-up still loads the group list eagerly because the count is bounded by the number of CMS sections (typically <100), and fix_stale_group/1 mutates rows that the post pass also reads.

fix_multiple_published_versions(post)

Ensures only one version is published per post.

If multiple versions have status "published", keeps the highest version number as published and archives the rest.

fix_stale_content(content)

fix_stale_group(group)

Fixes stale or invalid values on a publishing group record.

Checks and corrects:

  • mode — must be "timestamp" or "slug" (defaults to "timestamp")
  • data.type — must be in valid_types (defaults to "custom")
  • data.item_singular — must be a non-empty string (defaults based on type)
  • data.item_plural — must be a non-empty string (defaults based on type)

Can be called explicitly or runs lazily when groups are loaded in the admin. Returns the group unchanged if no fixes are needed.

fix_stale_post(post)

Fixes stale or invalid values on a publishing post record.

Checks and corrects:

  • mode — must be "timestamp" or "slug" (defaults to "timestamp")
  • post_date/post_time — must be present for timestamp mode posts
  • active_version_uuid — must point to a valid, published version

Deletes empty posts (no content in any version) that are past the grace period.

fix_stale_version(version)

reconcile_post_status(post)

@spec reconcile_post_status(PhoenixKit.Modules.Publishing.PublishingPost.t()) :: [
  any()
]