feat(2meet-data-optimizer): guard orphaned flat-table groups

- On init:1, re-register aeav_only groups whose flat table exists and whose definition is in wpdo_registry_meta but no active plugin registers them, so their data stays readable (routing only, never DDL)
- Keys owned by a live group, or with rows in native meta (newer data written while orphaned), are left alone; the native-meta check is cached for a day
- Surface restored groups via Site Health (wpdo_orphaned_entity_groups), the admin Doctor tab, and wp wpdo doctor
- Verify: EntityRegistryRestoreTest (9), OrphanGroupRestoreTest (7); core unit 622 / integration 439, HP 141/49, WC 10/22 OK; dry-run on dev20–22 restores 16/17/4 groups, keeps hp_taxonomy hp_sort_order/hp_icon on native
- PR: PR-018
This commit is contained in:
2026-09-25 23:38:12 +08:00
parent e9d8696c93
commit 1653011f4f
9 changed files with 583 additions and 20 deletions
+45 -2
View File
@@ -2,7 +2,7 @@
/**
* TMDO_Site_Health — WordPress Site Health integration (v2.2.0 M3).
*
* Registers 8 tests under Tools → Site Health → Status:
* Registers 9 tests under Tools → Site Health → Status:
* 1. wpdo_schema_drift (critical)
* 2. wpdo_error_budget (recommended)
* 3. wpdo_hook_conflicts (recommended)
@@ -11,6 +11,7 @@
* 6. wpdo_orphan_zone_rows (recommended)
* 7. wpdo_missing_snapshot (critical)
* 8. wpdo_entity_group_collisions (recommended)
* 9. wpdo_orphaned_entity_groups (recommended)
*
* Each test result is cached for 5 minutes to keep Site Health responsive.
*
@@ -43,6 +44,7 @@ class TMDO_Site_Health {
'wpdo_orphan_zone_rows' => 'check_orphan_zone_rows',
'wpdo_missing_snapshot' => 'check_missing_snapshot',
'wpdo_entity_group_collisions' => 'check_entity_group_collisions',
'wpdo_orphaned_entity_groups' => 'check_orphaned_entity_groups',
);
/**
@@ -55,7 +57,7 @@ class TMDO_Site_Health {
}
/**
* Register the 8 tests with WP Site Health.
* Register the 9 tests with WP Site Health.
*
* @param array $tests Existing tests.
* @return array
@@ -86,6 +88,7 @@ class TMDO_Site_Health {
'wpdo_orphan_zone_rows' => __( 'WPDO orphan zone rows', '2meet-data-optimizer' ),
'wpdo_missing_snapshot' => __( 'WPDO missing snapshot', '2meet-data-optimizer' ),
'wpdo_entity_group_collisions' => __( 'WPDO entity group collisions', '2meet-data-optimizer' ),
'wpdo_orphaned_entity_groups' => __( 'WPDO orphaned entity groups', '2meet-data-optimizer' ),
);
return $map[ $key ] ?? $key;
}
@@ -468,6 +471,46 @@ class TMDO_Site_Health {
);
}
// ─── Test 9: Orphaned entity groups ─────────────────────────────────
/**
* Report flat-table groups kept alive from wpdo_registry_meta because no
* active plugin registers them any more.
*
* Not cached for the same reason as check_entity_group_collisions().
*
* @return array Site Health result.
*/
public static function check_orphaned_entity_groups(): array {
$restored = class_exists( 'TMDO_Entity_Registry' ) ? TMDO_Entity_Registry::get_restored_groups() : array();
if ( empty( $restored ) ) {
return self::wrap( 'wpdo_orphaned_entity_groups', self::pass( __( 'Every flat-table group is registered by an active plugin.', '2meet-data-optimizer' ) ) );
}
$lines = array();
foreach ( $restored as $r ) {
$lines[] = sprintf(
'%s/%s (%d fields%s%s)',
$r['entity_type'],
$r['group'],
$r['fields'],
$r['skipped'] ? ', skipped: ' . implode( ',', $r['skipped'] ) : '',
$r['native'] ? ', left on native meta (newer data there): ' . implode( ',', $r['native'] ) : ''
);
}
return self::wrap(
'wpdo_orphaned_entity_groups',
self::fail(
__( 'WPDO entity groups restored from stored definitions', '2meet-data-optimizer' ),
sprintf(
/* translators: %s: list of entity/group names */
__( 'No active plugin registers these groups, so their stored definitions were re-applied to keep the flat-table data readable. Reactivate the owning plugin, or write the data back to native meta before removing it: %s', '2meet-data-optimizer' ),
implode( '; ', $lines )
),
'recommended'
)
);
}
/**
* Wrap a raw check result with required Site Health envelope fields.
*