Compare commits
19 Commits
hardening/2.4
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 0c15266034 | |||
| c13691bcea | |||
| 04ae4c0d0f | |||
| 6f117f4e9b | |||
| c9d5a08a42 | |||
| cd5da4143e | |||
| 15096f064f | |||
| 90877b81e0 | |||
| 6687d54bef | |||
| 86ac84e07c | |||
| b6200c581c | |||
| 81324903a6 | |||
| 3e96357459 | |||
| 80343ec282 | |||
| 33addd1e49 | |||
| bed3f906da | |||
| 7ad65eab95 | |||
| 4b34851316 | |||
| b30baeddf0 |
@@ -3,7 +3,7 @@
|
||||
* Plugin Name: 2meet Data Optimizer
|
||||
* Plugin URI: https://2meet.io/2meet-data-optimizer
|
||||
* Description: 通用 WordPress 反 EAV 引擎:將 postmeta / usermeta / termmeta / commentmeta 自動分流至四象限扁平表(Hot / Warm / Cold / Archive),大幅提升搜尋與篩選效能。從 wp-data-optimizer v2.16.0 提煉的純核心,整合層交給 11 個 AddOn。
|
||||
* Version: 1.4.0
|
||||
* Version: 1.4.3
|
||||
* Requires at least: 6.0
|
||||
* Tested up to: 6.9.4
|
||||
* Requires PHP: 8.1
|
||||
@@ -26,7 +26,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
}
|
||||
|
||||
// ── Constants ──────────────────────────────────────────────────────────────
|
||||
define( 'TMDO_VERSION', '1.4.0' );
|
||||
define( 'TMDO_VERSION', '1.4.3' );
|
||||
define( 'TMDO_DB_VERSION', '2.1.0' );
|
||||
define( 'TMDO_PATH', plugin_dir_path( __FILE__ ) );
|
||||
define( 'TMDO_URL', plugin_dir_url( __FILE__ ) );
|
||||
|
||||
+85
-4
@@ -7,9 +7,78 @@ Versioning follows [Semantic Versioning](https://semver.org/).
|
||||
|
||||
---
|
||||
|
||||
## [1.4.2] — 2026-09-28 — 手冊已知問題修正(hardening 2.4.2)
|
||||
|
||||
**性質**:修正。無 schema 版本變更;archive 表新增索引(見「升級後」)。來源:`2meet-do-manual.md`
|
||||
附錄 F(F-2、F-4〜F-8、F-11)。
|
||||
|
||||
### Fixed
|
||||
|
||||
- **設定頁會說明模式為何沒有變更**:完整表單與 AJAX 區塊儲存都經 `TMDO_Mode_Manager::set()`,
|
||||
過去忽略它回傳的 `WP_Error`:不安全的跳階或 Promotion Guard 拒絕時,頁面仍顯示「已儲存」、
|
||||
模式卻沒變。現在完整表單在重新導向後顯示拒絕原因(每位使用者一次),AJAX 儲存以錯誤訊息回傳。(PR-135,F-2)
|
||||
- **archive 不再重複歸檔**:`wpdo_archive_sweep` 略過已在 archive 表的 meta(依 `original_meta_id`),
|
||||
過去同一筆 meta 每次 sweep 都再寫一列(dev20:300 列只有 150 筆不同)。archive 表新增
|
||||
`idx_original_meta` 索引;`wp tmdo install` 會補上索引並刪除重複列(保留最早一列)。(PR-136,F-6)
|
||||
- **entity 健康面板看得到執行中的 backfill**:批次以 `(entity, group)` 參數排程,面板過去只查
|
||||
`(entity)`,永遠看不到、一直提示可開始。(PR-137,F-11)
|
||||
- **停用與解除安裝清掉所有排程**:改用 `wp_unschedule_hook()`,連帶參數排程的事件
|
||||
(`tmdo_drift_resync`、backfill 批次)也清除;修正錯誤的 `wpdo_user_stress_test_batch` 名稱,
|
||||
補上 `wpdo_migration_tick`、`wpdo_entity_backfill_batch`、`wpdo_auto_promote_check` 與各壓測批次。
|
||||
解除安裝另外刪除 `tmdo_*` option 及 `tmdo_*` transient。(PR-138,F-4、F-5)
|
||||
- 解除安裝被拒絕時的提示改為指向 `wp tmdo bridge-restore-native`(過去說沒有寫回工具);post
|
||||
壓測工具不再使用已退役的 `wc_product` 表。(PR-139,F-7、F-8)
|
||||
|
||||
### 升級後
|
||||
|
||||
- 每個站台執行一次 `wp tmdo install`:為 archive 表加上 `idx_original_meta` 並刪除重複的 archive
|
||||
列(刪除重複只在 CLI 執行,web 啟用外掛時不做)。表很大時請在離峰時段執行。
|
||||
- **未執行前 archive sweep 會暫停**(沒有索引時 NOT EXISTS 會對每筆候選掃整張 archive 表)。
|
||||
sweep 只複製、不刪 postmeta,暫停不會遺失資料。
|
||||
- 解除安裝的 option 清理保留 LatePoint AddOn 的 `tmdo_latepoint_db_version`;設定頁的 AJAX 錯誤訊息
|
||||
不再 2.5 秒後自動消失。(PR-141,驗收修正)
|
||||
|
||||
### 已知、未修改
|
||||
|
||||
- 已歸檔的 meta 以 `meta_id` 判斷:文章還原、修改後再次丟到回收桶,archive 保留的是第一次的值。
|
||||
- post 壓測工具預設仍是 `product`,但 product 已沒有 flat 表,量測會回報 `flat_table_missing`。
|
||||
|
||||
---
|
||||
|
||||
## [1.4.1] — 2026-09-28 — 2.4 驗收修正
|
||||
|
||||
**性質**:修正。無 schema 變更。來源:2.4 全面驗收的 security review 與 correctness review。
|
||||
|
||||
### Fixed
|
||||
|
||||
- **meta_key 的排序不再被清掉**:查詢帶 `meta_key`,且 orderby 在多個排序(陣列或
|
||||
`'meta_value date'`)中仍有 `meta_value`、`meta_value_num` 或該 key 名稱時,1.4.0 會把
|
||||
meta_key 當 EXISTS 路由並清空,WordPress 因此丟掉價格排序。現在只在 orderby 完全沒有引用它時
|
||||
才路由;`meta_compare_key` 不是 `=`(例如 LIKE 會比對到其他 key)時維持原生;排序形狀的
|
||||
group 只有在 orderby 沒有引用它、`meta_value(_num)` 或它的 key 時才當成未使用而略過(沒有
|
||||
meta_key 時它是 WordPress 的主要 clause)。(PR-130)
|
||||
- **ORDER BY 只改寫單獨的 `posts.ID`**:flat-first 與 copy route 共用 `ties_on_post_id()`;
|
||||
外掛加上的 `FIELD(wp_posts.ID, …)`、`(wp_posts.ID IN (…))` 等運算式保持原樣。1.4.0 會在
|
||||
運算式內插入方向,SQL 語法錯誤、頁面沒有結果。正則失敗(PCRE 回溯或 JIT 上限)時回傳原
|
||||
SQL,不再變成空字串。(PR-131)
|
||||
- 呼叫端以 `new WP_Query( array( … ) )` 預設的 router 內部 query var(`wpdo_post_clauses`、
|
||||
`wpdo_post_sort`、`wpdo_post_copy_route`、`wpdo_post_count_sql`)一律清除;copy route 的
|
||||
排序方向改用白名單。無法從網址觸發。(PR-132)
|
||||
- 新文章建立的空 flat 列一併寫入 `post_status` / `post_date` 副本(`wp_insert_post` 在
|
||||
`transition_post_status` 之後才執行,原本留下 NULL,會讓整個 group 關閉 copy route);
|
||||
`wp tmdo post-status-sync` 完成後遞增路由計數版本(dry run 不遞增)。(PR-133)
|
||||
|
||||
### 已知、未修改
|
||||
|
||||
- 1.4.0 的 flat-first 排序同值時依 ID 與排序同方向(原生為 ID DESC),集合與總數相同(已接受)。
|
||||
- 若日後有 group 註冊名為 `post_status` / `post_date` 的欄位,遷移引擎寫副本時 `$data` 與
|
||||
`$formats` 會錯位;目前沒有這樣的 group。
|
||||
|
||||
---
|
||||
|
||||
## [1.4.0] — 2026-09-28 — 百萬級 listing 的路由排序與日期查詢(hardening 2.4)
|
||||
|
||||
**性質**:效能 + 修正。無 schema 變更;post status/date 副本的索引改為三欄(`wp tmdo post-status-sync` 就地替換)。
|
||||
**性質**:效能 + 修正。無 schema 變更;post status/date 副本的索引改為三欄(見「升級後」)。
|
||||
搭配 HivePress AddOn 0.5.0。來源:dev36 第 3 階壓測(130 萬 listing、121 萬 product、6.2 萬 vendor)。
|
||||
|
||||
### Changed
|
||||
@@ -41,9 +110,13 @@ Versioning follows [Semantic Versioning](https://semver.org/).
|
||||
|
||||
### 升級後
|
||||
|
||||
- 已啟用 post status/date 副本的站(`tmdo_post_status_columns` 有 `ready` 的 group)執行一次
|
||||
`wp tmdo post-status-sync`:替換索引並重新同步副本(dev36 130 萬列約 75 s)。未執行前
|
||||
copy route 照常運作,只是維持 1.3.0 的速度。
|
||||
- 只需替換索引:對 `tmdo_post_status_columns` 列出的每個 group 表執行
|
||||
`ALTER TABLE <表> ADD INDEX idx_post_status_date_id (post_status, post_date, post_id), DROP INDEX idx_post_status_date`
|
||||
(空表瞬間完成,dev36 130 萬列約 5 s)。未替換前 copy route 照常運作,只是維持 1.3.0 的速度。
|
||||
- **不要為了換索引執行 `wp tmdo post-status-sync`**:它除了替換索引,還會替**所有**尚未有副本的
|
||||
post group 加上 `post_status` / `post_date` 欄位並逐列回填(大表 ALTER + 全表 UPDATE;dev36
|
||||
130 萬列約 75 s,上千萬列的站更久)。只有要讓更多 group 啟用 copy route 時才執行,並先在
|
||||
離峰時段以 `--dry-run` 確認列數。
|
||||
- 效能數字(dev36 前台,routed):價格區間 0.34 s、價格排序 0.37 s、時薪排序 0.35 s、
|
||||
評分排序 0.51 s、關鍵字 + 價格 0.59 s(原生 6–43 s)。
|
||||
|
||||
@@ -528,3 +601,11 @@ HivePress AddOn 0.3.0、WooCommerce AddOn 0.2.0。
|
||||
- PHPCS 套件 + 0/0 達成
|
||||
- 打包腳本 10 終檢驗收
|
||||
- WPDO_ → TMDO_ migration CLI
|
||||
|
||||
## [1.4.3] — 2026-10-02 — 重新打包
|
||||
|
||||
### Changed
|
||||
- 重新打包(無功能變更):與 WP-MVB v8 樞紐站(dev39)一同驗收後發版;程式碼與前一版相同。
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a transient status message, then fade it out after 2.5s.
|
||||
* Show a status message; success fades out after 2.5s, errors stay.
|
||||
*
|
||||
* @param {HTMLElement} statusEl
|
||||
* @param {string} message
|
||||
@@ -56,6 +56,9 @@
|
||||
statusEl.style.color = isError ? 'var(--color-error, #b03d3d)' : 'var(--color-success, #5a8c5a)';
|
||||
statusEl.classList.add( 'visible' );
|
||||
clearTimeout( statusEl._wpdo_timer );
|
||||
if ( isError ) {
|
||||
return;
|
||||
}
|
||||
statusEl._wpdo_timer = setTimeout( () => {
|
||||
statusEl.classList.remove( 'visible' );
|
||||
}, 2500 );
|
||||
@@ -92,7 +95,7 @@
|
||||
if ( data.success ) {
|
||||
showStatus( statusEl, i18n.saved, false );
|
||||
} else {
|
||||
showStatus( statusEl, i18n.error, true );
|
||||
showStatus( statusEl, ( data.data && data.data.message ) || i18n.error, true );
|
||||
}
|
||||
} )
|
||||
.catch( () => {
|
||||
|
||||
+81
-24
@@ -398,17 +398,7 @@ class TMDO_Admin {
|
||||
|
||||
// v2.5.4: Entity Bridge settings (v2.11.0: post added).
|
||||
update_option( 'wpdo_hook_bus_enabled', isset( $_POST['wpdo_hook_bus_enabled'] ) ? '1' : '0', false );
|
||||
if ( class_exists( 'TMDO_Mode_Manager' ) ) {
|
||||
foreach ( array( 'user', 'post', 'term', 'comment' ) as $entity_type ) {
|
||||
$new_mode = isset( $_POST[ 'wpdo_bridge_mode_' . $entity_type ] )
|
||||
? sanitize_key( wp_unslash( (string) $_POST[ 'wpdo_bridge_mode_' . $entity_type ] ) )
|
||||
: '';
|
||||
if ( TMDO_Mode_Manager::is_valid_mode( $new_mode ) ) {
|
||||
TMDO_Mode_Manager::set( $entity_type, $new_mode );
|
||||
}
|
||||
}
|
||||
TMDO_Mode_Manager::reset_cache();
|
||||
}
|
||||
self::remember_bridge_mode_refusals( self::apply_bridge_modes( self::posted_bridge_modes() ) );
|
||||
if ( class_exists( 'TMDO_Hook_Bus_Bridge' ) ) {
|
||||
TMDO_Hook_Bus_Bridge::reset_cache();
|
||||
}
|
||||
@@ -3144,6 +3134,9 @@ wpdo.getListings({ per_page: 3 }).then(r => console.log(r));'
|
||||
if ( isset( $_GET['wpdo_msg'] ) && 'settings_saved' === sanitize_key( wp_unslash( (string) $_GET['wpdo_msg'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
echo '<div class="notice notice-success is-dismissible"><p>' . esc_html__( '設定已儲存。', '2meet-data-optimizer' ) . '</p></div>';
|
||||
}
|
||||
foreach ( self::pull_bridge_mode_refusals() as $refused ) {
|
||||
echo '<div class="notice notice-error"><p>' . esc_html__( '模式未變更:', '2meet-data-optimizer' ) . esc_html( $refused ) . '</p></div>';
|
||||
}
|
||||
$enabled = class_exists( 'TMDO_Email_Notifier' ) && TMDO_Email_Notifier::is_enabled();
|
||||
$email = class_exists( 'TMDO_Email_Notifier' ) ? TMDO_Email_Notifier::recipient() : '';
|
||||
$throttle = class_exists( 'TMDO_Email_Notifier' ) ? TMDO_Email_Notifier::throttle_hours() : 24;
|
||||
@@ -3743,22 +3736,33 @@ wpdo.getListings({ per_page: 3 }).then(r => console.log(r));'
|
||||
}
|
||||
}
|
||||
|
||||
private static function save_section_entity_bridge(): void {
|
||||
/**
|
||||
* Save the Entity Bridge section (Hook Bus switch and bridge modes).
|
||||
*
|
||||
* @return string[] Refused changes, "<entity>:<reason>".
|
||||
*/
|
||||
private static function save_section_entity_bridge(): array {
|
||||
update_option( 'wpdo_hook_bus_enabled', isset( $_POST['wpdo_hook_bus_enabled'] ) ? '1' : '0', false );
|
||||
if ( class_exists( 'TMDO_Mode_Manager' ) ) {
|
||||
foreach ( array( 'user', 'post', 'term', 'comment' ) as $entity_type ) {
|
||||
$new_mode = isset( $_POST[ 'wpdo_bridge_mode_' . $entity_type ] )
|
||||
? sanitize_key( wp_unslash( (string) $_POST[ 'wpdo_bridge_mode_' . $entity_type ] ) )
|
||||
: '';
|
||||
if ( TMDO_Mode_Manager::is_valid_mode( $new_mode ) ) {
|
||||
TMDO_Mode_Manager::set( $entity_type, $new_mode );
|
||||
}
|
||||
}
|
||||
TMDO_Mode_Manager::reset_cache();
|
||||
}
|
||||
$refused = self::apply_bridge_modes( self::posted_bridge_modes() );
|
||||
if ( class_exists( 'TMDO_Hook_Bus_Bridge' ) ) {
|
||||
TMDO_Hook_Bus_Bridge::reset_cache();
|
||||
}
|
||||
return $refused;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bridge modes posted by the settings form, keyed by entity type ('' when absent).
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
private static function posted_bridge_modes(): array {
|
||||
$posted = array();
|
||||
foreach ( array( 'user', 'post', 'term', 'comment' ) as $entity_type ) {
|
||||
$posted[ $entity_type ] = isset( $_POST[ 'wpdo_bridge_mode_' . $entity_type ] )
|
||||
? sanitize_key( wp_unslash( (string) $_POST[ 'wpdo_bridge_mode_' . $entity_type ] ) )
|
||||
: '';
|
||||
}
|
||||
return $posted;
|
||||
}
|
||||
|
||||
private static function save_section_hp_transient(): void {
|
||||
@@ -3786,6 +3790,56 @@ wpdo.getListings({ per_page: 3 }).then(r => console.log(r));'
|
||||
}
|
||||
// phpcs:enable WordPress.Security.NonceVerification.Missing,Squiz.Commenting.FunctionComment.Missing,Squiz.Commenting.FunctionComment.WrongStyle
|
||||
|
||||
/**
|
||||
* Apply posted bridge modes through TMDO_Mode_Manager::set(). Empty or
|
||||
* unknown modes are skipped; refused changes (unsafe jump, Promotion Guard)
|
||||
* are returned instead of being dropped silently (2.4.2 PR-135).
|
||||
*
|
||||
* @param array<string, string> $posted Mode per entity type.
|
||||
* @return string[] Refused changes, "<entity>:<reason>".
|
||||
*/
|
||||
public static function apply_bridge_modes( array $posted ): array {
|
||||
if ( ! class_exists( 'TMDO_Mode_Manager' ) ) {
|
||||
return array();
|
||||
}
|
||||
$refused = array();
|
||||
foreach ( $posted as $entity_type => $new_mode ) {
|
||||
if ( ! TMDO_Mode_Manager::is_valid_mode( (string) $new_mode ) ) {
|
||||
continue;
|
||||
}
|
||||
$result = TMDO_Mode_Manager::set( (string) $entity_type, (string) $new_mode );
|
||||
if ( is_wp_error( $result ) ) {
|
||||
$refused[] = $entity_type . ':' . $result->get_error_message();
|
||||
}
|
||||
}
|
||||
TMDO_Mode_Manager::reset_cache();
|
||||
return $refused;
|
||||
}
|
||||
|
||||
/**
|
||||
* Keep refused bridge-mode changes for the page the settings form redirects to.
|
||||
*
|
||||
* @param string[] $refused Refused changes.
|
||||
* @return void
|
||||
*/
|
||||
public static function remember_bridge_mode_refusals( array $refused ): void {
|
||||
if ( $refused ) {
|
||||
set_transient( 'wpdo_mode_refused_' . get_current_user_id(), $refused, 5 * MINUTE_IN_SECONDS );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Refused bridge-mode changes remembered for this user, once.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public static function pull_bridge_mode_refusals(): array {
|
||||
$key = 'wpdo_mode_refused_' . get_current_user_id();
|
||||
$refused = get_transient( $key );
|
||||
delete_transient( $key );
|
||||
return is_array( $refused ) ? $refused : array();
|
||||
}
|
||||
|
||||
/**
|
||||
* AJAX: save a single settings section without a full page reload.
|
||||
*/
|
||||
@@ -3807,7 +3861,10 @@ wpdo.getListings({ per_page: 3 }).then(r => console.log(r));'
|
||||
if ( ! isset( $handlers[ $section ] ) ) {
|
||||
wp_send_json_error( 'invalid_section', 400 );
|
||||
}
|
||||
self::{$handlers[ $section ]}();
|
||||
$refused = self::{$handlers[ $section ]}();
|
||||
if ( is_array( $refused ) && $refused ) {
|
||||
wp_send_json_error( array( 'message' => __( '部分模式未變更:', '2meet-data-optimizer' ) . implode( ';', $refused ) ) );
|
||||
}
|
||||
wp_send_json_success( array( 'message' => __( '設定已儲存。', '2meet-data-optimizer' ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -217,6 +217,16 @@ class TMDO_Installer {
|
||||
// Idempotent — only creates tables that don't already exist.
|
||||
self::install_v2_tables();
|
||||
|
||||
// 1.4.2: archive sweeps before this release copied trashed meta daily.
|
||||
// One unbounded DELETE: CLI only, never in a web activation.
|
||||
if ( defined( 'WP_CLI' ) && WP_CLI && class_exists( 'TMDO_Zone_Archive' ) ) {
|
||||
global $wpdb;
|
||||
$archive = TMDO_Zone_Archive::table();
|
||||
if ( $archive === $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $archive ) ) ) ) {
|
||||
TMDO_Zone_Archive::remove_duplicates();
|
||||
}
|
||||
}
|
||||
|
||||
update_option( 'wpdo_db_version', self::SCHEMA_VERSION );
|
||||
|
||||
// Register wpdo_features with autoload=no so it doesn't inflate every page load.
|
||||
@@ -771,31 +781,46 @@ class TMDO_Installer {
|
||||
return $status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Every cron hook the plugin schedules. Cleared with wp_unschedule_hook(),
|
||||
* which also removes events scheduled with args (tmdo_drift_resync( 'post' ),
|
||||
* backfill batches) that wp_clear_scheduled_hook( $hook ) leaves behind
|
||||
* (2.4.2 PR-138).
|
||||
*/
|
||||
private const CRON_HOOKS = array(
|
||||
'wpdo_warm_cleanup',
|
||||
'wpdo_archive_sweep',
|
||||
'wpdo_errors_gc',
|
||||
'wpdo_flush_views',
|
||||
'wpdo_remove_uae_plugin_dir',
|
||||
'wpdo_daily_health_check',
|
||||
'wpdo_snapshot_prune_daily',
|
||||
'wpdo_fsm_automator_run',
|
||||
'wpdo_collect_site_metrics',
|
||||
'wpdo_health_snapshot_monthly',
|
||||
'wpdo_post_shadow_verify',
|
||||
'wpdo_term_comment_shadow_verify',
|
||||
'tmdo_drift_resync',
|
||||
'tmdo_ensure_group_indexes',
|
||||
'wpdo_entity_backfill_batch',
|
||||
'wpdo_migration_tick',
|
||||
'wpdo_auto_promote_check',
|
||||
'wpdo_post_stress_test_batch',
|
||||
'wpdo_stress_test_batch',
|
||||
'wpdo_term_stress_test_batch',
|
||||
'wpdo_comment_stress_test_batch',
|
||||
);
|
||||
|
||||
/**
|
||||
* Called on plugin deactivation. Non-destructive.
|
||||
*/
|
||||
public static function deactivate(): void {
|
||||
wp_clear_scheduled_hook( 'wpdo_warm_cleanup' );
|
||||
wp_clear_scheduled_hook( 'wpdo_archive_sweep' );
|
||||
// v2.14.0: clear all plugin cron hooks (was incomplete pre-v2.14.0).
|
||||
wp_clear_scheduled_hook( 'wpdo_errors_gc' );
|
||||
wp_clear_scheduled_hook( 'wpdo_flush_views' );
|
||||
wp_clear_scheduled_hook( 'wpdo_remove_uae_plugin_dir' );
|
||||
wp_clear_scheduled_hook( 'wpdo_daily_health_check' );
|
||||
wp_clear_scheduled_hook( 'wpdo_snapshot_prune_daily' );
|
||||
wp_clear_scheduled_hook( 'wpdo_fsm_automator_run' );
|
||||
wp_clear_scheduled_hook( 'wpdo_collect_site_metrics' );
|
||||
wp_clear_scheduled_hook( 'wpdo_health_snapshot_monthly' );
|
||||
wp_clear_scheduled_hook( 'wpdo_post_shadow_verify' );
|
||||
wp_clear_scheduled_hook( 'wpdo_term_comment_shadow_verify' );
|
||||
wp_clear_scheduled_hook( 'tmdo_drift_resync' );
|
||||
wp_clear_scheduled_hook( 'tmdo_ensure_group_indexes' );
|
||||
wp_clear_scheduled_hook( 'wpdo_post_stress_test_batch' );
|
||||
wp_clear_scheduled_hook( 'wpdo_user_stress_test_batch' );
|
||||
wp_clear_scheduled_hook( 'wpdo_term_stress_test_batch' );
|
||||
wp_clear_scheduled_hook( 'wpdo_comment_stress_test_batch' );
|
||||
foreach ( self::CRON_HOOKS as $hook ) {
|
||||
wp_unschedule_hook( $hook );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ── v2.14.0: Multisite-aware site cleanup ─────────────────────────────────
|
||||
|
||||
/**
|
||||
@@ -967,42 +992,26 @@ class TMDO_Installer {
|
||||
// Sweep any remaining wpdo_* options (stragglers introduced post-v2.14.0
|
||||
// or by 3rd-party hooks). Validates name pattern before delete to avoid
|
||||
// accidental option removal.
|
||||
$residual = $wpdb->get_col(
|
||||
$wpdb->prepare(
|
||||
"SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE %s",
|
||||
$wpdb->esc_like( 'wpdo_' ) . '%'
|
||||
)
|
||||
);
|
||||
foreach ( (array) $residual as $opt ) {
|
||||
if ( preg_match( '/^wpdo_[a-zA-Z0-9_]+$/', $opt ) && delete_option( $opt ) ) {
|
||||
++$options_deleted;
|
||||
// 1.4.2: tmdo_* options and their transients too (tmdo_schema_deferred,
|
||||
// tmdo_entity_indexes, tmdo_cov_* …) — a reinstall saw stale ones.
|
||||
// tmdo_latepoint_* belongs to the LatePoint add-on.
|
||||
foreach ( array( 'wpdo_', 'tmdo_', '_transient_tmdo_', '_transient_timeout_tmdo_' ) as $prefix ) {
|
||||
$residual = $wpdb->get_col(
|
||||
$wpdb->prepare(
|
||||
"SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE %s",
|
||||
$wpdb->esc_like( $prefix ) . '%'
|
||||
)
|
||||
);
|
||||
foreach ( (array) $residual as $opt ) {
|
||||
if ( preg_match( '/^(_transient_(timeout_)?)?(wpdo|tmdo)_(?!latepoint_)[a-zA-Z0-9_]+$/', $opt ) && delete_option( $opt ) ) {
|
||||
++$options_deleted;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ── 5) Clear cron events ──────────────────────────────────────────────
|
||||
$crons = array(
|
||||
'wpdo_warm_cleanup',
|
||||
'wpdo_archive_sweep',
|
||||
'wpdo_errors_gc',
|
||||
'wpdo_flush_views',
|
||||
'wpdo_remove_uae_plugin_dir',
|
||||
'wpdo_daily_health_check',
|
||||
'wpdo_snapshot_prune_daily',
|
||||
'wpdo_fsm_automator_run',
|
||||
'wpdo_collect_site_metrics',
|
||||
'wpdo_health_snapshot_monthly',
|
||||
'wpdo_post_shadow_verify',
|
||||
'wpdo_term_comment_shadow_verify',
|
||||
'tmdo_drift_resync',
|
||||
'tmdo_ensure_group_indexes',
|
||||
'wpdo_post_stress_test_batch',
|
||||
'wpdo_user_stress_test_batch',
|
||||
'wpdo_term_stress_test_batch',
|
||||
'wpdo_comment_stress_test_batch',
|
||||
);
|
||||
foreach ( $crons as $hook ) {
|
||||
if ( false !== wp_next_scheduled( $hook ) ) {
|
||||
wp_clear_scheduled_hook( $hook );
|
||||
foreach ( self::CRON_HOOKS as $hook ) {
|
||||
if ( wp_unschedule_hook( $hook ) ) {
|
||||
++$crons_cleared;
|
||||
}
|
||||
}
|
||||
@@ -1440,7 +1449,8 @@ class TMDO_Installer {
|
||||
original_meta_id bigint(20) unsigned NOT NULL DEFAULT 0,
|
||||
PRIMARY KEY (id),
|
||||
KEY idx_post_id (post_id),
|
||||
KEY idx_post_type_date (post_type, archived_at)
|
||||
KEY idx_post_type_date (post_type, archived_at),
|
||||
KEY idx_original_meta (original_meta_id)
|
||||
) {$charset};";
|
||||
|
||||
foreach ( $sqls as $sql ) {
|
||||
|
||||
@@ -872,7 +872,6 @@ final class TMDO_Post_Stress_Tester {
|
||||
global $wpdb;
|
||||
$prefix = $wpdb->prefix . 'wpdo_post_';
|
||||
$map = array(
|
||||
'product' => $prefix . 'wc_product',
|
||||
'hp_listing' => $prefix . 'hp_listing_core',
|
||||
'hp_request' => $prefix . 'hp_request_core',
|
||||
'hp_vendor' => $prefix . 'hp_vendor_core',
|
||||
@@ -1036,7 +1035,6 @@ final class TMDO_Post_Stress_Tester {
|
||||
return array(
|
||||
$prefix . 'wp_core',
|
||||
$prefix . 'attachment',
|
||||
$prefix . 'wc_product',
|
||||
$prefix . 'hp_listing_core',
|
||||
$prefix . 'hp_request_core',
|
||||
$prefix . 'hp_vendor_core',
|
||||
|
||||
@@ -325,7 +325,20 @@ final class TMDO_Entity_Health {
|
||||
return TMDO_Mode_Manager::ALL_MODES[ $idx - 1 ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a backfill batch is scheduled for any group of the entity. Batches
|
||||
* are scheduled with (entity, group) args, so looking for (entity) alone
|
||||
* never found one (2.4.2 PR-137).
|
||||
*
|
||||
* @param string $entity_type Entity type.
|
||||
* @return bool
|
||||
*/
|
||||
private static function is_backfill_active( string $entity_type ): bool {
|
||||
return (bool) wp_next_scheduled( 'wpdo_entity_backfill_batch', array( $entity_type ) );
|
||||
foreach ( TMDO_Entity_Registry::get_groups_for_type( $entity_type ) as $group ) {
|
||||
if ( wp_next_scheduled( 'wpdo_entity_backfill_batch', array( $entity_type, $group ) ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,6 +163,10 @@ final class TMDO_Post_Status_Sync {
|
||||
}
|
||||
self::set_state( $group, 'ready' );
|
||||
}
|
||||
// Routed counts cached while the copies were stale must go.
|
||||
if ( ! $dry_run && class_exists( 'TMDO_Post_Query_Router' ) ) {
|
||||
TMDO_Post_Query_Router::bump_count_version();
|
||||
}
|
||||
return $report;
|
||||
}
|
||||
|
||||
|
||||
@@ -125,9 +125,17 @@ class TMDO_Post_Query_Router {
|
||||
global $wpdb;
|
||||
foreach ( TMDO_Post_Fields::groups_for_post_type( $post->post_type ) as $group ) {
|
||||
$table = TMDO_Schema_Manager::get_table_name( 'post', $group );
|
||||
if ( TMDO_Schema_Manager::table_exists( $table ) ) {
|
||||
$wpdb->query( $wpdb->prepare( "INSERT IGNORE INTO `{$table}` (`post_id`) VALUES (%d)", (int) $post_id ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
||||
if ( ! TMDO_Schema_Manager::table_exists( $table ) ) {
|
||||
continue;
|
||||
}
|
||||
// With the status / date copies: this runs after transition_post_status,
|
||||
// and one NULL copy turns the copy route off for the whole group.
|
||||
$copies = class_exists( 'TMDO_Post_Status_Sync' ) ? TMDO_Post_Status_Sync::insert_columns( (int) $post_id, $group ) : array();
|
||||
if ( $copies ) {
|
||||
$wpdb->query( $wpdb->prepare( "INSERT IGNORE INTO `{$table}` (`post_id`, `post_status`, `post_date`) VALUES (%d, %s, %s)", (int) $post_id, $copies['post_status'], $copies['post_date'] ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
||||
continue;
|
||||
}
|
||||
$wpdb->query( $wpdb->prepare( "INSERT IGNORE INTO `{$table}` (`post_id`) VALUES (%d)", (int) $post_id ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,6 +146,11 @@ class TMDO_Post_Query_Router {
|
||||
* @return void
|
||||
*/
|
||||
public function pre_get_posts( \WP_Query $query ): void {
|
||||
// The router's query vars are its own: drop any a caller passed in.
|
||||
foreach ( array( self::QUERY_VAR, self::SORT_VAR, self::COPY_VAR, self::COUNT_VAR ) as $var ) {
|
||||
$query->set( $var, '' );
|
||||
}
|
||||
|
||||
// Mode gate: only run when post mode is reads_from_flat.
|
||||
if ( ! self::is_router_active() ) {
|
||||
return;
|
||||
@@ -172,8 +185,11 @@ class TMDO_Post_Query_Router {
|
||||
|
||||
// meta_key + orderby meta_value(_num): native INNER JOINs the key
|
||||
// (EXISTS) and orders by meta_value+0 (NUMERIC) or meta_value.
|
||||
$meta_key = $query->get( 'meta_key' );
|
||||
$take_key = is_string( $meta_key ) && in_array( $sort_name, array( 'meta_value', 'meta_value_num' ), true )
|
||||
// A key comparison other than equality (meta_compare_key LIKE …) matches
|
||||
// other keys too: not a test on one flat column.
|
||||
$meta_key = $query->get( 'meta_key' );
|
||||
$key_exact = in_array( (string) $query->get( 'meta_compare_key' ), array( '', '=' ), true );
|
||||
$take_key = $key_exact && is_string( $meta_key ) && in_array( $sort_name, array( 'meta_value', 'meta_value_num' ), true )
|
||||
&& null !== self::field_for( array( 'key' => $meta_key ), $pt );
|
||||
if ( $take_key ) {
|
||||
$field = self::field_for( array( 'key' => $meta_key ), $pt );
|
||||
@@ -192,11 +208,13 @@ class TMDO_Post_Query_Router {
|
||||
$routed[ $pt ][] = $route;
|
||||
$sort = self::sort_for( $pt, $route, $direction );
|
||||
}
|
||||
// meta_key alone (no meta_value, not a meta_value sort): WP_Query adds a
|
||||
// clause that tests the key exists — HivePress's featured-listing lookup.
|
||||
$exists_key = ! $take_key && is_string( $meta_key ) && '' !== $meta_key
|
||||
// meta_key alone (no meta_value, not ordered by): WP_Query adds a clause
|
||||
// that tests the key exists — HivePress's featured-listing lookup. Any
|
||||
// orderby naming meta_value, meta_value_num or the key sorts by that
|
||||
// clause, which clearing meta_key would drop.
|
||||
$exists_key = ! $take_key && $key_exact && is_string( $meta_key ) && '' !== $meta_key
|
||||
&& '' === (string) $query->get( 'meta_value' ) && '' === (string) $query->get( 'meta_compare' )
|
||||
&& ! in_array( $sort_name, array( 'meta_value', 'meta_value_num' ), true )
|
||||
&& ! array_intersect( $named, array( 'meta_value', 'meta_value_num', $meta_key ) )
|
||||
&& null !== self::field_for( array( 'key' => $meta_key ), $pt );
|
||||
if ( $exists_key ) {
|
||||
$route = self::route_clause(
|
||||
@@ -220,8 +238,12 @@ class TMDO_Post_Query_Router {
|
||||
if ( ! isset( $clause['key'] ) ) {
|
||||
// Sort shape: matches every post, only orders by the key.
|
||||
$name = 'AND' === $relation ? self::sort_shape( $clause ) : '';
|
||||
if ( '' !== $name && ! in_array( $name, $named, true ) && self::field_for( $clause[ $name ], $pt ) ) {
|
||||
continue; // Matches every post and orders nothing here (a copy of a search's meta query).
|
||||
// Matches every post and orders nothing here (a copy of a search's meta
|
||||
// query) — unless orderby names it, or meta_value(_num) / its key, which
|
||||
// sort by it when it is WordPress's primary (first) clause.
|
||||
if ( '' !== $name && ! array_intersect( $named, array( $name, 'meta_value', 'meta_value_num', (string) ( $clause[ $name ]['key'] ?? '' ) ) )
|
||||
&& self::field_for( $clause[ $name ], $pt ) ) {
|
||||
continue;
|
||||
}
|
||||
$field = '' !== $name && $name === $sort_name ? self::field_for( $clause[ $name ], $pt ) : null;
|
||||
if ( $field ) {
|
||||
@@ -380,7 +402,7 @@ class TMDO_Post_Query_Router {
|
||||
if ( empty( $copy ) ) {
|
||||
return $orderby;
|
||||
}
|
||||
return '`' . self::table_alias( $copy['post_type'], $copy['group'] ) . '`.`post_date` ' . $copy['order'];
|
||||
return '`' . self::table_alias( $copy['post_type'], $copy['group'] ) . '`.`post_date` ' . ( 'ASC' === $copy['order'] ? 'ASC' : 'DESC' );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -769,22 +791,58 @@ class TMDO_Post_Query_Router {
|
||||
if ( empty( $copy ) ) {
|
||||
return $request;
|
||||
}
|
||||
return self::ties_on_post_id( self::without_group_by( $request ), self::table_alias( $copy['post_type'], $copy['group'] ), '' );
|
||||
}
|
||||
|
||||
/**
|
||||
* ORDER BY terms that are posts.ID alone (with or without a direction)
|
||||
* read as the equal flat post_id — in $direction, or each in its own when
|
||||
* $direction is '' — and only once. posts.ID inside an expression a plugin
|
||||
* added (FIELD(), IN …) is left alone: a direction inserted there breaks
|
||||
* the SQL.
|
||||
*
|
||||
* @param string $request SELECT statement.
|
||||
* @param string $alias Flat table alias.
|
||||
* @param string $direction 'ASC', 'DESC' or '' (keep each term's own).
|
||||
* @return string
|
||||
*/
|
||||
private static function ties_on_post_id( string $request, string $alias, string $direction ): string {
|
||||
global $wpdb;
|
||||
$tie = '`' . self::table_alias( $copy['post_type'], $copy['group'] ) . '`.`post_id` ';
|
||||
return (string) preg_replace_callback(
|
||||
'/\bORDER BY\b(?!.*\bORDER BY\b).*$/s',
|
||||
static function ( $m ) use ( $wpdb, $tie ) {
|
||||
$order = (string) preg_replace_callback(
|
||||
'/`?' . preg_quote( $wpdb->posts, '/' ) . '`?\.`?ID`?(?!\w)(?:\s+(ASC|DESC)\b)?/i',
|
||||
static fn( $id ) => $tie . ( 'DESC' === strtoupper( $id[1] ?? '' ) ? 'DESC' : 'ASC' ),
|
||||
$m[0]
|
||||
);
|
||||
return (string) preg_replace( '/(,\s*' . preg_quote( $tie, '/' ) . '(ASC|DESC))(\s*,\s*' . preg_quote( $tie, '/' ) . '\2)+/', '$1', $order );
|
||||
},
|
||||
self::without_group_by( $request )
|
||||
$tie = "`{$alias}`.`post_id` ";
|
||||
$id = '`?' . preg_quote( $wpdb->posts, '/' ) . '`?\.`?ID`?';
|
||||
return self::replaced(
|
||||
preg_replace_callback(
|
||||
'/\bORDER BY\b(?!.*\bORDER BY\b).*$/s',
|
||||
static function ( $m ) use ( $id, $tie, $direction ) {
|
||||
$order = self::replaced(
|
||||
preg_replace_callback(
|
||||
'/(?<=ORDER BY |,)(\s*)' . $id . '(?:\s+(ASC|DESC)\b)?(?=\s*(?:,|\bLIMIT\b|$))/i',
|
||||
static fn( $t ) => $t[1] . $tie . ( '' !== $direction ? $direction : ( 'DESC' === strtoupper( $t[2] ?? '' ) ? 'DESC' : 'ASC' ) ),
|
||||
$m[0]
|
||||
),
|
||||
$m[0]
|
||||
);
|
||||
return self::replaced( preg_replace( '/(,\s*' . preg_quote( $tie, '/' ) . '(ASC|DESC))(\s*,\s*' . preg_quote( $tie, '/' ) . '\2)+/', '$1', $order ), $order );
|
||||
},
|
||||
$request
|
||||
),
|
||||
$request
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* A preg_* result, or the text it was given when PCRE failed (backtrack
|
||||
* or JIT stack limit on a very long request): the query stays unrouted
|
||||
* in shape rather than empty.
|
||||
*
|
||||
* @param string|null $result preg_* return value.
|
||||
* @param string $fallback Input text.
|
||||
* @return string
|
||||
*/
|
||||
private static function replaced( ?string $result, string $fallback ): string {
|
||||
return $result ?? $fallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* WordPress groups by posts.ID for any tax or meta query. With a flat row
|
||||
* (one per post) as the only join there is nothing to collapse, and the
|
||||
@@ -799,7 +857,7 @@ class TMDO_Post_Query_Router {
|
||||
if ( 1 !== preg_match_all( '/\bJOIN\b/i', $request ) ) {
|
||||
return $request;
|
||||
}
|
||||
return (string) preg_replace( '/\s+GROUP BY\s+`?' . preg_quote( $wpdb->posts, '/' ) . '`?\.`?ID`?(?=\s)/', ' ', $request, 1 );
|
||||
return self::replaced( preg_replace( '/\s+GROUP BY\s+`?' . preg_quote( $wpdb->posts, '/' ) . '`?\.`?ID`?(?=\s)/', ' ', $request, 1 ), $request );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -873,16 +931,9 @@ class TMDO_Post_Query_Router {
|
||||
// post_id, once, in the sort's direction: a (column, post_id) index then
|
||||
// returns rows in order with no filesort. Ties are ordered by ID the same
|
||||
// way as the column (natively ID DESC); pagination stays stable.
|
||||
$tie = "`{$alias}`.`post_id` " . ( 'ASC' === strtoupper( (string) $sort['order'] ) ? 'ASC' : 'DESC' );
|
||||
$flat_first = preg_replace_callback(
|
||||
'/\bORDER BY\b(?!.*\bORDER BY\b).*$/s',
|
||||
static function ( $m ) use ( $wpdb, $tie ) {
|
||||
$order = (string) preg_replace( '/`?' . preg_quote( $wpdb->posts, '/' ) . '`?\.`?ID`?(?!\w)(\s+(ASC|DESC)\b)?/i', $tie, $m[0] );
|
||||
return (string) preg_replace( '/(,\s*' . preg_quote( $tie, '/' ) . ')(\s*,\s*' . preg_quote( $tie, '/' ) . ')+/', '$1', $order );
|
||||
},
|
||||
(string) $flat_first
|
||||
);
|
||||
return (string) preg_replace( '/^\s*SELECT\s/', 'SELECT STRAIGHT_JOIN ', (string) $flat_first, 1 );
|
||||
$direction = 'ASC' === strtoupper( (string) $sort['order'] ) ? 'ASC' : 'DESC';
|
||||
$flat_first = self::ties_on_post_id( $flat_first, $alias, $direction );
|
||||
return self::replaced( preg_replace( '/^\s*SELECT\s/', 'SELECT STRAIGHT_JOIN ', $flat_first, 1 ), $request );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -892,7 +943,7 @@ class TMDO_Post_Query_Router {
|
||||
* @return string
|
||||
*/
|
||||
private static function without_found_rows( string $request ): string {
|
||||
return (string) preg_replace( '/\bSQL_CALC_FOUND_ROWS\s+/', '', $request, 1 );
|
||||
return self::replaced( preg_replace( '/\bSQL_CALC_FOUND_ROWS\s+/', '', $request, 1 ), $request );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -210,7 +210,15 @@ class TMDO_Zone_Archive {
|
||||
global $wpdb;
|
||||
|
||||
$cutoff = gmdate( 'Y-m-d H:i:s', time() - ( $days * DAY_IN_SECONDS ) );
|
||||
// Rows already archived are skipped: the sweep used to copy the same
|
||||
// trashed meta again every day (2.4.2 PR-136).
|
||||
$table = self::table();
|
||||
// Without the index each candidate scans the archive: wait for `wp tmdo install`.
|
||||
if ( ! TMDO_IS_SQLITE && ! $wpdb->get_var( "SHOW INDEX FROM `{$table}` WHERE Key_name = 'idx_original_meta'" ) ) { // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- internal table name
|
||||
return 0;
|
||||
}
|
||||
|
||||
// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- table name from internal self::table()
|
||||
$rows = $wpdb->get_results(
|
||||
$wpdb->prepare(
|
||||
"SELECT pm.meta_id, pm.post_id, pm.meta_key, pm.meta_value, p.post_type
|
||||
@@ -218,12 +226,14 @@ class TMDO_Zone_Archive {
|
||||
INNER JOIN {$wpdb->posts} p ON p.ID = pm.post_id
|
||||
WHERE p.post_status = 'trash'
|
||||
AND p.post_modified_gmt < %s
|
||||
AND NOT EXISTS ( SELECT 1 FROM `{$table}` a WHERE a.original_meta_id = pm.meta_id )
|
||||
LIMIT %d",
|
||||
$cutoff,
|
||||
$limit
|
||||
),
|
||||
ARRAY_A
|
||||
);
|
||||
// phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
||||
|
||||
if ( ! $rows ) {
|
||||
return 0;
|
||||
@@ -245,6 +255,21 @@ class TMDO_Zone_Archive {
|
||||
return count( $entries );
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete archive rows that copy the same original meta row again, keeping
|
||||
* the first copy (sweeps before 1.4.2 archived trashed meta every day).
|
||||
* Rows without an original meta id are left alone.
|
||||
*
|
||||
* @return int Rows deleted.
|
||||
*/
|
||||
public static function remove_duplicates(): int {
|
||||
global $wpdb;
|
||||
$table = self::table();
|
||||
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- table name from internal self::table()
|
||||
$deleted = $wpdb->query( "DELETE FROM `{$table}` WHERE original_meta_id > 0 AND id NOT IN ( SELECT keep_id FROM ( SELECT MIN(id) AS keep_id FROM `{$table}` WHERE original_meta_id > 0 GROUP BY original_meta_id ) AS k )" );
|
||||
return is_int( $deleted ) ? $deleted : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get archive statistics.
|
||||
*
|
||||
|
||||
+18
-2
@@ -4,7 +4,7 @@ Tags: performance, database, postmeta, optimization, hivepress
|
||||
Requires at least: 6.0
|
||||
Tested up to: 6.9
|
||||
Requires PHP: 8.1
|
||||
Stable tag: 1.4.0
|
||||
Stable tag: 1.4.3
|
||||
License: GPLv2 or later
|
||||
License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
||||
|
||||
@@ -107,10 +107,26 @@ The Classifier tab analyzes your existing `wp_postmeta` data (access frequency,
|
||||
|
||||
== Changelog ==
|
||||
|
||||
= 1.4.3 =
|
||||
* 重新打包(無功能變更):與 WP-MVB v8 樞紐站(dev39)一同驗收後發版;程式碼與前一版相同。
|
||||
|
||||
= 1.4.2 =
|
||||
* The settings page shows why a bridge-mode change was refused (unsafe jump, Promotion Guard) instead of reporting it saved
|
||||
* Archive sweep skips meta already archived; `wp tmdo install` adds an index on original_meta_id and removes duplicate archive rows (the sweep waits until the index exists)
|
||||
* Entity health sees a running backfill (batches are scheduled with entity and group args)
|
||||
* Deactivate and uninstall clear every scheduled event, including ones scheduled with args; uninstall also removes tmdo_* options and transients
|
||||
* The refused-uninstall notice points to `wp tmdo bridge-restore-native`; the post stress tester no longer uses the retired wc_product table
|
||||
|
||||
= 1.4.1 =
|
||||
* A query ordered by its meta_key among several orderings (or by the key's name) keeps meta_key native; meta_compare_key other than '=' is not routed; a sort group stays when orderby may use it as the primary clause
|
||||
* Only standalone posts.ID terms in ORDER BY become flat post_id tie-breaks (FIELD()/IN expressions from other plugins are left alone); PCRE failures keep the original SQL
|
||||
* Router query vars preset by callers are dropped
|
||||
* New posts' flat rows get their status/date copies; post-status-sync invalidates cached routed counts
|
||||
|
||||
= 1.4.0 =
|
||||
* Flat-first sorts read the ID tie-break from the flat post_id, so a declared (column, post_id) index returns rows in order; ties now follow the sort direction
|
||||
* Meta clauses without a value route as EXISTS; HivePress's featured-listing lookup on every search page uses the flat table
|
||||
* Date-ordered routed searches drop the redundant GROUP BY and use a (post_status, post_date, post_id) index (run `wp tmdo post-status-sync` once to replace the index)
|
||||
* Date-ordered routed searches drop the redundant GROUP BY and use a (post_status, post_date, post_id) index (replace the index on the tables listed in `tmdo_post_status_columns`; `wp tmdo post-status-sync` also adds the copy columns to every other post group)
|
||||
* Rows rebuilt by the migration engine keep their status/date copies and invalidate cached routed counts
|
||||
* Live test tools no longer flush the object cache
|
||||
|
||||
|
||||
+2
-1
@@ -180,7 +180,7 @@ if ( ! function_exists( 'do_action_ref_array' ) ) {
|
||||
}
|
||||
}
|
||||
if ( ! function_exists( 'wp_next_scheduled' ) ) {
|
||||
function wp_next_scheduled( string $hook ): int|false { return false; }
|
||||
function wp_next_scheduled( string $hook, array $args = array() ): int|false { return $GLOBALS['_wp_next_scheduled'][ $hook ][ md5( serialize( $args ) ) ] ?? false; }
|
||||
}
|
||||
if ( ! function_exists( 'wp_schedule_event' ) ) {
|
||||
function wp_schedule_event( int $t, string $r, string $h ): bool { return true; }
|
||||
@@ -188,6 +188,7 @@ if ( ! function_exists( 'wp_schedule_event' ) ) {
|
||||
if ( ! function_exists( 'wp_schedule_single_event' ) ) {
|
||||
function wp_schedule_single_event( int $ts, string $hook ): bool { return true; }
|
||||
}
|
||||
if ( ! function_exists( 'wp_unschedule_hook' ) ) { function wp_unschedule_hook( string $hook ): int|false { $GLOBALS['_wp_unscheduled'][] = $hook; return 0; } }
|
||||
if ( ! function_exists( 'wp_clear_scheduled_hook' ) ) {
|
||||
function wp_clear_scheduled_hook( string $hook ): int|false { return 0; }
|
||||
}
|
||||
|
||||
@@ -303,7 +303,8 @@ class DriftCheckTest extends TestCase {
|
||||
}
|
||||
// Literal: uninstall.php does not load TMDO_Drift_Check.
|
||||
$installer = (string) file_get_contents( WPDO_PLUGIN_DIR . 'includes/class-tmdo-installer.php' );
|
||||
$this->assertSame( 2, substr_count( $installer, "'" . TMDO_Drift_Check::RESYNC_HOOK . "'" ), 'cleared on deactivate and uninstall' );
|
||||
// One CRON_HOOKS list serves deactivate and uninstall (InstallerCleanupTest covers both).
|
||||
$this->assertSame( 1, substr_count( $installer, "'" . TMDO_Drift_Check::RESYNC_HOOK . "'" ), 'listed in CRON_HOOKS' );
|
||||
}
|
||||
|
||||
public function test_the_daily_tick_runs_on_the_daily_health_check_hook(): void {
|
||||
|
||||
@@ -68,6 +68,50 @@ class InstallerCleanupTest extends TestCase {
|
||||
$GLOBALS['_wp_options'] = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Events scheduled with args (tmdo_drift_resync( 'post' ), backfill
|
||||
* batches) are not cleared by wp_clear_scheduled_hook( $hook ); the user
|
||||
* stress hook was misnamed and three hooks were missing (2.4.2 PR-138, F-4).
|
||||
*/
|
||||
private const ARG_AND_MISSED_HOOKS = array( 'tmdo_drift_resync', 'wpdo_entity_backfill_batch', 'wpdo_stress_test_batch', 'wpdo_migration_tick', 'wpdo_auto_promote_check' );
|
||||
|
||||
public function test_deactivate_unschedules_every_hook_whatever_its_args(): void {
|
||||
$GLOBALS['_wp_unscheduled'] = array();
|
||||
|
||||
WPDO_Installer::deactivate();
|
||||
|
||||
foreach ( self::ARG_AND_MISSED_HOOKS as $hook ) {
|
||||
$this->assertContains( $hook, $GLOBALS['_wp_unscheduled'], $hook );
|
||||
}
|
||||
}
|
||||
|
||||
public function test_uninstall_unschedules_every_hook_whatever_its_args(): void {
|
||||
$GLOBALS['_wp_unscheduled'] = array();
|
||||
|
||||
WPDO_Installer::drop_all_tables_for_current_blog();
|
||||
|
||||
foreach ( self::ARG_AND_MISSED_HOOKS as $hook ) {
|
||||
$this->assertContains( $hook, $GLOBALS['_wp_unscheduled'], $hook );
|
||||
}
|
||||
}
|
||||
|
||||
/** tmdo_* options and transients were left behind; a reinstall then saw stale deferrals and indexes (F-5). */
|
||||
public function test_uninstall_removes_tmdo_options_and_transients(): void {
|
||||
global $wpdb;
|
||||
foreach ( array( 'tmdo_schema_deferred', 'tmdo_entity_indexes', '_transient_tmdo_cov_x', '_transient_timeout_tmdo_cov_x', 'hivepress_settings', 'tmdo_latepoint_db_version' ) as $name ) {
|
||||
$wpdb->insert( $wpdb->options, array( 'option_name' => $name, 'option_value' => '1' ) );
|
||||
$GLOBALS['_wp_options'][ $name ] = '1';
|
||||
}
|
||||
|
||||
WPDO_Installer::drop_all_tables_for_current_blog();
|
||||
|
||||
foreach ( array( 'tmdo_schema_deferred', 'tmdo_entity_indexes', '_transient_tmdo_cov_x', '_transient_timeout_tmdo_cov_x' ) as $name ) {
|
||||
$this->assertArrayNotHasKey( $name, $GLOBALS['_wp_options'], $name );
|
||||
}
|
||||
$this->assertArrayHasKey( 'hivepress_settings', $GLOBALS['_wp_options'], 'other plugins untouched' );
|
||||
$this->assertArrayHasKey( 'tmdo_latepoint_db_version', $GLOBALS['_wp_options'], 'the LatePoint add-on owns it' );
|
||||
}
|
||||
|
||||
public function test_drops_static_tables(): void {
|
||||
global $wpdb;
|
||||
|
||||
|
||||
@@ -100,6 +100,55 @@ class PostQueryRouterCopyTest extends TestCase {
|
||||
$this->assertStringEndsWith( 'ORDER BY ' . self::ALIAS . '.`post_date` DESC LIMIT 0, 10', $this->request( '', '' ) );
|
||||
}
|
||||
|
||||
public function test_copy_route_leaves_posts_id_inside_expressions_alone(): void {
|
||||
global $wpdb;
|
||||
$sql = $this->request( '', ', FIELD({posts}.ID,5,9) DESC, ({posts}.ID IN (3,4)) DESC, {posts}.ID DESC' );
|
||||
|
||||
$this->assertStringEndsWith( "`post_date` DESC, FIELD({$wpdb->posts}.ID,5,9) DESC, ({$wpdb->posts}.ID IN (3,4)) DESC, " . self::ALIAS . '.`post_id` DESC LIMIT 0, 10', $sql );
|
||||
}
|
||||
|
||||
/**
|
||||
* The router's query vars are its own: values a caller passed in
|
||||
* (new WP_Query( array( 'wpdo_post_copy_route' => … ) )) are dropped
|
||||
* (2.4 security review L2).
|
||||
*/
|
||||
public function test_query_vars_passed_by_a_caller_are_dropped(): void {
|
||||
$query = new WP_Query();
|
||||
foreach ( array(
|
||||
'post_type' => 'rc_item',
|
||||
'orderby' => 'title',
|
||||
'wpdo_post_copy_route' => array( 'post_type' => 'rc_item', 'group' => 'rc_core', 'statuses' => array( 'publish' ), 'order' => 'DESC, (SELECT 1)' ),
|
||||
'wpdo_post_sort' => array( 'post_type' => 'rc_item', 'group' => 'rc_core', 'column' => 'rc_price', 'order' => 'ASC' ),
|
||||
'wpdo_post_clauses' => array( 'rc_item' => array() ),
|
||||
'wpdo_post_count_sql' => 'SELECT 1',
|
||||
) as $k => $v ) {
|
||||
$query->set( $k, $v );
|
||||
}
|
||||
$router = new TMDO_Post_Query_Router();
|
||||
$router->pre_get_posts( $query );
|
||||
|
||||
foreach ( array( 'wpdo_post_copy_route', 'wpdo_post_sort', 'wpdo_post_clauses', 'wpdo_post_count_sql' ) as $var ) {
|
||||
$this->assertEmpty( $query->get( $var ), $var );
|
||||
}
|
||||
$this->assertSame( 'wp_posts.post_title ASC', $router->posts_orderby( 'wp_posts.post_title ASC', $query ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* wp_insert_post runs after transition_post_status: a new post's empty flat
|
||||
* row must carry the copies itself, or one NULL turns the copy route off for
|
||||
* the whole group (2.4 correctness review).
|
||||
*/
|
||||
public function test_a_new_post_gets_its_flat_row_with_the_copies(): void {
|
||||
global $wpdb;
|
||||
$post = new WP_Post( (object) array( 'ID' => 7, 'post_type' => 'rc_item', 'post_status' => 'draft', 'post_date' => '2026-02-02 00:00:00' ) );
|
||||
$GLOBALS['_wp_posts'][7] = $post;
|
||||
|
||||
( new TMDO_Post_Query_Router() )->add_flat_rows( 7, $post, false );
|
||||
|
||||
$this->assertSame( array( 'post_status' => 'draft', 'post_date' => '2026-02-02 00:00:00' ), $wpdb->get_row( 'SELECT post_status, post_date FROM `' . self::TABLE . '` WHERE post_id = 7', ARRAY_A ) );
|
||||
unset( $GLOBALS['_wp_posts'][7] );
|
||||
}
|
||||
|
||||
public function test_copy_route_keeps_group_by_with_another_join(): void {
|
||||
global $wpdb;
|
||||
$sql = $this->request( " LEFT JOIN wp_term_relationships ON ({$wpdb->posts}.ID = wp_term_relationships.object_id)" );
|
||||
|
||||
@@ -272,6 +272,25 @@ class PostQueryRouterFoundRowsTest extends TestCase {
|
||||
$this->assertSame( array( '2', '3' ), $wpdb->get_col( $sql ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Only standalone posts.ID terms are tie-breaks: inside an expression a
|
||||
* plugin added (pinning posts with FIELD() or IN) the direction must not be
|
||||
* inserted, or the SQL breaks (2.4 correctness review).
|
||||
*/
|
||||
public function test_flat_first_leaves_posts_id_inside_expressions_alone(): void {
|
||||
global $wpdb;
|
||||
list( $router, $query, $request ) = $this->sorted();
|
||||
$pinned = str_replace( ' LIMIT 0, 10', ", FIELD({$wpdb->posts}.ID,3,2) DESC, ({$wpdb->posts}.ID IN (2)) DESC LIMIT 0, 10", $request );
|
||||
|
||||
$sql = $router->posts_request( $pinned, $query );
|
||||
|
||||
$this->assertStringStartsWith( 'SELECT STRAIGHT_JOIN ', $sql );
|
||||
$this->assertStringContainsString( "FIELD({$wpdb->posts}.ID,3,2) DESC, ({$wpdb->posts}.ID IN (2)) DESC LIMIT", $sql );
|
||||
$wpdb->last_error = '';
|
||||
$this->assertSame( $wpdb->get_col( str_replace( 'SQL_CALC_FOUND_ROWS ', '', $pinned ) ), $wpdb->get_col( $sql ) );
|
||||
$this->assertSame( '', $wpdb->last_error );
|
||||
}
|
||||
|
||||
public function test_date_ordered_filtered_request_keeps_wordpress_join_order(): void {
|
||||
list( $router, $query, $request ) = $this->routed();
|
||||
|
||||
|
||||
@@ -471,6 +471,61 @@ class PostQueryRouterTest extends TestCase {
|
||||
$this->assertStringContainsString( 'BETWEEN', $where );
|
||||
}
|
||||
|
||||
/**
|
||||
* WordPress orders by the primary meta clause (meta_key) for meta_value,
|
||||
* meta_value_num or the key's name anywhere in orderby; routing the key and
|
||||
* clearing meta_key would drop that ordering (2.4 correctness review).
|
||||
*/
|
||||
public function test_meta_key_ordered_by_among_several_orderings_stays_native(): void {
|
||||
foreach ( array(
|
||||
array( 'meta_value_num' => 'ASC', 'title' => 'ASC' ),
|
||||
'meta_value date',
|
||||
'_stock',
|
||||
) as $orderby ) {
|
||||
$this->set_post_mode( 'aeav_only' );
|
||||
$query = $this->make_query( array( 'post_type' => 'product', 'meta_key' => '_stock', 'orderby' => $orderby ) );
|
||||
( new WPDO_Post_Query_Router() )->pre_get_posts( $query );
|
||||
|
||||
$label = is_array( $orderby ) ? implode( ',', array_keys( $orderby ) ) : $orderby;
|
||||
$this->assertSame( '_stock', $query->get( 'meta_key' ), $label );
|
||||
$this->assertSame( '', $query->get( 'wpdo_post_clauses' ), $label );
|
||||
}
|
||||
}
|
||||
|
||||
/** meta_compare_key LIKE matches other keys too: not a test on one flat column. */
|
||||
public function test_meta_key_with_a_key_comparison_stays_native(): void {
|
||||
foreach ( array( 'rand', 'meta_value_num' ) as $orderby ) {
|
||||
$this->set_post_mode( 'aeav_only' );
|
||||
$query = $this->make_query( array( 'post_type' => 'product', 'meta_key' => '_stock', 'meta_compare_key' => 'LIKE', 'orderby' => $orderby ) );
|
||||
( new WPDO_Post_Query_Router() )->pre_get_posts( $query );
|
||||
|
||||
$this->assertSame( '_stock', $query->get( 'meta_key' ), $orderby );
|
||||
$this->assertSame( '', $query->get( 'wpdo_post_clauses' ), $orderby );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Without meta_key the first clause is WordPress's primary one: orderby
|
||||
* meta_value_num sorts by the sort group's key, so the group stays.
|
||||
*/
|
||||
public function test_sort_group_ordered_as_the_primary_clause_is_not_dropped(): void {
|
||||
$this->assert_not_routed(
|
||||
array(
|
||||
'post_type' => 'product',
|
||||
'orderby' => 'meta_value_num',
|
||||
'meta_query' => array(
|
||||
array(
|
||||
'relation' => 'OR',
|
||||
'price__order' => array( 'key' => '_price', 'compare' => 'NOT EXISTS', 'type' => 'DECIMAL' ),
|
||||
array( 'key' => '_price', 'compare' => 'EXISTS', 'type' => 'DECIMAL' ),
|
||||
),
|
||||
array( 'key' => '_stock', 'value' => 1, 'compare' => '>=', 'type' => 'NUMERIC' ),
|
||||
),
|
||||
),
|
||||
'primary sort group'
|
||||
);
|
||||
}
|
||||
|
||||
public function test_meta_key_with_a_value_is_left_alone(): void {
|
||||
$this->set_post_mode( 'aeav_only' );
|
||||
$router = new WPDO_Post_Query_Router();
|
||||
|
||||
@@ -132,6 +132,16 @@ class PostStatusSyncTest extends TestCase {
|
||||
$this->assertSame( 2, $report['ps_a']['mismatched'] );
|
||||
}
|
||||
|
||||
/** Routed counts cached while copies were stale are dropped by a sync (2.4 correctness review). */
|
||||
public function test_a_sync_invalidates_cached_routed_counts_but_a_dry_run_does_not(): void {
|
||||
$GLOBALS['_wp_last_changed'][ TMDO_Post_Query_Router::COUNT_VERSION_GROUP ] = 'before';
|
||||
TMDO_Post_Status_Sync::run( true );
|
||||
$this->assertSame( 'before', $GLOBALS['_wp_last_changed'][ TMDO_Post_Query_Router::COUNT_VERSION_GROUP ] );
|
||||
|
||||
TMDO_Post_Status_Sync::run();
|
||||
$this->assertNotSame( 'before', $GLOBALS['_wp_last_changed'][ TMDO_Post_Query_Router::COUNT_VERSION_GROUP ] );
|
||||
}
|
||||
|
||||
public function test_copies_use_the_posts_collation_so_they_compare_with_posts(): void {
|
||||
global $wpdb;
|
||||
TMDO_Post_Status_Sync::run();
|
||||
|
||||
@@ -29,7 +29,8 @@ class ZoneArchiveIntegrationTest extends TestCase {
|
||||
`original_meta_id` bigint(20) unsigned NOT NULL DEFAULT 0,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `post_id` (`post_id`),
|
||||
KEY `archived_at` (`archived_at`)
|
||||
KEY `archived_at` (`archived_at`),
|
||||
KEY `idx_original_meta` (`original_meta_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4'
|
||||
);
|
||||
}
|
||||
@@ -45,6 +46,69 @@ class ZoneArchiveIntegrationTest extends TestCase {
|
||||
$GLOBALS['_wp_postmeta'] = [];
|
||||
}
|
||||
|
||||
// ── sweep / duplicates (2.4.2 PR-136, manual F-6) ─────────────────────
|
||||
|
||||
/** Posts and postmeta for sweep(): post 10 trashed 200 days ago, post 11 published. */
|
||||
private function seed_trashed_post(): void {
|
||||
global $wpdb;
|
||||
$wpdb->query( "DROP TABLE IF EXISTS `{$wpdb->posts}`" );
|
||||
$wpdb->query( "DROP TABLE IF EXISTS `{$wpdb->postmeta}`" );
|
||||
$wpdb->query( "CREATE TABLE `{$wpdb->posts}` ( ID BIGINT UNSIGNED NOT NULL, post_type VARCHAR(20) NOT NULL DEFAULT 'post', post_status VARCHAR(20) NOT NULL DEFAULT 'publish', post_modified_gmt DATETIME NOT NULL DEFAULT '2000-01-01 00:00:00', PRIMARY KEY (ID) ) ENGINE=InnoDB" );
|
||||
$wpdb->query( "CREATE TABLE `{$wpdb->postmeta}` ( meta_id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, post_id BIGINT UNSIGNED NOT NULL DEFAULT 0, meta_key VARCHAR(255) DEFAULT NULL, meta_value LONGTEXT, PRIMARY KEY (meta_id) ) ENGINE=InnoDB" );
|
||||
$old = gmdate( 'Y-m-d H:i:s', time() - 200 * DAY_IN_SECONDS );
|
||||
$wpdb->query( "INSERT INTO `{$wpdb->posts}` VALUES (10, 'hp_listing', 'trash', '{$old}'), (11, 'hp_listing', 'publish', '{$old}')" );
|
||||
$wpdb->query( "INSERT INTO `{$wpdb->postmeta}` (post_id, meta_key, meta_value) VALUES (10, 'hp_price', '5'), (10, 'hp_rating', '4'), (11, 'hp_price', '9')" );
|
||||
}
|
||||
|
||||
private function drop_posts(): void {
|
||||
global $wpdb;
|
||||
$wpdb->query( "DROP TABLE IF EXISTS `{$wpdb->posts}`" );
|
||||
$wpdb->query( "DROP TABLE IF EXISTS `{$wpdb->postmeta}`" );
|
||||
}
|
||||
|
||||
private function archive_rows(): int {
|
||||
global $wpdb;
|
||||
return (int) $wpdb->get_var( 'SELECT COUNT(*) FROM `' . self::TABLE . '`' );
|
||||
}
|
||||
|
||||
public function test_sweep_copies_each_trashed_meta_row_once(): void {
|
||||
$this->seed_trashed_post();
|
||||
try {
|
||||
$this->assertSame( 2, WPDO_Zone_Archive::sweep( 90, false ) );
|
||||
$this->assertSame( 0, WPDO_Zone_Archive::sweep( 90, false ), 'already archived' );
|
||||
$this->assertSame( 2, $this->archive_rows() );
|
||||
} finally {
|
||||
$this->drop_posts();
|
||||
}
|
||||
}
|
||||
|
||||
/** Until `wp tmdo install` adds the index, NOT EXISTS would scan the archive per candidate. */
|
||||
public function test_sweep_waits_for_the_original_meta_index(): void {
|
||||
global $wpdb;
|
||||
$this->seed_trashed_post();
|
||||
$wpdb->query( 'ALTER TABLE `' . self::TABLE . '` DROP INDEX `idx_original_meta`' );
|
||||
try {
|
||||
$this->assertSame( 0, WPDO_Zone_Archive::sweep( 90, false ) );
|
||||
$this->assertSame( 0, $this->archive_rows() );
|
||||
} finally {
|
||||
$wpdb->query( 'ALTER TABLE `' . self::TABLE . '` ADD KEY `idx_original_meta` (`original_meta_id`)' );
|
||||
$this->drop_posts();
|
||||
}
|
||||
}
|
||||
|
||||
public function test_remove_duplicates_keeps_the_first_copy_of_each_meta_row(): void {
|
||||
WPDO_Zone_Archive::archive( 10, 'hp_listing', 'hp_price', '5', 101 );
|
||||
WPDO_Zone_Archive::archive( 10, 'hp_listing', 'hp_price', '5', 101 );
|
||||
WPDO_Zone_Archive::archive( 10, 'hp_listing', 'hp_rating', '4', 102 );
|
||||
WPDO_Zone_Archive::archive( 10, 'hp_listing', 'hp_rating', '4', 102 );
|
||||
WPDO_Zone_Archive::archive( 12, 'hp_listing', 'hp_price', '7' ); // original_meta_id 0: no identity, kept.
|
||||
WPDO_Zone_Archive::archive( 12, 'hp_listing', 'hp_price', '7' );
|
||||
|
||||
$this->assertSame( 2, WPDO_Zone_Archive::remove_duplicates() );
|
||||
$this->assertSame( 4, $this->archive_rows() );
|
||||
$this->assertSame( 0, WPDO_Zone_Archive::remove_duplicates() );
|
||||
}
|
||||
|
||||
// ── archive / get ─────────────────────────────────────────────────────
|
||||
|
||||
public function test_archive_stores_plain_entry(): void {
|
||||
|
||||
@@ -315,6 +315,7 @@ if ( ! function_exists( 'get_metadata' ) ) {
|
||||
if ( ! function_exists( 'wp_next_scheduled' ) ) { function wp_next_scheduled( string $hook ): int|false { return false; } }
|
||||
if ( ! function_exists( 'wp_schedule_event' ) ) { function wp_schedule_event( int $t, string $r, string $h ): bool { return true; } }
|
||||
if ( ! function_exists( 'wp_schedule_single_event' ) ) { function wp_schedule_single_event( int $ts, string $hook ): bool { $GLOBALS['_wp_scheduled_single'][] = $hook; return true; } }
|
||||
if ( ! function_exists( 'wp_unschedule_hook' ) ) { function wp_unschedule_hook( string $hook ): int|false { $GLOBALS['_wp_unscheduled'][] = $hook; return 0; } }
|
||||
if ( ! function_exists( 'wp_clear_scheduled_hook' ) ) { function wp_clear_scheduled_hook( string $hook ): int|false { return 0; } }
|
||||
if ( ! function_exists( 'sanitize_text_field' ) ) { function sanitize_text_field( string $s ): string { return trim( strip_tags( $s ) ); } }
|
||||
if ( ! function_exists( '__' ) ) { function __( string $text, string $domain = 'default' ): string { return $text; } }
|
||||
@@ -354,6 +355,19 @@ if ( ! function_exists( 'get_term_meta' ) ) { function get_term_meta( int $tid,
|
||||
if ( ! function_exists( 'update_term_meta' ) ) { function update_term_meta( int $tid, string $key, $value, $prev = '' ): bool { $GLOBALS['_wp_termmeta'][ $tid ][ $key ] = $value; return true; } }
|
||||
if ( ! function_exists( 'get_comment_meta' ) ) { function get_comment_meta( int $cid, string $key = '', bool $single = false ) { return $GLOBALS['_wp_commentmeta'][ $cid ][ $key ] ?? ( $single ? '' : [] ); } }
|
||||
if ( ! function_exists( 'update_comment_meta' ) ) { function update_comment_meta( int $cid, string $key, $value, $prev = '' ): bool { $GLOBALS['_wp_commentmeta'][ $cid ][ $key ] = $value; return true; } }
|
||||
if ( ! class_exists( 'WP_Post' ) ) {
|
||||
final class WP_Post {
|
||||
public $ID = 0;
|
||||
public $post_type = 'post';
|
||||
public $post_status = 'publish';
|
||||
public $post_date = '0000-00-00 00:00:00';
|
||||
public function __construct( $post ) {
|
||||
foreach ( get_object_vars( $post ) as $k => $v ) {
|
||||
$this->$k = $v;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( ! function_exists( 'get_post' ) ) { function get_post( $post_id ) { return $GLOBALS['_wp_posts'][ (int) $post_id ] ?? null; } }
|
||||
if ( ! function_exists( 'get_post_type' ) ) { function get_post_type( $post_id ) { return $GLOBALS['_wp_post_types'][ (int) $post_id ] ?? false; } }
|
||||
if ( ! function_exists( 'get_post_status' ) ) { function get_post_status( $post_id ) { return $GLOBALS['_wp_post_status'][ (int) $post_id ] ?? 'publish'; } }
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* The admin settings form saves bridge modes through TMDO_Mode_Manager::set().
|
||||
* A refused change (unsafe jump, Promotion Guard) used to be dropped silently:
|
||||
* the page said "saved" while the mode stayed put (2.4.2 PR-135, manual F-2).
|
||||
*/
|
||||
class AdminBridgeModeSaveTest extends TestCase {
|
||||
|
||||
public static function setUpBeforeClass(): void {
|
||||
require_once TMDO_PATH . 'admin/class-tmdo-admin.php';
|
||||
}
|
||||
|
||||
protected function setUp(): void {
|
||||
ini_set( 'error_log', '/dev/null' );
|
||||
$GLOBALS['_wp_options'] = array();
|
||||
$GLOBALS['_wp_filter_callbacks'] = array();
|
||||
$GLOBALS['_wp_current_user_can'] = array( 'manage_options' => true );
|
||||
$GLOBALS['_wp_current_user_id'] = 7;
|
||||
TMDO_Mode_Manager::reset_cache();
|
||||
}
|
||||
|
||||
private function modes( array $modes ): void {
|
||||
$GLOBALS['_wp_options']['wpdo_bridge_modes'] = $modes;
|
||||
TMDO_Mode_Manager::reset_cache();
|
||||
}
|
||||
|
||||
public function test_an_accepted_change_is_applied_without_refusals(): void {
|
||||
$this->modes( array( 'user' => 'disabled' ) );
|
||||
|
||||
$refused = TMDO_Admin::apply_bridge_modes( array( 'user' => 'dual_write' ) );
|
||||
|
||||
$this->assertSame( array(), $refused );
|
||||
$this->assertSame( 'dual_write', TMDO_Mode_Manager::get( 'user' ) );
|
||||
}
|
||||
|
||||
public function test_an_unsafe_jump_is_reported_and_the_mode_kept(): void {
|
||||
$this->modes( array( 'post' => 'disabled' ) );
|
||||
|
||||
$refused = TMDO_Admin::apply_bridge_modes( array( 'post' => 'shadow_read' ) );
|
||||
|
||||
$this->assertCount( 1, $refused );
|
||||
$this->assertStringStartsWith( 'post', $refused[0] );
|
||||
$this->assertSame( 'disabled', TMDO_Mode_Manager::get( 'post' ) );
|
||||
}
|
||||
|
||||
public function test_empty_or_unknown_modes_are_ignored(): void {
|
||||
$this->modes( array( 'term' => 'disabled' ) );
|
||||
|
||||
$this->assertSame( array(), TMDO_Admin::apply_bridge_modes( array( 'post' => '', 'term' => 'bogus' ) ) );
|
||||
$this->assertSame( 'disabled', TMDO_Mode_Manager::get( 'term' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
public function test_a_promotion_refused_by_the_guard_is_reported(): void {
|
||||
eval( 'namespace HivePress; class Core {}' );
|
||||
$this->modes( array( 'user' => 'shadow_read' ) );
|
||||
|
||||
$refused = TMDO_Admin::apply_bridge_modes( array( 'user' => 'aeav_only' ) );
|
||||
|
||||
$this->assertCount( 1, $refused );
|
||||
$this->assertSame( 'shadow_read', TMDO_Mode_Manager::get( 'user' ) );
|
||||
}
|
||||
|
||||
/** The full-page form redirects after saving: refusals wait in a per-user transient, shown once. */
|
||||
public function test_refusals_are_kept_for_the_next_page_view_only(): void {
|
||||
TMDO_Admin::remember_bridge_mode_refusals( array( 'post:refused' ) );
|
||||
|
||||
$this->assertSame( array( 'post:refused' ), TMDO_Admin::pull_bridge_mode_refusals() );
|
||||
$this->assertSame( array(), TMDO_Admin::pull_bridge_mode_refusals() );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Backfill batches are scheduled per (entity, group) — REST backfill and
|
||||
* TMDO_Core re-chain `wpdo_entity_backfill_batch` with both args. The health
|
||||
* panel looked for (entity) alone, never found a running backfill and kept
|
||||
* offering to start one; starting one resets the group's checkpoint
|
||||
* (2.4.2 PR-137, manual F-11).
|
||||
*/
|
||||
class EntityHealthBackfillTest extends TestCase {
|
||||
|
||||
protected function setUp(): void {
|
||||
$GLOBALS['_wp_next_scheduled'] = array();
|
||||
TMDO_Entity_Registry::init();
|
||||
TMDO_Entity_Registry::register_adapter( 'user', new TMDO_Adapter_User() );
|
||||
TMDO_Entity_Registry::register_group( 'user', 'eh_one', array( array( 'key' => 'eh_a', 'type' => 'text' ) ) );
|
||||
TMDO_Entity_Registry::register_group( 'user', 'eh_two', array( array( 'key' => 'eh_b', 'type' => 'text' ) ) );
|
||||
}
|
||||
|
||||
protected function tearDown(): void {
|
||||
$GLOBALS['_wp_next_scheduled'] = array();
|
||||
TMDO_Entity_Registry::init();
|
||||
}
|
||||
|
||||
private function backfill_active( string $entity_type ): bool {
|
||||
$m = new ReflectionMethod( TMDO_Entity_Health::class, 'is_backfill_active' );
|
||||
$m->setAccessible( true );
|
||||
return (bool) $m->invoke( null, $entity_type );
|
||||
}
|
||||
|
||||
public function test_a_backfill_scheduled_for_one_group_is_seen(): void {
|
||||
$GLOBALS['_wp_next_scheduled']['wpdo_entity_backfill_batch'][ md5( serialize( array( 'user', 'eh_two' ) ) ) ] = time() + 5;
|
||||
|
||||
$this->assertTrue( $this->backfill_active( 'user' ) );
|
||||
$this->assertFalse( $this->backfill_active( 'post' ), 'other entities are not affected' );
|
||||
}
|
||||
|
||||
public function test_no_scheduled_batch_means_no_backfill(): void {
|
||||
$this->assertFalse( $this->backfill_active( 'user' ) );
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -94,7 +94,7 @@ if ( $wpdo_blocked ) {
|
||||
wp_die(
|
||||
'<p>' . esc_html( '2meet Data Optimizer 已停止解除安裝:以下資料只存在 wpdo_* 表,刪除外掛會一併刪除這些表。' ) . '</p>'
|
||||
. '<ul><li>' . implode( '</li><li>', array_map( 'esc_html', $wpdo_blocked ) ) . '</li></ul>'
|
||||
. '<p>' . esc_html( '目前沒有把這些資料寫回 WordPress 原生表的自動工具。若只想移除外掛程式,可手動刪除外掛目錄,資料表會保留。' ) . '</p>'
|
||||
. '<p>' . esc_html( '請先以 wp tmdo bridge-restore-native 把資料寫回 WordPress 原生表,再解除安裝。若只想移除外掛程式,可手動刪除外掛目錄,資料表會保留。' ) . '</p>'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user