refactor(2meet-data-optimizer): list post groups for backfill from the registry

- Admin "backfill all" and `wp tmdo post-migrate-group` take any registered post group via TMDO_Post_Migration::backfillable_groups() instead of a hard-coded list of 7 (dev36 registers 11; the 4 HP add-on groups were never backfilled). Restored orphan groups are excluded and rejected — their values live only in the flat table.
- Groups with json fields (attachment, nav_menu_item) go row by row through the migration engine instead of leaving the json columns NULL in the bulk pivot.
- Verify: PostBackfillJsonTest (3 RED on hardening/2.2); dev36 post-migrate-group attachment / nav_menu_item / hp_draft_flags: json columns semantically equal native (24/24, 21/21), checker unchanged.
- PR: PR-067
This commit is contained in:
2026-09-26 22:54:27 +08:00
parent 13ea341ef8
commit 7807eae957
4 changed files with 82 additions and 25 deletions
@@ -215,6 +215,38 @@ class PostBackfillJsonTest extends TestCase {
$this->assertSame( 0, $result['errors'] ?? -1 );
}
// ── backfill_group() / backfillable_groups() (2.2 PR-067) ───────────────
public function test_backfill_group_fills_json_columns_instead_of_skipping_them(): void {
$this->seed_attachment( 1, array( 'width' => 640 ), 'Alt text' );
$result = WPDO_Post_Migration::backfill_group( 'attachment' );
$this->assertSame( 'attachment', $result['group'] );
global $wpdb;
$row = $wpdb->get_row( 'SELECT _wp_attachment_metadata, _wp_attachment_image_alt FROM `' . self::FLAT . '` WHERE post_id = 1', ARRAY_A );
$this->assertSame( array( 'width' => 640 ), json_decode( (string) $row['_wp_attachment_metadata'], true ), 'json field must not be left NULL by the bulk pivot' );
$this->assertSame( 'Alt text', $row['_wp_attachment_image_alt'] );
}
public function test_backfillable_groups_are_the_registered_post_groups(): void {
WPDO_Entity_Registry::register_group( 'post', 'itest_extra', array( array( 'key' => 'itest_extra_key', 'type' => 'text' ) ) );
$groups = WPDO_Post_Migration::backfillable_groups();
$this->assertSame( WPDO_Entity_Registry::get_groups_for_type( 'post' ), $groups );
$this->assertContains( 'itest_extra', $groups, 'a group registered by an add-on must be offered for backfill' );
}
public function test_restored_orphan_groups_are_never_backfilled(): void {
WPDO_Entity_Registry::restore_group( 'post', 'itest_orphan', array( array( 'key' => 'itest_orphan_key', 'type' => 'text' ) ) );
$this->assertContains( 'itest_orphan', WPDO_Entity_Registry::get_groups_for_type( 'post' ) );
$this->assertNotContains( 'itest_orphan', WPDO_Post_Migration::backfillable_groups(), 'orphan data lives only in the flat table' );
$this->expectException( InvalidArgumentException::class );
WPDO_Post_Migration::backfill_group( 'itest_orphan' );
}
public function test_returns_error_for_unknown_group(): void {
$result = WPDO_Post_Migration::backfill_group_json( 'bogus_group' );