fix(2meet-data-optimizer): default misc bucket and garbage filter to off

- Both term/comment filters now default to disabled for new installs, so
  activating the plugin no longer reroutes or drops other plugins' meta
- One-time maybe_upgrade() migration keeps the misc bucket on for sites
  that already hold misc rows and never set the toggle (data stays readable)
- Admin toggles show the same defaults as the filters

Verify: phpunit-integration --filter 'defaults_false|preserve_default';
  unit 600 OK, integration 420 OK
PR: PR-006
This commit is contained in:
2026-09-25 21:39:38 +08:00
parent d3b72bd1af
commit 151aadd661
6 changed files with 89 additions and 9 deletions
+31
View File
@@ -40,6 +40,9 @@ class TMDO_Installer {
*/
private const SCHEMA_VERSION = '2.1.0';
/** Set once maybe_preserve_misc_bucket_default() has run for this site. */
public const MISC_BUCKET_DEFAULT_FLAG = 'wpdo_misc_bucket_default_v2';
/** Allowed SQL base types for hot-zone column definitions. */
private const ALLOWED_COL_BASE_TYPES = array(
'bigint',
@@ -299,6 +302,34 @@ class TMDO_Installer {
if ( get_option( 'wpdo_db_version' ) !== self::SCHEMA_VERSION ) {
self::install();
}
self::maybe_preserve_misc_bucket_default();
}
/**
* One-time migration for the misc bucket default flip (on → off).
*
* The bucket used to default to enabled; its rows are only readable while it
* is on. Sites that already hold misc rows and never set the toggle get '1'
* persisted so turning the default off cannot hide their data. Runs from
* maybe_upgrade() rather than install() because install() only runs when
* SCHEMA_VERSION changes; the flag is autoloaded since it is read per request.
*
* @return void
*/
public static function maybe_preserve_misc_bucket_default(): void {
if ( get_option( self::MISC_BUCKET_DEFAULT_FLAG ) || ! class_exists( 'TMDO_Term_Comment_Misc_Bucket' ) ) {
return;
}
$unset = false === get_option( TMDO_Term_Comment_Misc_Bucket::OPT_ENABLED );
$has_rows = TMDO_Term_Comment_Misc_Bucket::count_rows( 'term' ) > 0
|| TMDO_Term_Comment_Misc_Bucket::count_rows( 'comment' ) > 0;
if ( $unset && $has_rows ) {
update_option( TMDO_Term_Comment_Misc_Bucket::OPT_ENABLED, '1', false );
}
update_option( self::MISC_BUCKET_DEFAULT_FLAG, '1', true );
}
// ── v2.0.0 entity + audit + shadow_diffs schema (PR-2) ─────────────────
@@ -109,12 +109,12 @@ final class TMDO_Term_Comment_Garbage_Filter {
}
/**
* Check the admin toggle. Defaults to enabled.
* Check the admin toggle. Defaults to disabled.
*
* @return bool
*/
public static function is_enabled(): bool {
return (bool) get_option( self::OPT_ENABLED, '1' );
return (bool) get_option( self::OPT_ENABLED, '0' );
}
/**
@@ -95,12 +95,13 @@ final class TMDO_Term_Comment_Misc_Bucket {
}
/**
* Check the admin toggle. Defaults to enabled.
* Check the admin toggle. Defaults to disabled; sites that already hold misc
* rows keep it on via TMDO_Installer::maybe_preserve_misc_bucket_default().
*
* @return bool
*/
public static function is_enabled(): bool {
return (bool) get_option( self::OPT_ENABLED, '1' );
return (bool) get_option( self::OPT_ENABLED, '0' );
}
/**