Files
2meet-data-optimizer/includes/migration/phases/class-tmdo-phase-install-schema.php
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

58 lines
1.4 KiB
PHP

<?php
/**
* Migration phase: install flat schema tables for the entity type.
*
* @package TMDO
* @since 3.0.1
*/
declare(strict_types=1);
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Fires wpdo_register_entity_fields, runs schema migrations, verifies all tables exist.
*/
class TMDO_Phase_Install_Schema extends TMDO_Migration_Phase_Base {
/**
* Returns the phase slug.
*
* @return string
*/
public function name(): string {
return 'install_schema';
}
/**
* Executes the phase.
*
* @param array $job Job array (by reference).
* @return array{status: string}
* @throws \RuntimeException If any required tables are missing after migration.
*/
public function execute( array &$job ): array {
do_action( 'wpdo_register_entity_fields', TMDO_Entity_Registry::class );
TMDO_Schema_Manager::process_pending_migrations();
$missing = array();
foreach ( TMDO_Entity_Registry::get_groups_for_type( $this->entity_type ) as $group ) {
$table = TMDO_Schema_Manager::get_table_name( $this->entity_type, $group );
if ( ! TMDO_Schema_Manager::table_exists( $table ) ) {
$missing[] = $group;
}
}
if ( $missing ) {
throw new \RuntimeException( 'Schema migration failed; missing tables: ' . implode( ',', $missing ) );
}
$count = count( TMDO_Entity_Registry::get_groups_for_type( $this->entity_type ) );
$this->log( $job, "Schema migration ok ({$count} flat tables verified)" );
return array( 'status' => 'ok' );
}
}