d36bb954d1
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
84 lines
2.9 KiB
PHP
84 lines
2.9 KiB
PHP
<?php
|
|
/**
|
|
* Entity Adapter 合約介面
|
|
*
|
|
* 所有實體適配器(Post/User/Term/Comment)必須實作此介面
|
|
* 將不同實體的行為標準化,供 Hook Bus 統一呼叫
|
|
*
|
|
* @package WP_Data_Optimizer
|
|
*/
|
|
|
|
// phpcs:disable Squiz.Commenting,Generic.Commenting,WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber,Generic.CodeAnalysis.UnusedFunctionParameter,Generic.CodeAnalysis.EmptyStatement,Squiz.PHP.DisallowMultipleAssignments,Squiz.PHP.DisallowSizeFunctionsInLoops,WordPress.WP.I18n.MissingTranslatorsComment,WordPress.PHP.NoSilencedErrors,WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents,Squiz.PHP.CommentedOutCode,Universal.NamingConventions.NoReservedKeywordParameterNames,WordPress.PHP.YodaConditions,Squiz.Commenting.InlineComment.InvalidEndChar -- PR-1 ported from UAE; cleanup PR scheduled.
|
|
|
|
|
|
defined( 'ABSPATH' ) || exit;
|
|
|
|
// Back-compat: define WPDO_ marker first so TMDO_ can extend it.
|
|
// PHP class_alias() doesn't work on interfaces; extending is the only option.
|
|
// Any class implementing TMDO_Entity_Adapter_Interface automatically satisfies
|
|
// `instanceof WPDO_Entity_Adapter_Interface` via interface inheritance.
|
|
if ( ! interface_exists( 'WPDO_Entity_Adapter_Interface', false ) ) {
|
|
interface WPDO_Entity_Adapter_Interface {}
|
|
}
|
|
|
|
interface TMDO_Entity_Adapter_Interface extends WPDO_Entity_Adapter_Interface {
|
|
|
|
/**
|
|
* 實體類型識別子
|
|
* 必須回傳 WordPress metadata type 之一:post|user|term|comment
|
|
*/
|
|
public function get_entity_type(): string;
|
|
|
|
/**
|
|
* 原生 meta 表完整名稱(含 wp_ 前綴)
|
|
* 例:wp_postmeta / wp_usermeta
|
|
*/
|
|
public function get_native_meta_table(): string;
|
|
|
|
/**
|
|
* 原生 meta 表中指向實體的欄位名稱
|
|
* 例:post_id / user_id / term_id / comment_id
|
|
*/
|
|
public function get_entity_id_column(): string;
|
|
|
|
/**
|
|
* 對應的主實體表(用於 JOIN)
|
|
* 例:wp_posts / wp_users / wp_terms / wp_comments
|
|
*/
|
|
public function get_primary_table(): string;
|
|
|
|
/**
|
|
* 主實體表的主鍵欄位
|
|
* 例:ID (post/user) / term_id / comment_ID
|
|
*/
|
|
public function get_primary_id_column(): string;
|
|
|
|
/**
|
|
* 快取群組名稱(供 wp_cache_* 使用)
|
|
*/
|
|
public function get_cache_group(): string;
|
|
|
|
/**
|
|
* 實體刪除時會觸發的 WordPress hook
|
|
* 用於自動清理 UAE 資料表中對應列
|
|
*/
|
|
public function get_delete_hook(): string;
|
|
|
|
/**
|
|
* 擴充原生查詢物件以支援 UAE meta_query
|
|
*
|
|
* @param mixed $query_object WP_Query / WP_User_Query / WP_Comment_Query 等
|
|
*/
|
|
public function extend_native_query( $query_object ): void;
|
|
|
|
/**
|
|
* 取得所有已知的 ID(用於遷移時的迭代)
|
|
* 採用 cursor-based 分頁
|
|
*
|
|
* @param int $after_id 取大於此 ID 的筆
|
|
* @param int $limit 取多少筆
|
|
* @return array<int>
|
|
*/
|
|
public function get_entity_ids_after( int $after_id, int $limit ): array;
|
|
}
|