fix(2meet-data-optimizer): serialize arrays in text fields instead of storing "Array"
- TMDO_Type_Caster: text / textarea values that are arrays or objects are stored with maybe_serialize() (was (string) → the literal "Array", which bridge-restore-native then wrote back over native meta); from_db() unserializes them with TMDO_Safe_Unserialize. text columns are VARCHAR(255): longer values are stored NULL (native keeps them) and logged as text_overflow. - Add `wp tmdo repair-array-literals [--entity] [--confirm]` (TMDO_Array_Literal_Repair): rewrites flat "Array" values from native meta and lists native rows that are "Array" themselves (backup needed). - Verify: TypeCasterSerializeTest 13 OK, ArrayLiteralRepairTest 3 OK; unit 685 OK, integration 483 OK, phpcs (phpcs.xml) 0, stan OK; live `serialized` 3 PASS; dev36 repair dry-run lists the value corrupted by the 2026-09-26 round trip (user #1 community-events-location) - PR: PR-055
This commit is contained in:
@@ -217,6 +217,50 @@ class TMDO_CLI_V2 {
|
||||
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.' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Find flat text / textarea values stored as the literal "Array" (pre-1.1.0
|
||||
* type caster) and rewrite them from native meta.
|
||||
*
|
||||
* Native rows that are "Array" too cannot be repaired here; they are listed
|
||||
* so they can be restored from a backup.
|
||||
*
|
||||
* ## OPTIONS
|
||||
*
|
||||
* [--entity=<entity>]
|
||||
* : post | user | term | comment. Default: all four.
|
||||
*
|
||||
* [--confirm]
|
||||
* : Write the repairs. Without it the command only reports.
|
||||
*
|
||||
* ## EXAMPLES
|
||||
*
|
||||
* wp tmdo repair-array-literals
|
||||
* wp tmdo repair-array-literals --entity=user --confirm
|
||||
*
|
||||
* @param array<int, string> $args Positional arguments (unused).
|
||||
* @param array<string, string> $assoc_args Named arguments.
|
||||
*/
|
||||
public function repair_array_literals( $args, $assoc_args ): void {
|
||||
$entities = isset( $assoc_args['entity'] ) ? array( (string) $assoc_args['entity'] ) : TMDO_Entity_Registry::VALID_ENTITY_TYPES;
|
||||
$apply = isset( $assoc_args['confirm'] );
|
||||
|
||||
foreach ( $entities as $entity ) {
|
||||
if ( ! in_array( $entity, TMDO_Entity_Registry::VALID_ENTITY_TYPES, true ) ) {
|
||||
WP_CLI::error( "Unknown entity: {$entity}" );
|
||||
}
|
||||
$report = TMDO_Array_Literal_Repair::run( $entity, $apply );
|
||||
WP_CLI::log( sprintf( '%s: %d "Array" value(s) in flat tables, %d repairable from native, %d repaired.', $entity, $report['found'], $report['repairable'], $report['repaired'] ) );
|
||||
foreach ( $report['unrepairable'] as $row ) {
|
||||
WP_CLI::log( sprintf( ' unrepairable %s/%s #%d (%s)', $row['group'], $row['key'], $row['id'], $row['reason'] ) );
|
||||
}
|
||||
foreach ( $report['native_polluted'] as $row ) {
|
||||
WP_CLI::warning( sprintf( 'native meta is "Array": %s %s #%d — restore it from a backup', $entity, $row['key'], $row['id'] ) );
|
||||
}
|
||||
}
|
||||
|
||||
WP_CLI::success( $apply ? 'Repair finished.' : '[dry-run] Nothing written. Re-run with --confirm to repair.' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Audit per-module state + shadow_read flags.
|
||||
*
|
||||
@@ -851,6 +895,8 @@ WP_CLI::add_command( 'wpdo bridge-set', array( 'TMDO_CLI_V2', 'bridge_set' ) );
|
||||
WP_CLI::add_command( 'tmdo bridge-set', array( 'TMDO_CLI_V2', 'bridge_set' ) );
|
||||
WP_CLI::add_command( 'wpdo bridge-restore-native', array( new TMDO_CLI_V2(), 'bridge_restore_native' ) );
|
||||
WP_CLI::add_command( 'tmdo bridge-restore-native', array( new TMDO_CLI_V2(), 'bridge_restore_native' ) );
|
||||
WP_CLI::add_command( 'wpdo repair-array-literals', array( new TMDO_CLI_V2(), 'repair_array_literals' ) );
|
||||
WP_CLI::add_command( 'tmdo repair-array-literals', array( new TMDO_CLI_V2(), 'repair_array_literals' ) );
|
||||
WP_CLI::add_command( 'wpdo mode-audit', array( 'TMDO_CLI_V2', 'mode_audit' ) );
|
||||
WP_CLI::add_command( 'tmdo mode-audit', array( 'TMDO_CLI_V2', 'mode_audit' ) );
|
||||
WP_CLI::add_command( 'wpdo mode-set', array( 'TMDO_CLI_V2', 'mode_set' ) );
|
||||
|
||||
Reference in New Issue
Block a user