feat(2meet-data-optimizer): repair drifted flat rows from native with drift-check --fix

- TMDO_Drift_Check::fix() deletes flat rows of deleted entities and, for post groups, of posts outside the group's post types; rebuilds every other drifted entity's row from native through the new TMDO_Entity_Migration_Engine::migrate_entity() (keys without native rows become NULL, PR-066); keeps a row whose entity has no native value for the group but clears its columns (no NULL-only inserts, no deleted rows the router may join on); invalidates the row cache of each touched entity; then checks again. Native meta is never written.
- `wp tmdo drift-check <entity> --fix` (not combinable with --sample).
- Verify: DriftCheckTest fix cases (RED: method missing); dev36 --fix: post 42 rows rebuilt, 1 stray row (post 312, hp_booking in hp_draft_flags) deleted, all four entities 0 drift after, checker miss/extra 0.
- PR: PR-071
This commit is contained in:
2026-09-27 00:07:33 +08:00
parent 02045c6f07
commit 3a347269c8
4 changed files with 222 additions and 29 deletions
@@ -182,6 +182,28 @@ final class TMDO_Entity_Migration_Engine {
return $stats;
}
/**
* Rebuild one entity's row of a group from native meta.
*
* @return bool False when native holds none of the group's keys (nothing written).
*/
public static function migrate_entity( string $entity_type, string $group_name, int $entity_id ): bool {
$adapter = TMDO_Entity_Registry::get_adapter( $entity_type );
$group_fields = TMDO_Entity_Registry::get_group_fields( $entity_type, $group_name );
if ( ! $adapter || empty( $group_fields ) ) {
return false;
}
return self::migrate_single_entity(
$entity_type,
$group_name,
$entity_id,
array_column( $group_fields, 'key' ),
array_column( $group_fields, null, 'key' ),
$adapter,
false
);
}
/**
* 遷移單一 entity 的所有 meta
*/