Files
2meet-data-optimizer/includes/class-tmdo-back-compat.php
T
wpdev f187ac5401 refactor(zones): 回填 Zone_Router + Routing_Predicate(PR-C)
A v3.0.1/v3.4.0 的架構深化,B 完全缺席:

新增
- includes/zones/class-tmdo-zone-router.php:module_name / read / write /
  delete_field / delete_post 五個 static 分派點
- includes/class-tmdo-routing-predicate.php:entity_bridge_owns(含
  request-level cache,B 原本沒有)+ should_{write,read,query}_from_zone
  + flush_cache

改寫
- Sync_Bridge 改用兩者,移除 5 個 private wrapper(get_zone_module /
  read_from_zone / write_to_zone / delete_from_zone / is_owned_by_entity_bridge)
  與 44 行 inline cleanup_post → Zone_Router::delete_post 一行(400→269 行)
- Query_Router 抽出 extract_hot_clauses() public static,pre_get_posts 變薄殼
- 收斂 5 處重複的 'hot_'/'cold_' . sanitize_key()(rest-api ×3、
  hot/cold-migration ×2)
- back-compat 補 WPDO_Zone_Router / WPDO_Routing_Predicate alias

測試
- 移植 ZoneRouterTest(250 行)+ RoutingPredicateTest(85 行)
- SyncBridgeEntityGuardTest 的 setUp/tearDownAfterClass 補 flush_cache(),
  否則 entity_bridge_cache 會跨測試污染(A v3.4.6 踩過同一個坑)

unit 409 / integration 398 GREEN

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TbG1keQQ7XBa7qMQY16KCY
2026-07-31 05:47:08 +08:00

