refactor(migration): 回填 Migration Phase Strategy 體系(PR-D)
A v3.0.1 把 orchestrator 的 11 個 phase 抽成可注入的 Phase 物件,B 仍是 1107 行單體、以 'phase_' . $current 字串魔法分派、completed 甚至 inline 在 tick() 裡。本 commit 對齊: 新增 13 檔 - includes/migration/interface-migration-phase.php - includes/migration/class-tmdo-migration-phase-base.php(log/get_managed_keys/ execute_bulk_pivot/values_loose_equal 等共用 helper) - includes/migration/phases/ 11 個 phase 類別 orchestrator 1107 → 640 行 - tick() 改 make_phase() 工廠 + $phase->execute($job) - 移除 final、self::ENTITY_TYPE → static::(A v3.3.0 late static binding) - 保留 B 原有的 '✓ %s (%.2fs)' 耗時 log(改為 tick 自行量測,A 版已簡化掉) - 公開介面(preflight/start/tick/get_status/cancel/resume/needs_attention/ cron_tick)經 diff 確認與 A 完全一致,呼叫端零影響 連帶 - Schema_Manager 補 table_exists 的 request-scoped cache 與 flush_table_exists_cache()(A v3.1.6 + v3.4.6),Phase 測試需要它 - back-compat 補 12 個 Phase 類別的 WPDO_ alias - 移植 MigrationPhaseTest + MigrationPhaseRemainingTest(527 行) 測試隔離差異(B 的 unit bootstrap 會載入 Member_Fields / Post_Fields, A 的不會):MigrationPhaseRemainingTest 的 setUp 需額外清空 Entity_Registry 與 wpdo_register_entity_fields listener,否則 install_schema 會真的走進 dbDelta。MigrationPhaseTest 的 interface 斷言改用 TMDO_ 正式名稱 (PHP 無法 class_alias 介面,且該契約是核心內部擴充點)。 unit 451 / integration 398 GREEN Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TbG1keQQ7XBa7qMQY16KCY
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/**
|
||||
* Migration phase: demote entity mode from aeav_only back to dual_write.
|
||||
*
|
||||
* @package TMDO
|
||||
* @since 3.0.1
|
||||
*/
|
||||
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Two-step mode demotion: aeav_only → shadow_read → dual_write.
|
||||
*/
|
||||
class TMDO_Phase_Demote extends TMDO_Migration_Phase_Base {
|
||||
|
||||
/**
|
||||
* Returns the phase slug.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function name(): string {
|
||||
return 'demote';
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the phase.
|
||||
*
|
||||
* @param array $job Job array (by reference).
|
||||
* @return array{status: string}
|
||||
* @throws \RuntimeException If mode transition fails.
|
||||
*/
|
||||
public function execute( array &$job ): array {
|
||||
$current = TMDO_Mode_Manager::get( $this->entity_type );
|
||||
|
||||
if ( TMDO_Mode_Manager::MODE_AEAV_ONLY !== $current ) {
|
||||
$this->log( $job, "↪ Demote skipped (mode is {$current}, not aeav_only)" );
|
||||
return array( 'status' => 'ok' );
|
||||
}
|
||||
|
||||
// Two-step demotion: aeav_only → shadow_read → dual_write.
|
||||
$r = TMDO_Mode_Manager::set( $this->entity_type, TMDO_Mode_Manager::MODE_SHADOW_READ );
|
||||
if ( is_wp_error( $r ) ) {
|
||||
throw new \RuntimeException( 'Demote step 1 failed: ' . $r->get_error_message() );
|
||||
}
|
||||
|
||||
$r = TMDO_Mode_Manager::set( $this->entity_type, TMDO_Mode_Manager::MODE_DUAL_WRITE );
|
||||
if ( is_wp_error( $r ) ) {
|
||||
throw new \RuntimeException( 'Demote step 2 failed: ' . $r->get_error_message() );
|
||||
}
|
||||
|
||||
$this->log( $job, 'Mode: aeav_only → dual_write (reads now go to EAV)' );
|
||||
return array( 'status' => 'ok' );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user