feat: generic idempotent upsert primitive + ResolvePostByPath helper#1167
Merged
feat: generic idempotent upsert primitive + ResolvePostByPath helper#1167
Conversation
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
2 tasks
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>
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.
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 pathresolve_or_create_stubs()— walk a path and auto-create missing intermediate nodes as empty stubsresolve_or_create_stub()— get-or-create a single stub post under a parentbuild_path()— reconstruct full slug path frompost_parentancestryUpsertPostAbility (
datamachine/upsert-post)Generic ability for idempotent create/update of any post type:
post_id— explicit numeric IDidentity_meta— custom meta key/value (e.g._source_file)slug+parent_id— scoped slug lookupcontent_hashparam compares against stored_datamachine_content_hashmeta; returnsno_changewhen identicalraw_sourceparam stored in_datamachine_raw_sourcemeta for round-trip sync (markdown ↔ HTML)parent_pathsupports slash-delimited paths with optionalcreate_stubs_datamachine_post_flow_idalready stamped by PostTracking;_datamachine_content_hashand_datamachine_raw_sourceadded by this abilityConsumers that can collapse onto this
wiki_upsert→ thin wrapper keepingparent_pathauto-stub logicEventUpsert→ shrinks to domain-specific concerns (venue taxonomy, date normalization, ticket URL canonicalization)sync/docendpoint → calls this ability directly instead of hand-rolling hash comparisonRelated
Testing
php -l)