Files
2meet-data-optimizer/tests/live/suites/zero_side_effect.php
T
wpdev 781f171770 fix(2meet-data-optimizer): skip zone deletes on tables that were never created
- TMDO_Zone_Router::delete_post() deleted from wp_wpdo_hot_/cold_{post_type}
  whenever fields were registered for that zone, so every post delete on a
  HivePress site (cold fields registered, module idle, table never created)
  logged a "table doesn't exist" error. Hot and cold deletes now also need
  the table to exist; module state is not checked, so a table left by a
  rolled-back module still loses the rows of deleted posts.
- Live suite zero_side_effect: saving / updating / deleting an hp_listing
  issues no query on missing zone tables (covers PR-054 and this PR).
- Verify: ZoneRouterTest 22 OK; live zero_side_effect + shadow_write +
  serialized 9/9 PASS (old code: zero_side_effect FAIL); unit 687 OK,
  integration 484 OK, phpcs (phpcs.xml) 0, stan OK
- PR: PR-054b
2026-09-26 19:02:10 +08:00

47 lines
1.4 KiB
PHP

<?php
/**
* Suite: zone tables that were never created are never queried.
*
* Bug (dev36, 2026-09-26): the HivePress AddOn registers cold fields, so every
* save_post / loop_start (PR-054) and every post delete (PR-054b) queried
* wp_wpdo_cold_{post_type} although the cold module was idle and the table
* did not exist ("table doesn't exist" DB errors on each write).
*
* @package WP_Data_Optimizer
*/
declare(strict_types=1);
TMDO_Live::test(
'saving and deleting an hp_listing does not touch missing zone tables',
static function () {
global $wpdb;
$tables = array( TMDO_Zone_Cold::table( 'hp_listing' ), TMDO_Zone_Hot::table( 'hp_listing' ) );
foreach ( $tables as $table ) {
if ( TMDO_Schema_Manager::table_exists( $table ) ) {
throw new TMDO_Live_Skip( "{$table} exists on this site" );
}
}
$touched = array();
$spy = static function ( $sql ) use ( $tables, &$touched ) {
foreach ( $tables as $table ) {
if ( false !== strpos( $sql, $table ) && 0 !== stripos( ltrim( $sql ), 'SHOW TABLES' ) ) {
$touched[] = $sql;
}
}
return $sql;
};
add_filter( 'query', $spy );
try {
$id = TMDO_Live_Fixtures::post( 'hp_listing' );
wp_update_post( array( 'ID' => $id, 'post_title' => 'tmdo-live-updated' ) );
wp_delete_post( $id, true );
} finally {
remove_filter( 'query', $spy );
}
tmdo_live_assert_same( array(), $touched, 'queries on missing zone tables' );
}
);