'hot_' . sanitize_key( $post_type ), 'cold' => 'cold_' . sanitize_key( $post_type ), 'warm' => 'warm', 'archive' => 'archive', default => 'unknown', }; } /** * Read a field value from the appropriate zone. * * @param array $field Field definition from Schema Registry. * @param int $post_id Post ID. * @param string $post_type Post type. * @param string $meta_key Meta key. * @return mixed Value from zone, or null if not found / zone not supported. */ public static function read( array $field, int $post_id, string $post_type, string $meta_key ): mixed { return match ( $field['zone'] ) { 'hot' => TMDO_Zone_Hot::get( $post_id, $post_type, $field['column'] ), 'cold' => TMDO_Zone_Cold::get( $post_id, $post_type, $meta_key ), 'warm' => TMDO_Zone_Warm::get( $post_id, $meta_key ), default => null, }; } /** * Write a field value to the appropriate zone. * * @param array $field Field definition from Schema Registry. * @param int $post_id Post ID. * @param string $post_type Post type. * @param string $meta_key Meta key. * @param mixed $value Value to write. * @return void */ public static function write( array $field, int $post_id, string $post_type, string $meta_key, mixed $value ): void { match ( $field['zone'] ) { 'hot' => TMDO_Zone_Hot::set( $post_id, $post_type, $field['column'], $value ), 'cold' => TMDO_Zone_Cold::set( $post_id, $post_type, $meta_key, $value ), 'warm' => TMDO_Zone_Warm::set( $post_id, $meta_key, is_string( $value ) ? $value : wp_json_encode( $value ), $field['ttl'] ?? null ), default => null, }; } /** * Delete a single field value from the appropriate zone. * * @param array $field Field definition from Schema Registry. * @param int $post_id Post ID. * @param string $post_type Post type. * @param string $meta_key Meta key. * @return void */ public static function delete_field( array $field, int $post_id, string $post_type, string $meta_key ): void { match ( $field['zone'] ) { 'hot' => TMDO_Zone_Hot::set( $post_id, $post_type, $field['column'], null ), 'cold' => TMDO_Zone_Cold::remove( $post_id, $post_type, $meta_key ), 'warm' => TMDO_Zone_Warm::delete( $post_id, $meta_key ), default => null, }; } /** * Delete all Zone data for a post being permanently removed. * * Callers only need post_id and post_type; zone enumeration and per-zone * error isolation are handled here. Hot and Cold are skipped when the * post_type has no registered fields in that zone (table may not exist). * * @param int $post_id Post ID being deleted. * @param string $post_type Post type slug. * @return void */ public static function delete_post( int $post_id, string $post_type ): void { $registry = TMDO_Schema_Registry::instance(); if ( ! empty( $registry->get_hot_columns( $post_type ) ) ) { try { TMDO_Zone_Hot::delete( $post_id, $post_type ); } catch ( \Throwable $e ) { TMDO_Logger::error( 'hot_' . $post_type, 'delete_post', $e->getMessage() ); } } if ( ! empty( $registry->get_cold_meta_keys( $post_type ) ) ) { try { TMDO_Zone_Cold::delete( $post_id, $post_type ); } catch ( \Throwable $e ) { TMDO_Logger::error( 'cold_' . $post_type, 'delete_post', $e->getMessage() ); } } try { TMDO_Zone_Warm::delete_all( $post_id ); } catch ( \Throwable $e ) { TMDO_Logger::error( 'warm', 'delete_post', $e->getMessage() ); } try { TMDO_Zone_Archive::delete( $post_id ); } catch ( \Throwable $e ) { TMDO_Logger::error( 'archive', 'delete_post', $e->getMessage() ); } } }