refactor(2meet-data-optimizer): remove HPCT legacy from core

- Feature flags keep only the live AddOn modules (wc_orders, latepoint) as ADDON_MODULES / addon_modules(); drop map_hpct_status() and the 7 HivePress HPCT modules whose interceptors were removed in PR-014
- Remove HPCT detection/notice (Compatibility, core), the admin HPCT import tab and status row, CLI import-hpct, the 7 advisor rules for dead modules, and the removed interceptors from COEXIST_WHITELIST
- Verify: NoHpctLegacyTest guard; core unit 635 / integration 449, HP 145/49, WC 10/22 OK; all sites have every module idle and never imported HPCT
- PR: PR-020c
This commit is contained in:
2026-09-26 00:14:18 +08:00
parent 1eedaa9b3c
commit 8a1c9c0353
13 changed files with 110 additions and 378 deletions
@@ -284,7 +284,6 @@ class TMDO_Module_Detector {
$active = match ( $plugin ) {
'hivepress' => TMDO_Compatibility::is_hivepress_active(),
'woocommerce' => TMDO_Compatibility::is_woocommerce_active(),
'hpct' => TMDO_Compatibility::is_hpct_active(),
'latepoint' => TMDO_Compatibility::is_latepoint_active(),
default => false,
};
+2 -44
View File
@@ -29,52 +29,10 @@ if ( ! defined( 'ABSPATH' ) ) {
class TMDO_Module_Rules {
/**
* Default rules for the 15 known modules. Use `get()` to apply filter.
* Default rules for the 8 known modules. Use `get()` to apply filter.
*/
private const DEFAULT_RULES = array(
// ─── HPCT modules(HivePress + HPCT)────────────────────────────
'reviews' => array(
'compat_required' => array( 'hivepress' ),
'post_type_required' => 'hp_review',
'min_post_count' => 100,
'description' => '若使用 HivePress reviews 且累積評論 ≥ 100 條,啟用後可顯著降低 listing 查詢的 JOIN 成本。',
),
'messages' => array(
'compat_required' => array( 'hivepress' ),
'post_type_required' => 'hp_message_thread',
'min_post_count' => 50,
'description' => 'HivePress messages 累積對話數 ≥ 50 時,啟用 module 可加速 inbox / unread count 查詢。',
),
'favorites' => array(
'compat_required' => array( 'hivepress' ),
'post_type_required' => 'hp_favorite',
'min_post_count' => 200,
'description' => '使用者 favorite 累積 ≥ 200 條時,啟用 module 把 favorite meta 從 wp_postmeta 搬出。',
),
'memberships' => array(
'compat_required' => array( 'hivepress' ),
'post_type_required' => 'hp_membership',
'min_post_count' => 50,
'description' => 'HivePress memberships 啟用且 ≥ 50 條訂閱時,membership 過期檢查會更快。',
),
'statistics' => array(
'compat_required' => array( 'hivepress' ),
'post_type_required' => 'hp_listing',
'min_post_count' => 500,
'description' => 'Listing ≥ 500 條時,view_count / favorite_count 等高頻統計搬到 stats module 可大幅減少 wp_postmeta 寫入。',
),
'requests' => array(
'compat_required' => array( 'hivepress' ),
'post_type_required' => 'hp_request',
'min_post_count' => 50,
'description' => 'HivePress requests / quotes 累積 ≥ 50 條時建議啟用。',
),
'listing_meta' => array(
'compat_required' => array( 'hivepress' ),
'post_type_required' => 'hp_listing',
'min_post_count' => 100,
'description' => '所有 listing meta 集中管理;listing ≥ 100 時可省下大量 postmeta JOIN。',
),
// ─── AddOn modules ──────────────────────────────────────────────
'wc_orders' => array(
'compat_required' => array( 'woocommerce' ),
'post_type_required' => 'shop_order',
+3 -56
View File
@@ -37,57 +37,23 @@ class TMDO_Compatibility {
}
self::$detected = array(
'hpct_active' => self::is_hpct_active(),
'hpct_imported' => self::is_hpct_imported(),
'hivepress' => self::is_hivepress_active(),
'woocommerce' => self::is_woocommerce_active(),
'hivepress' => self::is_hivepress_active(),
'woocommerce' => self::is_woocommerce_active(),
);
return self::$detected;
}
/**
* Can WPDO register its HPCT-inherited module interceptors?
*
* True when:
* - hp-custom-tables is NOT active, OR
* - hp-custom-tables IS active but already imported into WPDO.
*/
public static function can_register_hpct_hooks(): bool {
$compat = self::check();
// HPCT not active → WPDO can freely register.
if ( ! $compat['hpct_active'] ) {
return true;
}
// HPCT is active but already imported → WPDO takes over.
if ( $compat['hpct_imported'] ) {
return true;
}
// HPCT is active and NOT imported → defer to HPCT.
return false;
}
/**
* Can WPDO register zone-specific interceptors (hot/warm/cold/archive)?
*
* Zone interceptors are always safe to register — they operate on
* WPDO's own tables and do not conflict with HPCT.
* WPDO's own tables.
*/
public static function can_register_zone_hooks(): bool {
return true;
}
/**
* Should WPDO show an admin notice about HPCT import?
*/
public static function should_show_hpct_notice(): bool {
$compat = self::check();
return $compat['hpct_active'] && ! $compat['hpct_imported'];
}
/**
* Is HivePress core active?
*/
@@ -113,23 +79,4 @@ class TMDO_Compatibility {
|| defined( 'LATEPOINT_VERSION' )
|| function_exists( 'latepoint_get_settings' );
}
// ── Detection Methods ────────────────────────────────────────────────
/**
* Is HP Custom Tables plugin active (loaded)?
*
* Checks for the HPCT_Loader class, which is always loaded
* when hp-custom-tables is active.
*/
public static function is_hpct_active(): bool {
return class_exists( 'HPCT_Loader' ) || defined( 'HPCT_VERSION' );
}
/**
* Has HPCT been imported into WPDO?
*/
private static function is_hpct_imported(): bool {
return (bool) get_option( 'wpdo_hpct_imported', false );
}
}
-41
View File
@@ -95,11 +95,6 @@ class TMDO_Core {
// Cache Layer hooks (Zone C prefetch + save_post warming).
TMDO_Cache_Layer::register_hooks();
// Register HPCT-inherited module interceptors if allowed.
if ( TMDO_Compatibility::can_register_hpct_hooks() ) {
$this->register_hpct_interceptors();
}
// Zone interceptors are always safe to register.
if ( TMDO_Compatibility::can_register_zone_hooks() ) {
$this->register_zone_hooks();
@@ -130,11 +125,6 @@ class TMDO_Core {
// Schedule cron events.
$this->schedule_cron();
// Admin notice for HPCT import.
if ( is_admin() && TMDO_Compatibility::should_show_hpct_notice() ) {
add_action( 'admin_notices', array( $this, 'render_hpct_notice' ) );
}
// v2.6.6: async entity backfill cron handler.
add_action( 'wpdo_entity_backfill_batch', array( $this, 'run_entity_backfill_batch' ), 10, 2 );
@@ -248,16 +238,6 @@ class TMDO_Core {
do_action( 'wpdo_register_entity_fields', TMDO_Entity_Registry::class );
}
/**
* Register HPCT-inherited module interceptors and query interceptors.
*/
private function register_hpct_interceptors(): void {
// 7 HPCT-era meta interceptors 已搬到 2meet-data-optimizer-hivepress-addon。
// 1 LatePoint interceptor 已搬到 2meet-data-optimizer-latepoint-addon。
// 5 query interceptors 已搬到 2meet-data-optimizer-hivepress-addon。
// 此方法保留為空殼以保持 ABI 相容;AddOn 各自於自身 bootstrap 內 register_hooks。
}
/**
* Register zone-specific hooks.
*/
@@ -555,27 +535,6 @@ class TMDO_Core {
TMDO_Zone_Archive::sweep();
}
/**
* Render admin notice when hp-custom-tables is detected but not imported.
*/
public function render_hpct_notice(): void {
$import_url = admin_url( 'tools.php?page=wp-data-optimizer&tab=hpct-import' );
?>
<div class="notice notice-warning is-dismissible">
<p>
<strong>WP Data Optimizer:</strong>
<?php
printf(
/* translators: %s: URL to import page */
esc_html__( 'HP Custom Tables 外掛已偵測到。請前往 %s 匯入其設定,然後停用 HP Custom Tables。', '2meet-data-optimizer' ),
'<a href="' . esc_url( $import_url ) . '">' . esc_html__( 'HPCT 匯入頁面', '2meet-data-optimizer' ) . '</a>'
);
?>
</p>
</div>
<?php
}
/**
* WP Cron handler: process one backfill batch for an entity/group pair.
*
+6 -33
View File
@@ -27,17 +27,9 @@ class TMDO_Feature_Flags {
private const OPTION_KEY = 'wpdo_features';
/**
* All known HPCT-inherited modules.
* These modules operate on existing hpct_* tables.
* Modules driven by AddOn interceptors (WooCommerce commissions, LatePoint).
*/
public const HPCT_MODULES = array(
'reviews',
'messages',
'favorites',
'memberships',
'statistics',
'requests',
'listing_meta',
public const ADDON_MODULES = array(
'wc_orders',
'latepoint',
);
@@ -300,7 +292,7 @@ class TMDO_Feature_Flags {
$saved = array();
}
$all_modules = array_merge( self::HPCT_MODULES, self::ZONE_MODULES );
$all_modules = array_merge( self::ADDON_MODULES, self::ZONE_MODULES );
$defaults = array_fill_keys( $all_modules, 'idle' );
self::$cache = array_merge( $defaults, $saved );
@@ -308,13 +300,13 @@ class TMDO_Feature_Flags {
}
/**
* Return only HPCT-inherited module states.
* Return only AddOn module states.
*
* @return array<string, string>
*/
public static function hpct_modules(): array {
public static function addon_modules(): array {
$all = self::all();
return array_intersect_key( $all, array_flip( self::HPCT_MODULES ) );
return array_intersect_key( $all, array_flip( self::ADDON_MODULES ) );
}
/**
@@ -326,23 +318,4 @@ class TMDO_Feature_Flags {
$all = self::all();
return array_intersect_key( $all, array_flip( self::ZONE_MODULES ) );
}
/**
* Map an HPCT feature flag status to a WPDO state.
*
* Used during HPCT import to translate HPCT's 4-state model
* to WPDO's 7-state model.
*
* @param string $hpct_status HPCT status (disabled/migrating/verified/enabled).
* @return string WPDO state.
*/
public static function map_hpct_status( string $hpct_status ): string {
return match ( $hpct_status ) {
'disabled' => 'idle',
'migrating' => 'backfill',
'verified' => 'cutover',
'enabled' => 'complete',
default => 'idle',
};
}
}
-7
View File
@@ -98,13 +98,6 @@ final class TMDO_Hook_Bus_Bridge {
* @var string[]
*/
private const COEXIST_WHITELIST = array(
'TMDO_Reviews_Interceptor',
'TMDO_Messages_Interceptor',
'TMDO_Favorites_Interceptor',
'TMDO_Memberships_Interceptor',
'TMDO_Statistics_Interceptor',
'TMDO_Requests_Interceptor',
'TMDO_Listing_Meta_Interceptor',
'TMDO_WC_Orders_Interceptor',
'TMDO_LatePoint_Interceptor',
'TMDO_Sync_Bridge',
@@ -424,7 +424,7 @@ class TMDO_Snapshot_Manager {
return array();
}
$out = array();
$modules = array_merge( TMDO_Feature_Flags::HPCT_MODULES, TMDO_Feature_Flags::ZONE_MODULES );
$modules = array_merge( TMDO_Feature_Flags::ADDON_MODULES, TMDO_Feature_Flags::ZONE_MODULES );
foreach ( $modules as $m ) {
$out[ $m ] = TMDO_Feature_Flags::get( $m );
}