diff --git a/2meet-data-optimizer-latepoint-addon.php b/2meet-data-optimizer-latepoint-addon.php index 4f60845..bd77c18 100644 --- a/2meet-data-optimizer-latepoint-addon.php +++ b/2meet-data-optimizer-latepoint-addon.php @@ -3,7 +3,7 @@ * Plugin Name: 2meet Data Optimizer — Latepoint AddOn * Plugin URI: https://2meet.io/2meet-data-optimizer/latepoint * Description: LatePoint 預約系統 booking 索引同步(4 hook → wp_hpct_latepoint_idx) - * Version: 0.1.0 + * Version: 0.1.1 * Requires at least: 6.0 * Tested up to: 6.9.4 * Requires PHP: 8.1 @@ -24,7 +24,7 @@ if ( ! defined( 'ABSPATH' ) ) { exit; } -define( 'TMDO_LATEPOINT_VERSION', '0.1.0' ); +define( 'TMDO_LATEPOINT_VERSION', '0.1.1' ); define( 'TMDO_LATEPOINT_PATH', plugin_dir_path( __FILE__ ) ); define( 'TMDO_LATEPOINT_URL', plugin_dir_url( __FILE__ ) ); define( 'TMDO_LATEPOINT_FILE', __FILE__ ); diff --git a/CHANGELOG.md b/CHANGELOG.md index c180b69..cb564ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,35 @@ Versioning follows [Semantic Versioning](https://semver.org/). --- +## [0.1.1] — 2026-08-08 — 補上從未存在的 `wp_hpct_latepoint_idx` 建表流程 + +### Fixed + +- **`wp_hpct_latepoint_idx` 從未被建立,索引同步全程靜默失敗(嚴重)。** 這張表 + 在整個 `wp-data-optimizer` / `2meet-data-optimizer` 系譜中**從未有過** + `CREATE TABLE` 定義,但 `TMDO_LatePoint_Interceptor::sync_booking()` 一直對它 + 做 INSERT/UPDATE,且整段包在 try/catch 內——在乾淨站台上每一次 booking 同步都 + 會失敗,索引表永遠是空的,而且沒有任何錯誤訊號可循。新增 + `TMDO_Latepoint_Bootstrap::maybe_install_table()`,以 `dbDelta()` 建立 12 欄表 + (`booking_id` UNIQUE KEY + `agent_id` / `service_id` / `customer_id` 三個 KEY), + 並以 `tmdo_latepoint_db_version` option 追蹤版本。刻意**不**只掛 + `register_activation_hook()`:本外掛多以 git pull 部署、不會經過停用/啟用循環, + 唯有版本 option 才能確保既有安裝也補建到表。 +- `TMDO_Custom_Table_Registry::register()` 的索引期望值 config key 由 + `expected_indexes` 更正為 `indexes`。該 API 以 `wp_parse_args()` 併入預設值, + 未知 key 會被**靜默丟棄**——先前索引期望值等同從未送達 registry, + `wp wpdo doctor` 的 schema drift 只驗欄位、不驗索引。此問題橫跨全部 8 個 AddOn, + 已一併更正。 + +### Added + +- `TMDO_Latepoint_Bootstrap::register_custom_tables()`:把 `hpct_latepoint_idx` + 註冊進 `TMDO_Custom_Table_Registry`(12 欄 `expected_columns` + 4 個 `indexes`), + 讓 `wp wpdo doctor` / `benchmark` / `cleanup` 能治理此表。此前這張表對 TMDO + 治理工具完全不可見。 + +--- + ## [0.1.0] — TBD ### Added (initial release, scaffold) diff --git a/includes/class-tmdo-latepoint-bootstrap.php b/includes/class-tmdo-latepoint-bootstrap.php index c276a81..877fde5 100644 --- a/includes/class-tmdo-latepoint-bootstrap.php +++ b/includes/class-tmdo-latepoint-bootstrap.php @@ -12,6 +12,9 @@ if ( ! defined( 'ABSPATH' ) ) { final class TMDO_Latepoint_Bootstrap { + const DB_VERSION_OPTION = 'tmdo_latepoint_db_version'; + const DB_VERSION = '0.1.0'; + public static function init(): void { if ( ! class_exists( 'TMDO_API' ) && ! class_exists( 'WPDO_API' ) ) { add_action( 'admin_notices', array( __CLASS__, 'missing_core_notice' ) ); @@ -24,6 +27,9 @@ final class TMDO_Latepoint_Bootstrap { dirname( plugin_basename( TMDO_LATEPOINT_FILE ) ) . '/languages' ); + self::maybe_install_table(); + add_action( 'wpdo_register_custom_tables', array( __CLASS__, 'register_custom_tables' ) ); + require_once TMDO_LATEPOINT_PATH . 'includes/class-tmdo-latepoint-interceptor.php'; if ( class_exists( 'TMDO_LatePoint_Interceptor' ) ) { @@ -36,4 +42,86 @@ final class TMDO_Latepoint_Bootstrap { echo esc_html__( '2meet Data Optimizer LatePoint AddOn 需要 2meet-data-optimizer 核心外掛,請先安裝並啟用。', 'tmdo-latepoint' ); echo '

