7f788cb4dc
Baseline before backporting wp-data-optimizer v3.0.1-v3.4.6. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TbG1keQQ7XBa7qMQY16KCY
101 lines
2.8 KiB
PHP
101 lines
2.8 KiB
PHP
<?php
|
|
/**
|
|
* Register 12 hub-core custom tables to TMDO Custom Table Registry.
|
|
*
|
|
* 從 2meet-hub-core/includes/class-tmhc-plugin.php:222-245 抽出。
|
|
* 表 schema 定義仍由 hub-core 擁有(透過 tmhc_get_table_suffixes() 等 helper 取得)。
|
|
*
|
|
* @package TMDO_HUB
|
|
* @since 0.1.0
|
|
*/
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
exit;
|
|
}
|
|
|
|
final class TMDO_Hub_Custom_Tables {
|
|
|
|
private static bool $registered = false;
|
|
|
|
/**
|
|
* Hub 12 表清單(fallback 當 tmhc_get_table_suffixes 不可用時)。
|
|
*/
|
|
private const FALLBACK_SUFFIXES = array(
|
|
'2mhc_oauth_clients',
|
|
'2mhc_oauth_auth_codes',
|
|
'2mhc_oauth_access_tokens',
|
|
'2mhc_oauth_refresh_tokens',
|
|
'2mhc_oauth_slo_state',
|
|
'2mhc_user_identities',
|
|
'2mhc_vendor_sites',
|
|
'2mhc_aggregated_services',
|
|
'2mhc_brand_pages',
|
|
'2mhc_audit_log',
|
|
'2mhc_sync_inbox',
|
|
'2mhc_rate_limits',
|
|
);
|
|
|
|
/**
|
|
* Register tables to TMDO Custom Table Registry.
|
|
*
|
|
* @param object $registry TMDO_Custom_Table_Registry / WPDO_Custom_Table_Registry instance.
|
|
*/
|
|
public static function register( $registry ): void {
|
|
if ( self::$registered ) {
|
|
return;
|
|
}
|
|
if ( ! is_object( $registry ) || ! method_exists( $registry, 'register' ) ) {
|
|
return;
|
|
}
|
|
|
|
$suffixes = self::get_suffixes();
|
|
$expected_columns = self::get_expected_columns_safe();
|
|
$expected_indexes = self::get_expected_indexes_safe();
|
|
|
|
foreach ( $suffixes as $suffix ) {
|
|
$registry->register(
|
|
'2meet-data-optimizer-hub-addon',
|
|
array(
|
|
'table_name' => $suffix,
|
|
'primary_key' => 'id',
|
|
'expected_columns' => $expected_columns[ $suffix ] ?? array(),
|
|
'indexes' => $expected_indexes[ $suffix ] ?? array(),
|
|
'description' => '2meet Hub Core 自訂表:' . $suffix,
|
|
)
|
|
);
|
|
}
|
|
|
|
self::$registered = true;
|
|
}
|
|
|
|
private static function get_suffixes(): array {
|
|
if ( function_exists( 'tmhc_get_table_suffixes' ) ) {
|
|
$out = tmhc_get_table_suffixes();
|
|
if ( is_array( $out ) && ! empty( $out ) ) {
|
|
return $out;
|
|
}
|
|
}
|
|
return self::FALLBACK_SUFFIXES;
|
|
}
|
|
|
|
private static function get_expected_columns_safe(): array {
|
|
if ( class_exists( 'TMHC_Plugin' ) && method_exists( 'TMHC_Plugin', 'get_expected_columns' ) ) {
|
|
$reflection = new ReflectionMethod( 'TMHC_Plugin', 'get_expected_columns' );
|
|
if ( $reflection->isStatic() && $reflection->isPublic() ) {
|
|
return TMHC_Plugin::get_expected_columns();
|
|
}
|
|
}
|
|
return array();
|
|
}
|
|
|
|
private static function get_expected_indexes_safe(): array {
|
|
if ( class_exists( 'TMHC_Plugin' ) && method_exists( 'TMHC_Plugin', 'get_expected_indexes' ) ) {
|
|
$reflection = new ReflectionMethod( 'TMHC_Plugin', 'get_expected_indexes' );
|
|
if ( $reflection->isStatic() && $reflection->isPublic() ) {
|
|
return TMHC_Plugin::get_expected_indexes();
|
|
}
|
|
}
|
|
return array();
|
|
}
|
|
}
|