feat(2meet-data-optimizer): group-scoped native write-back and group retirement
- TMDO_Native_Restorer::run() takes an optional group; the CLI gains `bridge-restore-native <entity> --group=<g>`. - New retire(): once native meta holds every non-NULL value of a group's flat table (checked against the persisted field definitions), forget its registry_meta row and rename the table to <table>_retired_<Ymd>, so orphan restore no longer routes its keys to the flat table. Refused while a plugin still registers the group or any value differs. CLI: `--group=<g> --retire`. - For retiring the user `sso` group (SSO AddOn deprecation). - Verify: core unit 659 / integration 479 green, phpcs clean - PR: PR-042
This commit is contained in:
@@ -170,18 +170,31 @@ class TMDO_CLI_V2 {
|
||||
* [--demote]
|
||||
* : After a complete run, switch the entity to dual_write (both copies kept in step).
|
||||
*
|
||||
* [--group=<group>]
|
||||
* : Only this group.
|
||||
*
|
||||
* [--retire]
|
||||
* : With --group, after the write-back: forget the group (registry_meta row)
|
||||
* and rename its flat table to <table>_retired_<Ymd>. Refused while a plugin
|
||||
* still registers the group or native meta differs from the flat table.
|
||||
*
|
||||
* ## EXAMPLES
|
||||
*
|
||||
* wp tmdo bridge-restore-native user --dry-run
|
||||
* wp tmdo bridge-restore-native user --demote
|
||||
* wp tmdo bridge-restore-native user --group=sso --retire
|
||||
*/
|
||||
public function bridge_restore_native( $args, $assoc_args ): void {
|
||||
$entity = (string) ( $args[0] ?? '' );
|
||||
if ( ! in_array( $entity, TMDO_Entity_Registry::VALID_ENTITY_TYPES, true ) ) {
|
||||
WP_CLI::error( 'Usage: wp tmdo bridge-restore-native <post|user|term|comment> [--dry-run] [--batch=<n>] [--demote]' );
|
||||
WP_CLI::error( 'Usage: wp tmdo bridge-restore-native <post|user|term|comment> [--dry-run] [--batch=<n>] [--demote] [--group=<group> [--retire]]' );
|
||||
}
|
||||
$dry_run = isset( $assoc_args['dry-run'] );
|
||||
$report = TMDO_Native_Restorer::run( $entity, $dry_run, (int) ( $assoc_args['batch'] ?? 500 ), isset( $assoc_args['demote'] ) );
|
||||
$group = sanitize_key( (string) ( $assoc_args['group'] ?? '' ) );
|
||||
if ( isset( $assoc_args['retire'] ) && '' === $group ) {
|
||||
WP_CLI::error( '--retire needs --group=<group>.' );
|
||||
}
|
||||
$report = TMDO_Native_Restorer::run( $entity, $dry_run, (int) ( $assoc_args['batch'] ?? 500 ), isset( $assoc_args['demote'] ), $group );
|
||||
|
||||
foreach ( $report['groups'] as $group => $g ) {
|
||||
WP_CLI::log( sprintf( '%s/%s: %d row(s)%s', $entity, $group, $g['rows'], $dry_run ? '' : sprintf( ', %d native value(s) written', $g['written'] ) ) );
|
||||
@@ -190,6 +203,14 @@ class TMDO_CLI_V2 {
|
||||
WP_CLI::success( '[dry-run] Nothing written.' );
|
||||
return;
|
||||
}
|
||||
if ( isset( $assoc_args['retire'] ) ) {
|
||||
$retired = TMDO_Native_Restorer::retire( $entity, $group );
|
||||
if ( 'retired' !== $retired['status'] ) {
|
||||
WP_CLI::error( sprintf( 'Not retired (%s%s). Written values stay in native meta.', $retired['status'], $retired['mismatches'] ? ", {$retired['mismatches']} value(s) differ" : '' ) );
|
||||
}
|
||||
WP_CLI::success( "{$entity}/{$group} retired; flat table kept as {$retired['archived_table']}." );
|
||||
return;
|
||||
}
|
||||
WP_CLI::success( $report['demoted'] ? "Restored; {$entity} is now dual_write." : 'Restored. Demote the entity to dual_write (admin Entity Bridge tab) before its next write, or re-run with --demote.' );
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user