fix(2meet-data-optimizer-hivepress-addon): declare post_type scopes on HivePress post groups

- hp_listing_core / hp_request_core / hp_vendor_core declare hp_listing / hp_request / hp_vendor, matching core (PR-033), so the AddOn keeps scoped routing once core stops registering them (PR-020b)
- Test: with tmdo_post_scoped_routing on, every key of each group resolves to its own post type's group; legacy owner and hash pins unchanged
- Verify: HP unit 145 / integration 49 OK
- PR: PR-033b
This commit is contained in:
2026-09-25 23:57:52 +08:00
parent 7d0edb6228
commit 3c57fb0ee6
2 changed files with 28 additions and 13 deletions
@@ -15,8 +15,9 @@
* persisted in wpdo_registry_meta (originally registered by core's * persisted in wpdo_registry_meta (originally registered by core's
* TMDO_Post_Fields / TMDO_Member_Fields). Any drift changes the schema hash * TMDO_Post_Fields / TMDO_Member_Fields). Any drift changes the schema hash
* and triggers ALTER TABLE on flat tables that may hold aeav_only data. * and triggers ALTER TABLE on flat tables that may hold aeav_only data.
* The three post groups also share keys (hp_status, hp_user, …) and the * The three post groups share keys (hp_status, hp_user, …): each declares
* entity field index is last-registered-wins, so keep their order. * its post type so a post's key resolves to its own type's group, while
* lookups without a post type keep last-registered-wins — keep their order.
* *
* @package TMDO_HIVEPRESS * @package TMDO_HIVEPRESS
*/ */
@@ -133,7 +134,8 @@ final class TMDO_HivePress_Entity_Groups {
'type' => 'decimal', 'type' => 'decimal',
'label' => 'Hourly rate', 'label' => 'Hourly rate',
), ),
) ),
array( 'post_types' => array( 'hp_listing' ) )
); );
} }
/** /**
@@ -176,7 +178,8 @@ final class TMDO_HivePress_Entity_Groups {
'type' => 'integer', 'type' => 'integer',
'label' => 'View counter', 'label' => 'View counter',
), ),
) ),
array( 'post_types' => array( 'hp_request' ) )
); );
} }
/** /**
@@ -218,7 +221,8 @@ final class TMDO_HivePress_Entity_Groups {
'searchable' => true, 'searchable' => true,
'label' => 'Average rating', 'label' => 'Average rating',
), ),
) ),
array( 'post_types' => array( 'hp_vendor' ) )
); );
} }
/** /**
+19 -8
View File
@@ -21,14 +21,10 @@ class HivePressEntityGroupsTest extends TestCase {
); );
/** /**
* Keys shared by several post groups resolve to the LAST group registered * Lookups that do not pass a post type (or run with scoped routing off,
* (the post entity has a single field index, not one per post_type). * until a site's rows are reconciled) keep the legacy owner of keys shared
* * by several post groups: the LAST group registered. Pinned so the
* ⚠️ This pins current behaviour, not desired behaviour: a listing's * registration order cannot change silently.
* hp_rating is routed to the hp_vendor_core table, its hp_status to
* hp_request_core, etc. It is pinned so that moving the registration
* between plugins cannot change routing silently; fixing the routing is
* tracked separately in the backlog.
*/ */
private const SHARED_KEY_OWNERS = array( private const SHARED_KEY_OWNERS = array(
'hp_status' => 'hp_request_core', 'hp_status' => 'hp_request_core',
@@ -48,6 +44,10 @@ class HivePressEntityGroupsTest extends TestCase {
TMDO_HivePress_Entity_Groups::register_entity_fields(); TMDO_HivePress_Entity_Groups::register_entity_fields();
} }
protected function tearDown(): void {
unset( $GLOBALS['_wp_options'][ TMDO_Entity_Registry::SCOPED_ROUTING_OPTION ] );
}
public function test_definitions_match_persisted_schema_hashes(): void { public function test_definitions_match_persisted_schema_hashes(): void {
foreach ( self::PERSISTED_HASHES as $id => $hash ) { foreach ( self::PERSISTED_HASHES as $id => $hash ) {
list( $type, $group ) = explode( '/', $id ); list( $type, $group ) = explode( '/', $id );
@@ -63,6 +63,17 @@ class HivePressEntityGroupsTest extends TestCase {
} }
} }
public function test_shared_keys_follow_the_post_type_when_scoped_routing_is_on(): void {
$GLOBALS['_wp_options'][ TMDO_Entity_Registry::SCOPED_ROUTING_OPTION ] = '1';
foreach ( array( 'hp_listing' => 'hp_listing_core', 'hp_request' => 'hp_request_core', 'hp_vendor' => 'hp_vendor_core' ) as $post_type => $group ) {
foreach ( TMDO_Entity_Registry::get_group_keys( 'post', $group ) as $key ) {
$this->assertSame( $group, TMDO_Entity_Registry::get_field( 'post', $key, $post_type )['group'], "{$post_type}:{$key}" );
}
}
$this->assertNull( TMDO_Entity_Registry::get_field( 'post', 'hp_rating', 'post' ), 'HivePress keys stay native on other post types' );
}
public function test_core_adapter_does_not_register_a_conflicting_group(): void { public function test_core_adapter_does_not_register_a_conflicting_group(): void {
( new TMDO_HivePress_Core_Adapter() )->on_register_entity_fields(); ( new TMDO_HivePress_Core_Adapter() )->on_register_entity_fields();