refactor(2meet-data-optimizer): resolve post_type/group/table mappings through the registry
- TMDO_Post_Fields::post_type_for_group() / groups_for_post_type() derive HivePress-style groups from their registry post_type scope (core keeps its own attachment / wc_product / nav_menu_item map); the three copy-pasted switches and the query router's POST_TYPE_GROUP_MAP use them - Term/comment backfill, shadow verifier and CLI take their groups from the registry (TMDO_Term_Comment_Backfill::registered_groups()); installer drops the hp_* entries already covered by its table patterns; REST listings default post type is filterable (tmdo_rest_default_post_type, default 'post') - Verify: NoHpMappingsTest guard + mapping/default tests; core unit 640 / integration 449, HP 146/49, WC 10/22 OK - PR: PR-020e
This commit is contained in:
@@ -860,23 +860,7 @@ class TMDO_CLI_Post {
|
||||
* @return string|null
|
||||
*/
|
||||
private static function group_post_type_for_cli( string $group ): ?string {
|
||||
switch ( $group ) {
|
||||
case 'attachment':
|
||||
return 'attachment';
|
||||
case 'wc_product':
|
||||
return 'product';
|
||||
case 'hp_listing_core':
|
||||
return 'hp_listing';
|
||||
case 'hp_request_core':
|
||||
return 'hp_request';
|
||||
case 'hp_vendor_core':
|
||||
return 'hp_vendor';
|
||||
case 'nav_menu_item':
|
||||
return 'nav_menu_item';
|
||||
case 'wp_core':
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
return TMDO_Post_Fields::post_type_for_group( $group );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -429,7 +429,7 @@ class TMDO_CLI_Term_Comment {
|
||||
WP_CLI::log( sprintf( 'Mode: %s', $term_mode ) );
|
||||
WP_CLI::log( sprintf( 'wp_terms: %s', number_format_i18n( $terms_count ) ) );
|
||||
WP_CLI::log( sprintf( 'wp_termmeta: %s (1:%s)', number_format_i18n( $termmeta_count ), $terms_count > 0 ? round( $termmeta_count / $terms_count, 2 ) : 'n/a' ) );
|
||||
self::print_flat_row( $wpdb->prefix . 'wpdo_term_hp_taxonomy', 'wpdo_term_hp_taxonomy' );
|
||||
self::print_group_rows( 'term' );
|
||||
self::print_flat_row( $wpdb->prefix . 'wpdo_term_misc', 'wpdo_term_misc' );
|
||||
|
||||
WP_CLI::log( '' );
|
||||
@@ -437,7 +437,7 @@ class TMDO_CLI_Term_Comment {
|
||||
WP_CLI::log( sprintf( 'Mode: %s', $comment_mode ) );
|
||||
WP_CLI::log( sprintf( 'wp_comments: %s', number_format_i18n( $comments_count ) ) );
|
||||
WP_CLI::log( sprintf( 'wp_commentmeta: %s (1:%s)', number_format_i18n( $commentmeta_count ), $comments_count > 0 ? round( $commentmeta_count / $comments_count, 2 ) : 'n/a' ) );
|
||||
self::print_flat_row( $wpdb->prefix . 'wpdo_comment_hp_review', 'wpdo_comment_hp_review' );
|
||||
self::print_group_rows( 'comment' );
|
||||
self::print_flat_row( $wpdb->prefix . 'wpdo_comment_misc', 'wpdo_comment_misc' );
|
||||
|
||||
WP_CLI::log( '' );
|
||||
@@ -470,6 +470,21 @@ class TMDO_CLI_Term_Comment {
|
||||
return 'Both entities at disabled. Promote to dual_write first to enable Hook Bus interception.';
|
||||
}
|
||||
|
||||
/**
|
||||
* Print the row count of every registered group table of an entity.
|
||||
*
|
||||
* @param string $entity_type 'term' or 'comment'.
|
||||
* @return void
|
||||
*/
|
||||
private static function print_group_rows( string $entity_type ): void {
|
||||
foreach ( TMDO_Term_Comment_Backfill::registered_groups() as $group => $type ) {
|
||||
if ( $type === $entity_type ) {
|
||||
$table = TMDO_Schema_Manager::get_table_name( $entity_type, $group );
|
||||
self::print_flat_row( $table, TMDO_TABLE_PREFIX . $entity_type . '_' . $group );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Print a flat table's row count (or "(missing)" when not present).
|
||||
*
|
||||
@@ -647,7 +662,8 @@ class TMDO_CLI_Term_Comment {
|
||||
);
|
||||
}
|
||||
|
||||
$valid_groups = array( 'all', 'hp_taxonomy', 'hp_review' );
|
||||
$registered = TMDO_Term_Comment_Backfill::registered_groups();
|
||||
$valid_groups = array_merge( array( 'all' ), array_keys( $registered ) );
|
||||
if ( ! in_array( $group, $valid_groups, true ) ) {
|
||||
WP_CLI::error( 'Invalid --group. Choose: ' . implode( ', ', $valid_groups ) );
|
||||
}
|
||||
@@ -656,8 +672,7 @@ class TMDO_CLI_Term_Comment {
|
||||
if ( 'all' === $group ) {
|
||||
$results = TMDO_Term_Comment_Backfill::backfill_all( $dry_run );
|
||||
} else {
|
||||
$entity_type = 'hp_review' === $group ? 'comment' : 'term';
|
||||
$results = array( $group => TMDO_Term_Comment_Backfill::backfill_group( $entity_type, $group, $dry_run ) );
|
||||
$results = array( $group => TMDO_Term_Comment_Backfill::backfill_group( $registered[ $group ], $group, $dry_run ) );
|
||||
}
|
||||
|
||||
// Render table.
|
||||
|
||||
Reference in New Issue
Block a user