register_hooks(); } } public static function missing_core_notice(): void { echo '

'; 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' ), ), ) ); } }