fix(2meet-data-optimizer): stop false alarms in doctor, term-comment-diagnose and bridge-status
- doctor: entity flat tables come from the registry (TMDO_CLI::check_entity_tables()) instead of a hard-coded user list naming the never-registered sso group, which failed doctor on every site; it also reports Promotion Guard violations and the recorded drift status per entity (report_guard_and_drift()). - term-comment-diagnose: filter status comes from each filter's is_enabled() (the garbage filter and misc bucket default to off but were shown enabled); a filter whose add-on is not active shows "not installed". - bridge-status: flat_rows counts rows holding a value (wp_core keeps an all-NULL row per post: 15306% on dev36) and eav_ids of a post-type group counts only its post types. - Tests: the WP_CLI stubs record their output in $GLOBALS['_wp_cli_output']. - Verify: DoctorTest, CliFilterStatusTest, CliBridgeStatusTest (RED before); dev36 doctor exit 1 → 0, wp_core 15306% → 100%. - PR: PR-076
This commit is contained in:
+82
-23
@@ -94,6 +94,83 @@ class TMDO_CLI {
|
||||
WP_CLI::success( 'Tables installed. DB version: ' . get_option( 'wpdo_db_version' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Report the flat table of every backfillable group of every entity type,
|
||||
* plus the installer's migration status and points ledger tables.
|
||||
*
|
||||
* @return bool Every table exists.
|
||||
*/
|
||||
public static function check_entity_tables(): bool {
|
||||
global $wpdb;
|
||||
|
||||
$tables = array( $wpdb->prefix . 'wpdo_migration_status', $wpdb->prefix . 'wpdo_user_points_ledger' );
|
||||
foreach ( TMDO_Entity_Registry::VALID_ENTITY_TYPES as $entity_type ) {
|
||||
foreach ( TMDO_Entity_Migration_Engine::backfillable_groups( $entity_type ) as $group ) {
|
||||
$tables[] = TMDO_Schema_Manager::get_table_name( $entity_type, $group );
|
||||
}
|
||||
}
|
||||
|
||||
$ok = true;
|
||||
foreach ( $tables as $t ) {
|
||||
if ( TMDO_IS_SQLITE ) {
|
||||
$exists = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name=%s", $t ) );
|
||||
} else {
|
||||
$exists = $wpdb->get_var( $wpdb->prepare( 'SELECT COUNT(*) FROM information_schema.TABLES WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = %s', $t ) );
|
||||
}
|
||||
if ( $exists ) {
|
||||
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
||||
$rows = (int) $wpdb->get_var( "SELECT COUNT(*) FROM `{$t}`" );
|
||||
WP_CLI::log( " [OK] {$t} ({$rows} rows)" );
|
||||
} else {
|
||||
WP_CLI::warning( " [MISSING] {$t} — run `wp wpdo install` to create." );
|
||||
$ok = false;
|
||||
}
|
||||
}
|
||||
return $ok;
|
||||
}
|
||||
|
||||
/**
|
||||
* Report Promotion Guard violations and the recorded drift status of every
|
||||
* entity that writes flat tables or has been checked (informational).
|
||||
*/
|
||||
public static function report_guard_and_drift(): void {
|
||||
WP_CLI::log( '' );
|
||||
$violations = TMDO_Promotion_Guard::violations();
|
||||
if ( empty( $violations ) ) {
|
||||
WP_CLI::log( ' [OK] Promotion Guard: no violation' );
|
||||
}
|
||||
foreach ( $violations as $entity_type => $integrations ) {
|
||||
WP_CLI::warning( " [GUARD] {$entity_type} is aeav_only while " . implode( ', ', $integrations ) . " reads native meta — write flat back with `wp tmdo bridge-restore-native {$entity_type} --demote`." );
|
||||
}
|
||||
|
||||
$status = get_option( TMDO_Drift_Check::OPTION, array() );
|
||||
$status = is_array( $status ) ? $status : array();
|
||||
WP_CLI::log( 'Drift (last `wp tmdo drift-check` or daily sample):' );
|
||||
foreach ( TMDO_Entity_Registry::VALID_ENTITY_TYPES as $entity_type ) {
|
||||
$groups = TMDO_Entity_Migration_Engine::backfillable_groups( $entity_type );
|
||||
$last = $status[ $entity_type ] ?? array();
|
||||
if ( empty( $groups ) || ( empty( $last ) && ! TMDO_Mode_Manager::writes_to_flat( $entity_type ) ) ) {
|
||||
continue;
|
||||
}
|
||||
if ( empty( $last ) ) {
|
||||
WP_CLI::log( " {$entity_type}: never checked — run `wp tmdo drift-check {$entity_type}`" );
|
||||
continue;
|
||||
}
|
||||
$drifting = array();
|
||||
foreach ( $last as $group => $s ) {
|
||||
if ( (int) $s['miss'] + (int) $s['diff'] + (int) $s['extra'] > 0 ) {
|
||||
$drifting[] = sprintf( '%s miss=%d diff=%d extra=%d', $group, $s['miss'], $s['diff'], $s['extra'] );
|
||||
}
|
||||
}
|
||||
$oldest = min( array_column( $last, 'checked_at' ) );
|
||||
if ( $drifting ) {
|
||||
WP_CLI::warning( " {$entity_type}: " . implode( '; ', $drifting ) . " (checked {$oldest} UTC or later) — `wp tmdo drift-check {$entity_type} --fix`" );
|
||||
} else {
|
||||
WP_CLI::log( sprintf( ' [OK] %s: %d group(s) clean (oldest check %s UTC)', $entity_type, count( $last ), $oldest ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run health check on all tables.
|
||||
*
|
||||
@@ -195,30 +272,12 @@ class TMDO_CLI {
|
||||
WP_CLI::log( $exists ? " [OK] {$t}" : " [NOT CREATED] {$t} (will be created on first use)" );
|
||||
}
|
||||
|
||||
// Check user entity flat tables (v2.5.5+).
|
||||
$user_entity_tables = array(
|
||||
$wpdb->prefix . 'wpdo_user_membership',
|
||||
$wpdb->prefix . 'wpdo_user_activity',
|
||||
$wpdb->prefix . 'wpdo_user_profile',
|
||||
$wpdb->prefix . 'wpdo_user_sso',
|
||||
$wpdb->prefix . 'wpdo_user_points_ledger',
|
||||
$wpdb->prefix . 'wpdo_migration_status',
|
||||
);
|
||||
foreach ( $user_entity_tables as $t ) {
|
||||
if ( TMDO_IS_SQLITE ) {
|
||||
$exists = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name=%s", $t ) );
|
||||
} else {
|
||||
$exists = $wpdb->get_var( $wpdb->prepare( 'SELECT COUNT(*) FROM information_schema.TABLES WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = %s', $t ) );
|
||||
}
|
||||
if ( $exists ) {
|
||||
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
||||
$rows = (int) $wpdb->get_var( "SELECT COUNT(*) FROM `{$t}`" );
|
||||
WP_CLI::log( " [OK] {$t} ({$rows} rows)" );
|
||||
} else {
|
||||
WP_CLI::warning( " [MISSING] {$t} — run \`wp wpdo install\` to create." );
|
||||
$all_ok = false;
|
||||
}
|
||||
// Entity flat tables, from the registry (was a hard-coded user list that
|
||||
// named the never-registered sso group).
|
||||
if ( ! self::check_entity_tables() ) {
|
||||
$all_ok = false;
|
||||
}
|
||||
self::report_guard_and_drift();
|
||||
|
||||
// Check partner plugin custom tables via Custom Table Registry (v2.6.0+).
|
||||
if ( class_exists( 'TMDO_Custom_Table_Registry' ) ) {
|
||||
|
||||
Reference in New Issue
Block a user