'; } + + /** + * 建立 wp_hpct_latepoint_idx 表(若尚未存在或版本落後)。 + * + * 這張表在整個 wp-data-optimizer / 2meet-data-optimizer 系譜中從未有過 + * CREATE TABLE 定義——TMDO_LatePoint_Interceptor::sync_booking() 一直對著 + * 一張可能不存在的表做 INSERT/UPDATE(外包在 try/catch 內靜默失敗)。 + * 用 dbDelta version option(而非只掛 register_activation_hook)確保即使 + * 外掛是透過 git pull 部署、未經停用/啟用循環也能補建表。 + */ + public static function maybe_install_table(): void { + if ( get_option( self::DB_VERSION_OPTION ) === self::DB_VERSION ) { + return; + } + global $wpdb; + require_once ABSPATH . 'wp-admin/includes/upgrade.php'; + + $table = class_exists( 'TMDO_DB' ) ? TMDO_DB::table( 'hpct_latepoint_idx' ) : $wpdb->prefix . 'hpct_latepoint_idx'; + $charset = $wpdb->get_charset_collate(); + $sql = "CREATE TABLE {$table} ( + id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, + booking_id BIGINT NOT NULL, + agent_id BIGINT NOT NULL DEFAULT 0, + service_id BIGINT NOT NULL DEFAULT 0, + customer_id BIGINT NOT NULL DEFAULT 0, + status VARCHAR(50) NOT NULL DEFAULT '', + start_date VARCHAR(20) DEFAULT NULL, + end_date VARCHAR(20) DEFAULT NULL, + start_time INT NOT NULL DEFAULT 0, + end_time INT NOT NULL DEFAULT 0, + price VARCHAR(20) NOT NULL DEFAULT '0', + created_at DATETIME NOT NULL, + PRIMARY KEY (id), + UNIQUE KEY booking_id (booking_id), + KEY agent_id (agent_id), + KEY service_id (service_id), + KEY customer_id (customer_id) + ) {$charset};"; + dbDelta( $sql ); + update_option( self::DB_VERSION_OPTION, self::DB_VERSION, false ); + } + + /** + * 註冊 wp_hpct_latepoint_idx 到 TMDO Custom Table Registry, + * 讓 `wp wpdo doctor`/`benchmark`/`cleanup` 能治理此表。 + * + * @param mixed $registry TMDO_Custom_Table_Registry instance(loose typing 容錯舊版別名)。 + */ + public static function register_custom_tables( $registry ): void { + if ( ! is_object( $registry ) || ! method_exists( $registry, 'register' ) ) { + return; + } + + $registry->register( + '2meet-data-optimizer-latepoint-addon', + array( + 'table_name' => 'hpct_latepoint_idx', + 'primary_key' => 'id', + 'post_type_link' => null, + 'expected_columns' => array( + 'id' => 'BIGINT', + 'booking_id' => 'BIGINT', + 'agent_id' => 'BIGINT', + 'service_id' => 'BIGINT', + 'customer_id' => 'BIGINT', + 'status' => 'VARCHAR', + 'start_date' => 'VARCHAR', + 'end_date' => 'VARCHAR', + 'start_time' => 'INT', + 'end_time' => 'INT', + 'price' => 'VARCHAR', + 'created_at' => 'DATETIME', + ), + 'indexes' => array( + 'booking_id' => array( 'booking_id' ), + 'agent_id' => array( 'agent_id' ), + 'service_id' => array( 'service_id' ), + 'customer_id' => array( 'customer_id' ), + ), + ) + ); + } }