fix(2meet-data-optimizer): stop auto-activating entity bridge on install

- install() no longer switches the Hook Bus on or puts user/term/comment
  into dual_write; the now-unused maybe_autoactivate_entity_bridge() is gone
- Hook Bus and Mode_Manager defaults are off/disabled; sites with stored
  modes (incl. aeav_only) keep them since only unset keys use defaults
- Guard run_dbdelta()'s upgrade.php require like install_v2_tables() so
  install() can run under the integration test stub

Verify: InstallerV2Test::test_install_does_not_enable_entity_bridge,
  ModeManagerDefaultsTest; unit 602 OK, integration 421 OK
PR: PR-007
This commit is contained in:
2026-09-25 21:48:23 +08:00
parent 151aadd661
commit fc0f018a94
7 changed files with 77 additions and 46 deletions
+1 -1
View File
@@ -54,7 +54,7 @@ final class TMDO_Hook_Bus_Bridge {
if ( null !== self::$cache ) {
return self::$cache;
}
$value = get_option( self::OPTION, '1' ); // Default ON as of v2.5.4.
$value = get_option( self::OPTION, '0' );
self::$cache = ( '1' === (string) $value || true === $value );
return self::$cache;
}
+4 -36
View File
@@ -224,47 +224,12 @@ class TMDO_Installer {
add_option( 'wpdo_features', array(), '', 'no' );
}
// v2.5.4: one-time migration — enable Hook Bus + activate user/term/comment bridge.
self::maybe_autoactivate_entity_bridge();
// v2.15.0: one-time crypto migration — re-encrypt v1 CBC ciphertext as
// v2 GCM. Idempotent best-effort: skipped if no v1 ciphertext present
// or if the migration flag is already set.
self::maybe_migrate_crypto_v1_to_v2();
}
/**
* One-time migration: enable Hook Bus and set user/term/comment to dual_write.
*
* Runs once per site (guarded by wpdo_entity_bridge_autoactivated_v2 flag).
* Safe: dual_write still writes native EAV — zero data-loss risk.
*
* @return void
*/
private static function maybe_autoactivate_entity_bridge(): void {
if ( get_option( 'wpdo_entity_bridge_autoactivated_v2' ) ) {
return;
}
// Enable Hook Bus.
update_option( 'wpdo_hook_bus_enabled', '1', false );
// Upgrade user/term/comment from disabled → dual_write.
$modes = get_option( 'wpdo_bridge_modes', array() );
if ( ! is_array( $modes ) ) {
$modes = array();
}
foreach ( array( 'user', 'term', 'comment' ) as $type ) {
if ( ! isset( $modes[ $type ] ) || 'disabled' === $modes[ $type ] ) {
$modes[ $type ] = 'dual_write';
}
}
// post entity is intentionally left alone — it uses the legacy Feature_Flags FSM.
update_option( 'wpdo_bridge_modes', $modes, false );
update_option( 'wpdo_entity_bridge_autoactivated_v2', '1', false );
}
/**
* One-time best-effort crypto migration v1 (CBC) → v2 (GCM) (v2.15.0).
*
@@ -1303,7 +1268,10 @@ class TMDO_Installer {
*/
private static function run_dbdelta(): void {
global $wpdb;
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
// Same guard as install_v2_tables(): integration tests provide a stub dbDelta().
if ( ! function_exists( 'dbDelta' ) ) {
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
}
$charset = $wpdb->get_charset_collate();
$p = $wpdb->prefix;
+5 -6
View File
@@ -65,16 +65,15 @@ final class TMDO_Mode_Manager {
private static ?array $cache = null;
/**
* 預設模式(v2.5.4 起):
* post → disabled(由 Legacy Feature_Flags FSM 管理,不由 Mode_Manager 控制)
* user / term / comment → dual_write(安全雙寫:寫入 flat table + 原生 EAV,讀取仍走 EAV)
* 預設模式:全部 disabled,由管理者明確選擇後才啟用 entity bridge。
* 已存在 wpdo_bridge_modes 的站台(包含 aeav_only)以儲存值為準,不受影響。
*/
private static function defaults(): array {
return array(
'post' => self::MODE_DISABLED,
'user' => self::MODE_DUAL_WRITE,
'term' => self::MODE_DUAL_WRITE,
'comment' => self::MODE_DUAL_WRITE,
'user' => self::MODE_DISABLED,
'term' => self::MODE_DISABLED,
'comment' => self::MODE_DISABLED,
);
}