feat(2meet-data-optimizer): reconcile post rows written to the wrong group table
- TMDO_Post_Group_Reconciler copies non-NULL values that legacy routing stored in another group's table into the post type's own group (NULL/missing legacy values keep the scoped value), resumable via a cursor, with a catch-up pass for rows updated during the run, then switches on tmdo_post_scoped_routing - CLI: wp tmdo post-reconcile-groups [--dry-run] [--batch=<n>]; registry exposes get_group_post_types() - Verify: PostGroupReconcilerPlanTest (4), PostGroupReconcilerTest (6); core unit 635 / integration 449, HP 145/49, WC 10/22 OK; read-only dry-run: dev20 320 values / 0 overwrites, dev21/22 none - PR: PR-034
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Which values the reconciler has to move.
|
||||
*
|
||||
* Under legacy routing a key shared by several post groups was read and
|
||||
* written through the last group registered. Once lookups follow the post
|
||||
* type, each scoped group must first receive the values its posts stored in
|
||||
* that legacy owner's table.
|
||||
*/
|
||||
class PostGroupReconcilerPlanTest extends TestCase {
|
||||
|
||||
protected function setUp(): void {
|
||||
TMDO_Entity_Registry::init();
|
||||
TMDO_Entity_Registry::register_adapter( 'post', $this->createMock( TMDO_Entity_Adapter_Interface::class ) );
|
||||
}
|
||||
|
||||
public function test_plan_lists_shared_keys_whose_legacy_owner_is_another_group(): void {
|
||||
TMDO_Entity_Registry::register_group( 'post', 'listing', array( array( 'key' => 'shared', 'type' => 'text' ), array( 'key' => 'price', 'type' => 'decimal' ) ), array( 'post_types' => array( 'hp_listing' ) ) );
|
||||
TMDO_Entity_Registry::register_group( 'post', 'vendor', array( array( 'key' => 'shared', 'type' => 'text' ) ), array( 'post_types' => array( 'hp_vendor' ) ) );
|
||||
|
||||
$this->assertSame(
|
||||
array(
|
||||
array(
|
||||
'target' => 'listing',
|
||||
'source' => 'vendor',
|
||||
'key' => 'shared',
|
||||
'post_types' => array( 'hp_listing' ),
|
||||
),
|
||||
),
|
||||
TMDO_Post_Group_Reconciler::plan()
|
||||
);
|
||||
}
|
||||
|
||||
public function test_unscoped_groups_and_unshared_keys_need_no_move(): void {
|
||||
TMDO_Entity_Registry::register_group( 'post', 'site', array( array( 'key' => '_edit_lock', 'type' => 'text' ) ) );
|
||||
TMDO_Entity_Registry::register_group( 'post', 'listing', array( array( 'key' => 'price', 'type' => 'decimal' ) ), array( 'post_types' => array( 'hp_listing' ) ) );
|
||||
|
||||
$this->assertSame( array(), TMDO_Post_Group_Reconciler::plan() );
|
||||
}
|
||||
|
||||
public function test_registry_exposes_group_post_types(): void {
|
||||
TMDO_Entity_Registry::register_group( 'post', 'listing', array( array( 'key' => 'price', 'type' => 'decimal' ) ), array( 'post_types' => array( 'hp_listing' ) ) );
|
||||
TMDO_Entity_Registry::register_group( 'post', 'site', array( array( 'key' => '_edit_lock', 'type' => 'text' ) ) );
|
||||
|
||||
$this->assertSame( array( 'hp_listing' ), TMDO_Entity_Registry::get_group_post_types( 'post', 'listing' ) );
|
||||
$this->assertSame( array(), TMDO_Entity_Registry::get_group_post_types( 'post', 'site' ) );
|
||||
|
||||
TMDO_Entity_Registry::init();
|
||||
$this->assertSame( array(), TMDO_Entity_Registry::get_group_post_types( 'post', 'listing' ) );
|
||||
}
|
||||
|
||||
public function test_core_hivepress_groups_plan_the_eight_misrouted_keys(): void {
|
||||
TMDO_Post_Fields::register_entity_fields();
|
||||
|
||||
$moves = array();
|
||||
foreach ( TMDO_Post_Group_Reconciler::plan() as $m ) {
|
||||
$moves[] = "{$m['source']}>{$m['target']}:{$m['key']}";
|
||||
}
|
||||
sort( $moves );
|
||||
|
||||
$this->assertSame(
|
||||
array(
|
||||
'hp_request_core>hp_listing_core:hp_expired_time',
|
||||
'hp_request_core>hp_listing_core:hp_status',
|
||||
'hp_request_core>hp_listing_core:hp_view_count',
|
||||
'hp_vendor_core>hp_listing_core:hp_hourly_rate',
|
||||
'hp_vendor_core>hp_listing_core:hp_rating',
|
||||
'hp_vendor_core>hp_listing_core:hp_rating_count',
|
||||
'hp_vendor_core>hp_listing_core:hp_verified',
|
||||
'hp_vendor_core>hp_request_core:hp_user',
|
||||
),
|
||||
$moves
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user