TMDO_Playlist::register() 舊版偵測 TMPL_Main 類別, 在 partner 外掛中並不存在(或載入太晚),偵測實際完全靠 file_exists() 後備 撐著——程式碼讀起來像在驗證「partner 已載入」,實際只驗證了「目錄存在」。 改用 TMPL_VERSION / TMPL_PLUGIN_DIR(保留確實存在的 TMPL_Plugin),兩者在 partner 主檔的檔案解析當下即 define,早於 plugins_loaded,故本 AddOn bootstrap 的 :6 時點確實可用。 file_exists() 後備保留不動,行為不變;但偵測不再是死碼,即使將來移除後備也 不會重演 infocards-addon 那種「整個 AddOn 靜默失效」的事故。 同一版本另含先前未提交的 schema 工作:補齊 expected_columns / indexes, 並將 registry 索引 config key 由 expected_indexes 更正為 indexes (wp_parse_args() 會靜默丟棄未知 key,索引期望值先前等同從未送達)。 實測驗證(mu-plugin 於 plugins_loaded:6 量測真實請求): 新常數 AVAILABLE;wp wpdo doctor 89 OK / 0 FAIL;表註冊欄位與索引 100% 完整。
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
* Plugin Name: 2meet Data Optimizer — Playlist AddOn
|
* Plugin Name: 2meet Data Optimizer — Playlist AddOn
|
||||||
* Plugin URI: https://2meet.io/2meet-data-optimizer/playlist
|
* Plugin URI: https://2meet.io/2meet-data-optimizer/playlist
|
||||||
* Description: 2meet-playlist 5 張自訂表 (2mpl_singer_settings/songs/queue/rate_limits/sessions) 註冊
|
* Description: 2meet-playlist 5 張自訂表 (2mpl_singer_settings/songs/queue/rate_limits/sessions) 註冊
|
||||||
* Version: 0.1.0
|
* Version: 0.1.1
|
||||||
* Requires at least: 6.0
|
* Requires at least: 6.0
|
||||||
* Tested up to: 6.9.4
|
* Tested up to: 6.9.4
|
||||||
* Requires PHP: 8.1
|
* Requires PHP: 8.1
|
||||||
@@ -24,7 +24,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
define( 'TMDO_PLAYLIST_VERSION', '0.1.0' );
|
define( 'TMDO_PLAYLIST_VERSION', '0.1.1' );
|
||||||
define( 'TMDO_PLAYLIST_PATH', plugin_dir_path( __FILE__ ) );
|
define( 'TMDO_PLAYLIST_PATH', plugin_dir_path( __FILE__ ) );
|
||||||
define( 'TMDO_PLAYLIST_URL', plugin_dir_url( __FILE__ ) );
|
define( 'TMDO_PLAYLIST_URL', plugin_dir_url( __FILE__ ) );
|
||||||
define( 'TMDO_PLAYLIST_FILE', __FILE__ );
|
define( 'TMDO_PLAYLIST_FILE', __FILE__ );
|
||||||
|
|||||||
@@ -13,6 +13,33 @@ Versioning follows [Semantic Versioning](https://semver.org/).
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## [0.1.1] — 2026-08-08 — 5 張 `2mpl_*` 表補齊 schema 期望值
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- 為全部 5 張 `2mpl_*` 表補上 `expected_columns` 與 `indexes`:
|
||||||
|
`2mpl_singer_settings`、`2mpl_songs`、`2mpl_queue`、`2mpl_rate_limits`、
|
||||||
|
`2mpl_sessions`。欄位與索引逐項轉錄自 2meet-playlist activator 的
|
||||||
|
`CREATE TABLE`。先前只註冊表名,`wp wpdo doctor` 只知道表存在,無從判斷欄位或
|
||||||
|
索引是否漂移——`2mpl_queue` / `2mpl_rate_limits` 這類高頻讀寫表尤其吃索引,
|
||||||
|
漏建索引卻沒有警訊是實際風險。
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- `TMDO_Custom_Table_Registry::register()` 的索引期望值 config key 由
|
||||||
|
`expected_indexes` 更正為 `indexes`。該 API 以 `wp_parse_args()` 併入預設值,
|
||||||
|
未知 key 會被**靜默丟棄**——先前索引期望值等同從未送達 registry,
|
||||||
|
`wp wpdo doctor` 的 schema drift 只驗欄位、不驗索引。此問題橫跨全部 8 個 AddOn,
|
||||||
|
已一併更正。
|
||||||
|
- `TMDO_Playlist::register()` 的 partner 偵測符號對齊實際存在的常數。舊版偵測的
|
||||||
|
`TMPL_Main` 類別在 2meet-playlist 中**根本不存在**。補上 `TMPL_VERSION` /
|
||||||
|
`TMPL_PLUGIN_DIR`(兩者在主檔檔案解析當下即 define,早於 `plugins_loaded`),
|
||||||
|
並保留確實存在的 `TMPL_Plugin`。
|
||||||
|
實測(mu-plugin 於 `plugins_loaded:6` 量測):`TMPL_VERSION` = AVAILABLE。
|
||||||
|
`file_exists()` 後備保留不動,行為不變;但偵測不再含死符號。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## [0.1.0] — TBD
|
## [0.1.0] — TBD
|
||||||
|
|
||||||
### Added (initial release, scaffold)
|
### Added (initial release, scaffold)
|
||||||
|
|||||||
@@ -20,8 +20,19 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||||||
*/
|
*/
|
||||||
final class TMDO_Playlist {
|
final class TMDO_Playlist {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 偵測以常數優先:`TMPL_VERSION` / `TMPL_PLUGIN_DIR` 在 2meet-playlist 主檔的
|
||||||
|
* **檔案解析當下**(第 34/36 行)即 define,早於 `plugins_loaded`;本 AddOn
|
||||||
|
* bootstrap 掛在 `plugins_loaded:6`,故此時常數已可用。
|
||||||
|
*
|
||||||
|
* 舊版偵測的 `TMPL_Main` 類別在 2meet-playlist 中**並不存在**;`TMPL_Plugin` 雖存在,
|
||||||
|
* 但要到 `plugins_loaded:30`(`tmpl_run_plugin`)才 require,在 :6 當下必定 MISSING。
|
||||||
|
* 偵測實際完全靠 `file_exists()` 撐著。保留 file_exists 作最終後備,但常數檢查
|
||||||
|
* 現在真的有效——即使將來移除後備也不會像 infocards 那樣整個 AddOn 靜默失效。
|
||||||
|
*/
|
||||||
public static function register(): void {
|
public static function register(): void {
|
||||||
$detected = class_exists( 'TMPL_Main' )
|
$detected = defined( 'TMPL_VERSION' )
|
||||||
|
|| defined( 'TMPL_PLUGIN_DIR' )
|
||||||
|| class_exists( 'TMPL_Plugin' )
|
|| class_exists( 'TMPL_Plugin' )
|
||||||
|| file_exists( WP_PLUGIN_DIR . '/2meet-playlist/2meet-playlist.php' );
|
|| file_exists( WP_PLUGIN_DIR . '/2meet-playlist/2meet-playlist.php' );
|
||||||
if ( ! $detected ) {
|
if ( ! $detected ) {
|
||||||
@@ -32,19 +43,114 @@ final class TMDO_Playlist {
|
|||||||
|
|
||||||
public static function register_custom_tables( TMDO_Custom_Table_Registry $registry ): void {
|
public static function register_custom_tables( TMDO_Custom_Table_Registry $registry ): void {
|
||||||
$tables = array(
|
$tables = array(
|
||||||
'2mpl_singer_settings' => array( 'id', 'hp_vendor' ),
|
'2mpl_singer_settings' => array(
|
||||||
'2mpl_songs' => array( 'id', null ),
|
'primary_key' => 'id',
|
||||||
'2mpl_queue' => array( 'id', null ),
|
'post_type_link' => 'hp_vendor',
|
||||||
'2mpl_rate_limits' => array( 'id', null ),
|
'expected_columns' => array(
|
||||||
'2mpl_sessions' => array( 'id', null ),
|
'id' => 'BIGINT',
|
||||||
|
'vendor_id' => 'BIGINT',
|
||||||
|
'is_accepting_requests' => 'TINYINT',
|
||||||
|
'show_queue_public' => 'TINYINT',
|
||||||
|
'request_limit_per_ip' => 'SMALLINT',
|
||||||
|
'request_limit_minutes' => 'SMALLINT',
|
||||||
|
'banner_text' => 'VARCHAR',
|
||||||
|
'enable_sound_notification' => 'TINYINT',
|
||||||
|
'push_subscription' => 'TEXT',
|
||||||
|
'created_at' => 'DATETIME',
|
||||||
|
'updated_at' => 'DATETIME',
|
||||||
|
),
|
||||||
|
'indexes' => array(
|
||||||
|
'vendor_id' => array( 'vendor_id' ),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'2mpl_songs' => array(
|
||||||
|
'primary_key' => 'id',
|
||||||
|
'post_type_link' => null,
|
||||||
|
'expected_columns' => array(
|
||||||
|
'id' => 'BIGINT',
|
||||||
|
'vendor_id' => 'BIGINT',
|
||||||
|
'title' => 'VARCHAR',
|
||||||
|
'artist' => 'VARCHAR',
|
||||||
|
'notes' => 'TEXT',
|
||||||
|
'is_visible' => 'TINYINT',
|
||||||
|
'is_deleted' => 'TINYINT',
|
||||||
|
'request_count' => 'INT',
|
||||||
|
'created_at' => 'DATETIME',
|
||||||
|
'updated_at' => 'DATETIME',
|
||||||
|
),
|
||||||
|
'indexes' => array(
|
||||||
|
'vendor_visible' => array( 'vendor_id', 'is_visible', 'is_deleted' ),
|
||||||
|
'vendor_requests' => array( 'vendor_id', 'request_count' ),
|
||||||
|
'ft_search' => array( 'title', 'artist' ),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'2mpl_queue' => array(
|
||||||
|
'primary_key' => 'id',
|
||||||
|
'post_type_link' => null,
|
||||||
|
'expected_columns' => array(
|
||||||
|
'id' => 'BIGINT',
|
||||||
|
'session_id' => 'BIGINT',
|
||||||
|
'vendor_id' => 'BIGINT',
|
||||||
|
'song_id' => 'BIGINT',
|
||||||
|
'display_title' => 'VARCHAR',
|
||||||
|
'display_artist' => 'VARCHAR',
|
||||||
|
'requester_name' => 'VARCHAR',
|
||||||
|
'requester_ip_hash' => 'CHAR',
|
||||||
|
'status' => 'VARCHAR',
|
||||||
|
'sort_order' => 'INT',
|
||||||
|
'vote_count' => 'INT',
|
||||||
|
'requested_at' => 'DATETIME',
|
||||||
|
'completed_at' => 'DATETIME',
|
||||||
|
),
|
||||||
|
'indexes' => array(
|
||||||
|
'vendor_status_order' => array( 'vendor_id', 'status', 'sort_order' ),
|
||||||
|
'vendor_status_time' => array( 'vendor_id', 'status', 'requested_at' ),
|
||||||
|
'song_id' => array( 'song_id' ),
|
||||||
|
'session_id' => array( 'session_id' ),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'2mpl_rate_limits' => array(
|
||||||
|
'primary_key' => 'id',
|
||||||
|
'post_type_link' => null,
|
||||||
|
'expected_columns' => array(
|
||||||
|
'id' => 'BIGINT',
|
||||||
|
'vendor_id' => 'BIGINT',
|
||||||
|
'ip_hash' => 'CHAR',
|
||||||
|
'request_count' => 'SMALLINT',
|
||||||
|
'window_start' => 'DATETIME',
|
||||||
|
),
|
||||||
|
'indexes' => array(
|
||||||
|
'vendor_ip_window' => array( 'vendor_id', 'ip_hash', 'window_start' ),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'2mpl_sessions' => array(
|
||||||
|
'primary_key' => 'id',
|
||||||
|
'post_type_link' => null,
|
||||||
|
'expected_columns' => array(
|
||||||
|
'id' => 'BIGINT',
|
||||||
|
'vendor_id' => 'BIGINT',
|
||||||
|
'event_id' => 'BIGINT',
|
||||||
|
'title' => 'VARCHAR',
|
||||||
|
'status' => 'VARCHAR',
|
||||||
|
'started_at' => 'DATETIME',
|
||||||
|
'ended_at' => 'DATETIME',
|
||||||
|
),
|
||||||
|
'indexes' => array(
|
||||||
|
'vendor_status' => array( 'vendor_id', 'status' ),
|
||||||
|
'vendor_started' => array( 'vendor_id', 'started_at' ),
|
||||||
|
'event_id' => array( 'event_id' ),
|
||||||
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
foreach ( $tables as $table_name => $meta ) {
|
foreach ( $tables as $table_name => $meta ) {
|
||||||
$registry->register(
|
$registry->register(
|
||||||
'2meet-playlist',
|
'2meet-playlist',
|
||||||
array(
|
array(
|
||||||
'table_name' => $table_name,
|
'table_name' => $table_name,
|
||||||
'primary_key' => $meta[0],
|
'primary_key' => $meta['primary_key'],
|
||||||
'post_type_link' => $meta[1],
|
'post_type_link' => $meta['post_type_link'],
|
||||||
|
'expected_columns' => $meta['expected_columns'],
|
||||||
|
'indexes' => $meta['indexes'],
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user