Files
2meet-data-optimizer/includes/migration/phases/class-tmdo-phase-backfill-bulk.php
T
wpdev 76c01e44df refactor: 全部 128 個生產檔加入 declare(strict_types=1)(PR-H)
對齊 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
2026-07-31 06:13:33 +08:00

65 lines
1.6 KiB
PHP

<?php
/**
* Migration phase: bulk pivot text-only meta groups via INSERT … SELECT.
*
* @package TMDO
* @since 3.0.1
*/
declare(strict_types=1);
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Iterates all registered groups for the entity type and pivots each
* text-only group in a single INSERT … SELECT … ON DUPLICATE KEY UPDATE.
*/
class TMDO_Phase_Backfill_Bulk extends TMDO_Migration_Phase_Base {
/**
* Returns the phase slug.
*
* @return string
*/
public function name(): string {
return 'backfill_bulk';
}
/**
* Executes the phase.
*
* @param array $job Job array (by reference).
* @return array{status: string}
* @throws \RuntimeException On DB pivot failure.
*/
public function execute( array &$job ): array {
if ( ! empty( $job['options']['dry_run'] ) ) {
$this->log( $job, '↪ Backfill bulk skipped (dry_run)' );
return array( 'status' => 'ok' );
}
$total_groups = 0;
$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_unserialize.
}
$rows = $this->execute_bulk_pivot( $group );
$total_rows += $rows;
++$total_groups;
$this->log( $job, sprintf( ' • bulk pivot %s: %d row(s)', $group, $rows ) );
}
$this->log( $job, sprintf( 'Bulk backfill: %d groups, %d rows total', $total_groups, $total_rows ) );
$preflight = TMDO_Migration_Orchestrator::preflight();
$job['metrics']['eav_rows_now'] = $preflight['eav_rows'];
$job['metrics']['ratio_now'] = $preflight['ratio'];
return array( 'status' => 'ok' );
}
}