Syncs event dates from Event Details block attributes to the datamachine_event_dates table on save. Also handles ticket URL normalization for duplicate detection.
Event datetimes are stored in two places:
- Event Details block attributes (
startDate,startTime,endDate,endTime) — the authoring source of truth. Edited by humans and AI in the block editor. datamachine_event_datestable — the query source of truth. Calendar queries, upcoming-event filters, admin columns, and Schema.org fallbacks all read from this table.
The save_post hook parses the block attributes and writes the computed MySQL DATETIME to the table. There is no postmeta middle layer — the redundant _datamachine_event_datetime / _datamachine_event_end_datetime meta keys were removed in issue #424.
inc/Core/event-dates-sync.php
Monitors post saves and automatically syncs Event Details block data to the datamachine_event_dates table.
Parses Gutenberg blocks to extract datetime information from Event Details blocks.
The table includes a post_status column kept in sync via transition_post_status so date queries can filter to published events without joining the posts table.
Syncs event datetime to the datamachine_event_dates table on save.
Process:
- Validates post type is
data_machine_events - Skips autosave operations
- Parses blocks to find Event Details blocks
- Extracts start/end dates and times from block attributes
- Guards against malformed dates (issue #394) — skips the datetime write cleanly instead of writing a junk
0000-00-00 00:00:00row - Combines into MySQL DATETIME format
- Upserts or deletes the table row based on data presence
- Syncs ticket URL meta for duplicate detection queries
Datetime Logic:
- Start datetime:
startDate + ' ' + startTime(defaults to 00:00:00 if no time) - End datetime: Uses
endDate + endTimeif provided, otherwise null - If no start date, deletes the table row
- Event Details Block: Automatically triggered on block saves
- Calendar Block: Queries the table for efficient date-based filtering (via
DateFilter/UpcomingFilter) - EventUpsert: Block content is generated from AI parameters; save_post handles table sync
- Admin Interface: Enables date-based sorting and filtering via table JOIN
- EventSchemaProvider: Falls back to the table (not meta) when block attributes are empty
- EventHydrator: Reads datetime from the table to hydrate calendar event data
Storage Format: MySQL DATETIME (Y-m-d H:i:s)
Examples:
2024-12-25 14:30:00- December 25, 2024 at 2:30 PM2024-01-15 00:00:00- January 15, 2024 (midnight)
The system reads these attributes from Event Details blocks:
startDate: Date in Y-m-d formatstartTime: Time in H:i:s format (optional)endDate: End date in Y-m-d format (optional)endTime: End time in H:i:s format (optional)
- Index Support: Dedicated table with indexes on
start_datetime,end_datetime, and(post_status, start_datetime) - Fast Filtering: Enables efficient date range queries without postmeta JOINs
- Sorting: Allows ORDER BY on indexed datetime columns
- Calendar Queries: Powers responsive calendar block filtering
The EventDatesTable::backfill() method performs a one-time migration of events that still have legacy _datamachine_event_datetime postmeta but no row in the table. New events are written directly to the table by save_post.