185 lines
8.9 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* Back-compat aliases — 對外保留 WPDO_* 類別 / 常數,讓 hub-core / spoke-sso /
* 其他 sister plugins 在升級到 2meet-data-optimizer 後不需修改任何 class_exists()
* / new WPDO_X() / WPDO_API::xxx() 呼叫。
*
* Phase 1 起穩定。v0.2.0 後可加 _doing_it_wrong() deprecation notice。
*
* @package TMDO
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
// ── 公開合約類別(Phase 1 凍結,不可移除)─────────────────────────────
$tmdo_class_aliases = array(
'TMDO_API' => 'WPDO_API',
'TMDO_Schema_Registry' => 'WPDO_Schema_Registry',
'TMDO_Entity_Registry' => 'WPDO_Entity_Registry',
'TMDO_Custom_Table_Registry' => 'WPDO_Custom_Table_Registry',
'TMDO_Feature_Flags' => 'WPDO_Feature_Flags',
'TMDO_DB' => 'WPDO_DB',
'TMDO_Crypto' => 'WPDO_Crypto',
'TMDO_Logger' => 'WPDO_Logger',
'TMDO_Capability' => 'WPDO_Capability',
'TMDO_Safe_Unserialize' => 'WPDO_Safe_Unserialize',
// Engine / Migration / Adapterssecond-tier,部分 sister plugin 已直接呼叫)
'TMDO_Hook_Bus' => 'WPDO_Hook_Bus',
'TMDO_Mode_Manager' => 'WPDO_Mode_Manager',
'TMDO_Migration_Engine' => 'WPDO_Migration_Engine',
'TMDO_Migration_Orchestrator' => 'WPDO_Migration_Orchestrator',
'TMDO_Entity_Migration_Engine' => 'WPDO_Entity_Migration_Engine',
'TMDO_Entity_Health' => 'WPDO_Entity_Health',
'TMDO_Schema_Manager' => 'WPDO_Schema_Manager',
'TMDO_Sync_Bridge' => 'WPDO_Sync_Bridge',
'TMDO_Query_Router' => 'WPDO_Query_Router',
'TMDO_Post_Query_Router' => 'WPDO_Post_Query_Router',
'TMDO_Hook_Bus_Bridge' => 'WPDO_Hook_Bus_Bridge',
'TMDO_Conflict_Monitor' => 'WPDO_Conflict_Monitor',
'TMDO_Compatibility' => 'WPDO_Compatibility',
'TMDO_Installer' => 'WPDO_Installer',
'TMDO_Cache_Layer' => 'WPDO_Cache_Layer',
'TMDO_Zone_Classifier' => 'WPDO_Zone_Classifier',
'TMDO_Core' => 'WPDO_Core',
'TMDO_REST_API' => 'WPDO_REST_API',
'TMDO_Snapshot_Manager' => 'WPDO_Snapshot_Manager',
'TMDO_Snapshot_Writer' => 'WPDO_Snapshot_Writer',
'TMDO_Snapshot_Reader' => 'WPDO_Snapshot_Reader',
'TMDO_Snapshot_Pruner' => 'WPDO_Snapshot_Pruner',
'TMDO_FSM_Guard' => 'WPDO_FSM_Guard',
'TMDO_Site_Health' => 'WPDO_Site_Health',
'TMDO_Health_Cron' => 'WPDO_Health_Cron',
'TMDO_Email_Notifier' => 'WPDO_Email_Notifier',
'TMDO_Slack_Notifier' => 'WPDO_Slack_Notifier',
'TMDO_Discord_Notifier' => 'WPDO_Discord_Notifier',
'TMDO_Telegram_Notifier' => 'WPDO_Telegram_Notifier',
'TMDO_Monthly_Summary' => 'WPDO_Monthly_Summary',
'TMDO_Site_Metrics_Collector' => 'WPDO_Site_Metrics_Collector',
'TMDO_FSM_Advisor' => 'WPDO_FSM_Advisor',
'TMDO_Module_Detector' => 'WPDO_Module_Detector',
'TMDO_FSM_Automator' => 'WPDO_FSM_Automator',
'TMDO_Module_Rules' => 'WPDO_Module_Rules',
'TMDO_CSV_Writer' => 'WPDO_CSV_Writer',
'TMDO_Export' => 'WPDO_Export',
'TMDO_CLI' => 'WPDO_CLI',
'TMDO_CLI_V2' => 'WPDO_CLI_V2',
'TMDO_CLI_Member' => 'WPDO_CLI_Member',
'TMDO_CLI_Post' => 'WPDO_CLI_Post',
'TMDO_CLI_Term_Comment' => 'WPDO_CLI_Term_Comment',
'TMDO_Member_Fields' => 'WPDO_Member_Fields',
'TMDO_Post_Fields' => 'WPDO_Post_Fields',
'TMDO_Points_Manager' => 'WPDO_Points_Manager',
'TMDO_Demo_Entity_Counter' => 'WPDO_Demo_Entity_Counter',
'TMDO_Postmeta_Cleaner' => 'WPDO_Postmeta_Cleaner',
'TMDO_Termmeta_Cleaner' => 'WPDO_Termmeta_Cleaner',
'TMDO_Commentmeta_Cleaner' => 'WPDO_Commentmeta_Cleaner',
'TMDO_Post_Stress_Tester' => 'WPDO_Post_Stress_Tester',
'TMDO_User_Stress_Tester' => 'WPDO_User_Stress_Tester',
'TMDO_Term_Stress_Tester' => 'WPDO_Term_Stress_Tester',
'TMDO_Comment_Stress_Tester' => 'WPDO_Comment_Stress_Tester',
'TMDO_Post_Shadow_Verifier' => 'WPDO_Post_Shadow_Verifier',
'TMDO_Term_Comment_Shadow_Verifier' => 'WPDO_Term_Comment_Shadow_Verifier',
'TMDO_Term_Comment_Backfill' => 'WPDO_Term_Comment_Backfill',
'TMDO_Term_Comment_Misc_Bucket' => 'WPDO_Term_Comment_Misc_Bucket',
'TMDO_Term_Comment_Garbage_Filter' => 'WPDO_Term_Comment_Garbage_Filter',
'TMDO_Setup_Wizard' => 'WPDO_Setup_Wizard',
'TMDO_Dashboard_Widget' => 'WPDO_Dashboard_Widget',
'TMDO_Help_Tabs' => 'WPDO_Help_Tabs',
'TMDO_Admin' => 'WPDO_Admin',
'TMDO_V2_Upgrader' => 'WPDO_V2_Upgrader',
'TMDO_SQLite_Compat' => 'WPDO_SQLite_Compat',
'TMDO_Type_Caster' => 'WPDO_Type_Caster',
'TMDO_Audit_Logger' => 'WPDO_Audit_Logger',
'TMDO_Shadow_Diff_Logger' => 'WPDO_Shadow_Diff_Logger',
'TMDO_Conflict_Detector' => 'WPDO_Conflict_Detector',
'TMDO_Cache_Orchestrator' => 'WPDO_Cache_Orchestrator',
'TMDO_Query_Compiler' => 'WPDO_Query_Compiler',
'TMDO_Auto_Promoter' => 'WPDO_Auto_Promoter',
'TMDO_Adapter_Post' => 'WPDO_Adapter_Post',
'TMDO_Adapter_User' => 'WPDO_Adapter_User',
'TMDO_Adapter_Term' => 'WPDO_Adapter_Term',
'TMDO_Adapter_Comment' => 'WPDO_Adapter_Comment',
'TMDO_Options_Manager' => 'WPDO_Options_Manager',
'TMDO_Hot_Migration' => 'WPDO_Hot_Migration',
'TMDO_Warm_Migration' => 'WPDO_Warm_Migration',
'TMDO_Cold_Migration' => 'WPDO_Cold_Migration',
'TMDO_Archive_Migration' => 'WPDO_Archive_Migration',
'TMDO_Migration_Base' => 'WPDO_Migration_Base',
'TMDO_Post_Migration' => 'WPDO_Post_Migration',
'TMDO_Zone_Hot' => 'WPDO_Zone_Hot',
'TMDO_Zone_Warm' => 'WPDO_Zone_Warm',
'TMDO_Zone_Cold' => 'WPDO_Zone_Cold',
'TMDO_Zone_Router' => 'WPDO_Zone_Router',
'TMDO_Routing_Predicate' => 'WPDO_Routing_Predicate',
'TMDO_Zone_Archive' => 'WPDO_Zone_Archive',
'TMDO_Interceptor_Base' => 'WPDO_Interceptor_Base',
'TMDO_Query_Interceptor_Base' => 'WPDO_Query_Interceptor_Base',
'TMDO_Notifier' => 'WPDO_Notifier',
);
foreach ( $tmdo_class_aliases as $tmdo_class => $wpdo_alias ) {
if ( class_exists( $tmdo_class, false ) && ! class_exists( $wpdo_alias, false ) ) {
class_alias( $tmdo_class, $wpdo_alias );
}
}
unset( $tmdo_class_aliases, $tmdo_class, $wpdo_alias );
// trait + interface back-compatPHP class_alias 不支援 trait/interface,用 wrapper 解決)。
require_once __DIR__ . '/back-compat/trait-wpdo-anti-eav-aware-alias.php';
require_once __DIR__ . '/back-compat/interface-wpdo-entity-adapter-alias.php';
// ── 常數別名(部分 sister plugin 直接讀取常數)─────────────────────────
if ( ! defined( 'WPDO_VERSION' ) ) {
define( 'WPDO_VERSION', TMDO_VERSION );
}
if ( ! defined( 'WPDO_DB_VERSION' ) ) {
define( 'WPDO_DB_VERSION', TMDO_DB_VERSION );
}
if ( ! defined( 'WPDO_PLUGIN_DIR' ) ) {
define( 'WPDO_PLUGIN_DIR', TMDO_PATH );
}
if ( ! defined( 'WPDO_PLUGIN_URL' ) ) {
define( 'WPDO_PLUGIN_URL', TMDO_URL );
}
if ( ! defined( 'WPDO_PLUGIN_FILE' ) ) {
define( 'WPDO_PLUGIN_FILE', TMDO_FILE );
}
if ( ! defined( 'WPDO_TABLE_PREFIX' ) ) {
define( 'WPDO_TABLE_PREFIX', TMDO_TABLE_PREFIX );
}
if ( ! defined( 'WPDO_CACHE_GROUP' ) ) {
define( 'WPDO_CACHE_GROUP', TMDO_CACHE_GROUP );
}
if ( ! defined( 'WPDO_IS_SQLITE' ) ) {
define( 'WPDO_IS_SQLITE', TMDO_IS_SQLITE );
}
if ( ! defined( 'WPDO_IS_MYSQL' ) ) {
define( 'WPDO_IS_MYSQL', TMDO_IS_MYSQL );
}
// ── Hook dual-fire bridge ─────────────────────────────────────────────────
// Phase 1 過渡期:tmdo_* 與 wpdo_* hook 雙向轉發,讓既有 listener 仍能接收事件。
foreach ( array(
'wpdo_register_fields',
'wpdo_register_entity_fields',
'wpdo_register_custom_tables',
'wpdo_after_write',
'wpdo_after_delete',
'wpdo_schema_updated',
'wpdo_bridge_mode_changed',
'wpdo_bridge_emergency_disabled',
'wpdo_auto_promoted',
) as $tmdo_back_compat_hook ) {
$tmdo_new_hook = preg_replace( '/^wpdo_/', 'tmdo_', $tmdo_back_compat_hook );
add_action(
$tmdo_new_hook,
static function ( ...$args ) use ( $tmdo_back_compat_hook ) {
do_action_ref_array( $tmdo_back_compat_hook, $args );
},
1
);
}
unset( $tmdo_back_compat_hook, $tmdo_new_hook );