76c01e44df
對齊 A v3.2.0。型別強制會把隱式轉換變成 TypeError,所以一次全檔加入 並跑完整測試(unit 451 / integration 398 全綠,無迴歸)。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TbG1keQQ7XBa7qMQY16KCY
72 lines
1.8 KiB
PHP
72 lines
1.8 KiB
PHP
<?php
|
|
/**
|
|
* Migration phase: row-by-row backfill for groups with JSON/serialized fields.
|
|
*
|
|
* @package TMDO
|
|
* @since 3.0.1
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
exit;
|
|
}
|
|
|
|
/**
|
|
* Uses TMDO_Entity_Migration_Engine for groups whose fields contain JSON type,
|
|
* which cannot be bulk-pivoted via INSERT … SELECT.
|
|
*/
|
|
class TMDO_Phase_Backfill_Unserialize extends TMDO_Migration_Phase_Base {
|
|
|
|
/**
|
|
* Returns the phase slug.
|
|
*
|
|
* @return string
|
|
*/
|
|
public function name(): string {
|
|
return 'backfill_unserialize';
|
|
}
|
|
|
|
/**
|
|
* Executes the phase.
|
|
*
|
|
* @param array $job Job array (by reference).
|
|
* @return array{status: string}
|
|
* @throws \RuntimeException On migration engine failure.
|
|
*/
|
|
public function execute( array &$job ): array {
|
|
if ( ! empty( $job['options']['dry_run'] ) ) {
|
|
$this->log( $job, '↪ Backfill unserialize skipped (dry_run)' );
|
|
return array( 'status' => 'ok' );
|
|
}
|
|
|
|
$total_rows = 0;
|
|
|
|
foreach ( TMDO_Entity_Registry::get_groups_for_type( $this->entity_type ) as $group ) {
|
|
if ( ! $this->group_has_json_field( $group ) ) {
|
|
continue; // Handled in backfill_bulk.
|
|
}
|
|
|
|
$result = TMDO_Entity_Migration_Engine::migrate_group(
|
|
$this->entity_type,
|
|
$group,
|
|
array( 'sleep_ms' => 0 )
|
|
);
|
|
|
|
if ( ! empty( $result['error'] ) ) {
|
|
throw new \RuntimeException( "Row-by-row backfill {$group} failed: " . $result['error'] );
|
|
}
|
|
if ( ( $result['errors'] ?? 0 ) > 0 && 0 === ( $result['migrated'] ?? 0 ) ) {
|
|
throw new \RuntimeException( "All rows failed during {$group} backfill — see error_log" );
|
|
}
|
|
|
|
$total_rows += (int) ( $result['migrated'] ?? 0 );
|
|
$this->log( $job, sprintf( ' • row-by-row %s: %d row(s)', $group, $result['migrated'] ?? 0 ) );
|
|
}
|
|
|
|
$this->log( $job, sprintf( 'Row-by-row backfill: %d rows total', $total_rows ) );
|
|
return array( 'status' => 'ok' );
|
|
}
|
|
}
|