chore(2meet-data-optimizer-latepoint-addon): add hpct_latepoint_idx install
Tests / PHP Lint (pull_request) Successful in 7s

- Create hpct_latepoint_idx via dbDelta keyed on a version option, so
  git-pull deploys also get the table (interceptor wrote to it blindly)
- Register the table with TMDO_Custom_Table_Registry; fix indexes key
- Bump version to 0.1.1

Verify: php -l includes/*.php; git status --short clean
PR: PR-001
This commit is contained in:
2026-09-25 20:23:28 +08:00
parent f6b8323e17
commit 8393b213ae
3 changed files with 119 additions and 2 deletions
@@ -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 '</p></div>';
}
/**
* 建立 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' ),
),
)
);
}
}