feat(2meet-data-optimizer-hivepress-addon): flatten a site's own listing attributes on opt-in
- the tmdo_hp_listing_attribute_fields filter (hp_ key => type) registers a site's HivePress listing attributes, such as a "Warranty" number attribute (hp_warranty, 901k rows on dev36), in their own hp_listing_attrs group: a new table with each column indexed at creation; hp_listing_core and its pinned hash are unchanged - keys another group manages, keys without the hp_ prefix and unknown types are ignored - Verify: HivePressEntityGroupsTest (opt-in, filtering, pinned hashes), unit 147, integration 53, phpcs; dev36 hp_warranty backfill and queries - PR: PR-109
This commit is contained in:
@@ -76,6 +76,7 @@ final class TMDO_HivePress_Entity_Groups {
|
||||
self::register_hp_request_core_group();
|
||||
self::register_hp_vendor_core_group();
|
||||
self::register_hp_user_group();
|
||||
self::register_hp_listing_attributes_group();
|
||||
}
|
||||
|
||||
// ── Group definitions ────────────────────────────────────────────────────
|
||||
@@ -271,6 +272,39 @@ final class TMDO_HivePress_Entity_Groups {
|
||||
)
|
||||
);
|
||||
}
|
||||
/**
|
||||
* A site's own HivePress listing attributes (created under Listings →
|
||||
* Attributes, e.g. a "Warranty" number → hp_warranty), opt-in through the
|
||||
* `tmdo_hp_listing_attribute_fields` filter: `array( 'hp_warranty' => 'integer' )`.
|
||||
*
|
||||
* They get a group of their own — a new table, each column indexed at
|
||||
* creation — so hp_listing_core and its pinned definition stay unchanged.
|
||||
* Keys another group already manages, keys without the hp_ prefix and
|
||||
* unknown types are ignored. Backfill with `wp tmdo post-migrate-group`.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private static function register_hp_listing_attributes_group(): void {
|
||||
$fields = array();
|
||||
foreach ( (array) apply_filters( 'tmdo_hp_listing_attribute_fields', array() ) as $key => $type ) {
|
||||
$key = (string) $key;
|
||||
if ( 1 !== preg_match( '/^hp_[a-z0-9_]+$/', $key )
|
||||
|| ! in_array( $type, TMDO_Entity_Registry::VALID_TYPES, true )
|
||||
|| null !== TMDO_Entity_Registry::get_field( 'post', $key, 'hp_listing' ) ) {
|
||||
continue;
|
||||
}
|
||||
$fields[] = array(
|
||||
'key' => $key,
|
||||
'type' => $type,
|
||||
'searchable' => true,
|
||||
'label' => 'Site listing attribute',
|
||||
);
|
||||
}
|
||||
if ( $fields ) {
|
||||
TMDO_Entity_Registry::register_group( 'post', 'hp_listing_attrs', $fields, array( 'post_types' => array( 'hp_listing' ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* HivePress request core meta keys (post_type=hp_request).
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user