refactor(2meet-data-optimizer): stop registering the wc_product post group

- WooCommerce reads product meta directly and writes stock by SQL, so a flat copy drifted (R-2.1 V1 T4); product meta now stays in native only (plan decision 2). TMDO_Post_Fields registers wp_core, attachment and nav_menu_item. Existing wp_wpdo_post_wc_product tables are left in place and still dropped on uninstall; the orphan restore registers nothing for them while native meta holds the keys; `wp tmdo bridge-restore-native post --group=wc_product --retire` archives them.
- Tests that route products register the former group themselves (tmdo_test_register_wc_product_group(), same name and table); live router Q06 runs on wp_core's _wp_page_template instead of _sku. The post stress tester already skips flat tables that do not exist.
- Verify: PostFieldsRegistrationTest (RED before); dev36: wc_product absent from the registry and not restored as an orphan, a CLI order took stock 452 → 450 in native with no DB error (reverted), drift post 10 groups 0.
- PR: PR-077
This commit is contained in:
2026-09-27 01:11:52 +08:00
parent f15473527c
commit f48df1a33f
12 changed files with 68 additions and 174 deletions
@@ -129,6 +129,7 @@ class PostEntityLifecycleTest extends TestCase {
WPDO_Entity_Registry::init();
WPDO_Entity_Registry::register_adapter( 'post', new WPDO_Adapter_Post() );
WPDO_Post_Fields::register_entity_fields();
tmdo_test_register_wc_product_group();
}
public static function tearDownAfterClass(): void {
+1
View File
@@ -93,6 +93,7 @@ class PostMigrationTest extends TestCase {
WPDO_Entity_Registry::init();
WPDO_Entity_Registry::register_adapter( 'post', new WPDO_Adapter_Post() );
WPDO_Post_Fields::register_entity_fields();
tmdo_test_register_wc_product_group();
}
public static function tearDownAfterClass(): void {
@@ -15,6 +15,7 @@ class PostQueryRouterDriftTest extends TestCase {
WPDO_Entity_Registry::init();
WPDO_Entity_Registry::register_adapter( 'post', new WPDO_Adapter_Post() );
WPDO_Post_Fields::register_entity_fields();
tmdo_test_register_wc_product_group();
}
public static function tearDownAfterClass(): void {
@@ -20,6 +20,7 @@ class PostQueryRouterOrderTest extends TestCase {
WPDO_Entity_Registry::init();
WPDO_Entity_Registry::register_adapter( 'post', new WPDO_Adapter_Post() );
WPDO_Post_Fields::register_entity_fields();
tmdo_test_register_wc_product_group();
}
protected function setUp(): void {
@@ -39,6 +39,7 @@ class PostQueryRouterTest extends TestCase {
WPDO_Entity_Registry::init();
WPDO_Entity_Registry::register_adapter( 'post', new WPDO_Adapter_Post() );
WPDO_Post_Fields::register_entity_fields();
tmdo_test_register_wc_product_group();
}
public static function tearDownAfterClass(): void {
+40
View File
@@ -649,3 +649,43 @@ if ( ! class_exists( 'TMDO_Listing_Stats' ) ) {
}
class_alias( 'TMDO_Listing_Stats', 'WPDO_Listing_Stats' );
}
/**
* The WooCommerce product group core registered before 1.2.0 (PR-077 moved
* product meta back to native only). Tests that use products as a routed
* post type register it themselves; the table name wp_itest_wpdo_post_wc_product
* is unchanged.
*/
function tmdo_test_register_wc_product_group(): void {
$enum = static fn( string $key, array $options ): array => array(
'key' => $key,
'type' => 'enum',
'options' => $options,
);
TMDO_Entity_Registry::register_group(
'post',
'wc_product',
array(
array( 'key' => '_price', 'type' => 'decimal', 'searchable' => true ),
array( 'key' => '_regular_price', 'type' => 'decimal', 'searchable' => true ),
array( 'key' => '_sale_price', 'type' => 'decimal', 'searchable' => true ),
array( 'key' => '_stock', 'type' => 'integer', 'searchable' => true ),
array( 'key' => '_stock_status', 'type' => 'enum', 'searchable' => true, 'options' => array( 'instock', 'outofstock', 'onbackorder' ) ),
array( 'key' => '_sku', 'type' => 'text', 'searchable' => true ),
$enum( '_manage_stock', array( 'yes', 'no' ) ),
$enum( '_backorders', array( 'yes', 'no', 'notify' ) ),
$enum( '_sold_individually', array( 'yes', 'no' ) ),
$enum( '_virtual', array( 'yes', 'no' ) ),
$enum( '_downloadable', array( 'yes', 'no' ) ),
array( 'key' => '_tax_class', 'type' => 'text' ),
$enum( '_tax_status', array( 'taxable', 'shipping', 'none' ) ),
array( 'key' => '_download_limit', 'type' => 'integer' ),
array( 'key' => '_download_expiry', 'type' => 'integer' ),
array( 'key' => '_product_version', 'type' => 'text' ),
array( 'key' => '_wc_average_rating', 'type' => 'decimal', 'searchable' => true ),
array( 'key' => '_wc_review_count', 'type' => 'integer' ),
array( 'key' => 'total_sales', 'type' => 'integer', 'searchable' => true ),
),
array( 'post_types' => array( 'product' ) )
);
}