Skip to content

feat: generic idempotent upsert primitive + ResolvePostByPath helper#1167

Merged
chubes4 merged 1 commit intomainfrom
feat/upsert-post-primitive
Apr 23, 2026
Merged

feat: generic idempotent upsert primitive + ResolvePostByPath helper#1167
chubes4 merged 1 commit intomainfrom
feat/upsert-post-primitive

Conversation

@chubes4
Copy link
Copy Markdown
Member

@chubes4 chubes4 commented Apr 23, 2026

Summary

This PR introduces two DM core primitives that replace ad-hoc idempotent upsert implementations duplicated across Intelligence, data-machine-events, and extrachill-docs.

ResolvePostByPath

Static helper in inc/Core/WordPress/ResolvePostByPath.php:

  • resolve() — find a post by numeric ID, simple slug, or slash-delimited path
  • resolve_or_create_stubs() — walk a path and auto-create missing intermediate nodes as empty stubs
  • resolve_or_create_stub() — get-or-create a single stub post under a parent
  • build_path() — reconstruct full slug path from post_parent ancestry

UpsertPostAbility (datamachine/upsert-post)

Generic ability for idempotent create/update of any post type:

  • Three identity strategies (priority order):
    1. post_id — explicit numeric ID
    2. identity_meta — custom meta key/value (e.g. _source_file)
    3. slug + parent_id — scoped slug lookup
  • Content hash idempotency — optional content_hash param compares against stored _datamachine_content_hash meta; returns no_change when identical
  • Raw source storage — optional raw_source param stored in _datamachine_raw_source meta for round-trip sync (markdown ↔ HTML)
  • Hierarchical parent resolutionparent_path supports slash-delimited paths with optional create_stubs
  • Taxonomy assignment — auto-creates missing terms
  • Provenance_datamachine_post_flow_id already stamped by PostTracking; _datamachine_content_hash and _datamachine_raw_source added by this ability

Consumers that can collapse onto this

  • Intelligence wiki_upsert → thin wrapper keeping parent_path auto-stub logic
  • data-machine-events EventUpsert → shrinks to domain-specific concerns (venue taxonomy, date normalization, ticket URL canonicalization)
  • extrachill-docs sync/doc endpoint → calls this ability directly instead of hand-rolling hash comparison

Related

Testing

  • Syntax validated (php -l)
  • Smoke/unit tests to follow in follow-up commit

Introduces two DM core primitives that replace ad-hoc implementations
across Intelligence, data-machine-events, and extrachill-docs.

ResolvePostByPath (inc/Core/WordPress/ResolvePostByPath.php):
- Static helper for resolving hierarchical posts by slash-delimited path
- Supports numeric ID, simple slug, and full path resolution
- Optional auto-stub creation for missing intermediate nodes
- build_path() for reconstructing full slug paths from post_parent chains

UpsertPostAbility (datamachine/upsert-post):
- Generic idempotent create/update for any post type
- Three identity strategies: post_id, slug+parent, custom meta_key+value
- content_hash comparison returns created/updated/no_change
- Stores _datamachine_content_hash and _datamachine_raw_source meta
- Optional parent_path resolution via ResolvePostByPath with create_stubs
- Taxonomy assignment with auto-create for missing terms

Refs: #1166
Closes: #1163
@chubes4 chubes4 merged commit 0462087 into main Apr 23, 2026
1 check passed
@chubes4 chubes4 deleted the feat/upsert-post-primitive branch April 23, 2026 02:09
chubes4 added a commit to Extra-Chill/data-machine-events that referenced this pull request Apr 23, 2026
…sert-post ability (#209)

Replaces inline createEventPost/updateEventPost/hasDataChanged with a single
call to datamachine/upsert-post, which handles content-hash idempotency and
provenance stamping.

Domain-specific logic kept in the extension:
- Fuzzy identity resolution (findExistingEventViaAbility + findExistingEvent)
- Advisory locks by (date, normalized_title)
- Venue/promoter taxonomy assignment with smart merging
- Featured image processing
- Submission metadata
- Block content generation

Net: -122 lines, simpler create/update branching, leverages core primitives.

Refs Extra-Chill/data-machine#1167
Closes #208

Co-authored-by: homeboy-ci[bot] <266378653+homeboy-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant