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:
@@ -259,6 +259,50 @@ class TMDO_CLI_Post {
|
||||
);
|
||||
}
|
||||
|
||||
// ── post-reconcile-groups ─────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Move post values written under legacy routing into their post type's
|
||||
* group table, then switch on post_type-scoped routing.
|
||||
*
|
||||
* Needed once on sites that already hold post flat rows (the installer
|
||||
* leaves tmdo_post_scoped_routing off there). Resumable: an interrupted
|
||||
* run continues from its cursor.
|
||||
*
|
||||
* ## OPTIONS
|
||||
*
|
||||
* [--dry-run]
|
||||
* : Count the values that would be copied / overwritten; write nothing.
|
||||
*
|
||||
* [--batch=<n>]
|
||||
* : Rows per batch. Default 500.
|
||||
*
|
||||
* ## EXAMPLES
|
||||
*
|
||||
* wp tmdo post-reconcile-groups --dry-run
|
||||
* wp tmdo post-reconcile-groups
|
||||
*
|
||||
* @param array $args Positional arguments (unused).
|
||||
* @param array $assoc_args Named arguments.
|
||||
*/
|
||||
public function post_reconcile_groups( $args, $assoc_args ): void {
|
||||
$dry_run = isset( $assoc_args['dry-run'] );
|
||||
$report = TMDO_Post_Group_Reconciler::run( $dry_run, (int) ( $assoc_args['batch'] ?? 500 ) );
|
||||
|
||||
if ( empty( $report['moves'] ) ) {
|
||||
WP_CLI::log( 'No shared post keys to move.' );
|
||||
}
|
||||
foreach ( $report['moves'] as $m ) {
|
||||
WP_CLI::log( sprintf( '%s → %s %s: %d value(s)%s', $m['source'], $m['target'], $m['key'], $m['copied'], $dry_run ? sprintf( ', %d would overwrite a different value', $m['overwritten'] ) : '' ) );
|
||||
}
|
||||
|
||||
if ( $dry_run ) {
|
||||
WP_CLI::success( '[dry-run] Nothing written. Re-run without --dry-run to copy and switch on scoped routing.' );
|
||||
return;
|
||||
}
|
||||
WP_CLI::success( 'Post groups reconciled; tmdo_post_scoped_routing is on.' );
|
||||
}
|
||||
|
||||
// ── post-cleanup (v2.9.3) ─────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
@@ -853,3 +897,5 @@ WP_CLI::add_command( 'wpdo post-benchmark', array( 'TMDO_CLI_Post', 'post_benchm
|
||||
WP_CLI::add_command( 'tmdo post-benchmark', array( 'TMDO_CLI_Post', 'post_benchmark' ) );
|
||||
WP_CLI::add_command( 'wpdo post-shadow-report', array( 'TMDO_CLI_Post', 'post_shadow_report' ) );
|
||||
WP_CLI::add_command( 'tmdo post-shadow-report', array( 'TMDO_CLI_Post', 'post_shadow_report' ) );
|
||||
WP_CLI::add_command( 'wpdo post-reconcile-groups', array( 'TMDO_CLI_Post', 'post_reconcile_groups' ) );
|
||||
WP_CLI::add_command( 'tmdo post-reconcile-groups', array( 'TMDO_CLI_Post', 'post_reconcile_groups' ) );
|
||||
|
||||
Reference in New Issue
Block a user