Files
prautoblogger/uninstall.php
peptiderepo aaf1b4274e feat(M3): edit+rerun schema substrate — stage_inputs store, stale/human_modified columns, db 1.3.0
- Pipeline_Schema_Installer: run_stages gains human_modified + stale
  (stale is a COLUMN not a status: rows stay 'done' so resume code can
  never silently re-run them — CPO guardrail 3 by construction);
  run_decisions gains human_modified; new INSERT-only stage_inputs table
  (edit forks as immutable versions + idea seeds for re-run-from-here).
  All dbDelta-idempotent; PRAUTOBLOGGER_DB_VERSION 1.1.0 -> 1.3.0 (the
  constant never carried the documented 1.2.0) so the existing
  admin_init/cron self-healing migration path fires everywhere.
- Run_Stage_State split (M2 pattern, was 313 lines): pipeline write
  bodies moved verbatim to Run_Stage_Writes (public API unchanged via
  thin proxies); done() now clears stale on fresh output with a
  half-migrated-schema retry (Cost_Tracker v0.18.0 pattern); new
  item-scoped read stages_for_item(). Operator-action mutations
  (restart/mark_stale/demote_to_pending) isolated in
  Run_Stage_Rerun_State — the only code allowed to demote a done row.
- Audit_Writer::flag_decisions_human_modified() (guardrail 2 on
  run_decisions). Run_Reaper retention prunes human fork bodies (seeds
  kept). Uninstall covers the new table + rerun cron hooks.

Agent-Session: engineer-prab-m3-20260612
2026-06-12 14:28:10 +00:00

105 lines
3.1 KiB
PHP

<?php
/**
* phpcs:ignore Generic.PHP.RequireStrictTypes.MissingDeclaration -- strict_types must precede docblock
*
* Fired when the plugin is uninstalled (deleted) from WordPress.
*
* Removes ALL plugin data: custom tables, options, post meta, transients, and cron events.
* This is the nuclear option — only runs when the user explicitly deletes the plugin.
*
* @see class-deactivator.php — Lighter cleanup on deactivation (preserves data).
*/
declare(strict_types=1);
// Abort if not called by WordPress uninstall process.
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit;
}
global $wpdb;
/*
|--------------------------------------------------------------------------
| 1. Drop Custom Tables
|--------------------------------------------------------------------------
*/
$prefix = $wpdb->prefix . 'prautoblogger_';
$tables = array(
$prefix . 'source_data',
$prefix . 'analysis_results',
$prefix . 'generation_log',
$prefix . 'content_scores',
$prefix . 'event_log',
// Pipeline v2 substrate (v0.18.0 / db 1.2.0).
$prefix . 'prompts',
$prefix . 'run_sources',
$prefix . 'run_decisions',
$prefix . 'runs',
$prefix . 'run_stages',
// Edit + re-run input versions (v0.20.0 / db 1.3.0).
$prefix . 'stage_inputs',
);
foreach ( $tables as $table ) {
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Table names are hardcoded above, not user input.
$wpdb->query( "DROP TABLE IF EXISTS {$table}" );
}
/*
|--------------------------------------------------------------------------
| 2. Delete All Plugin Options
|--------------------------------------------------------------------------
*/
$options = $wpdb->get_col(
"SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE 'prautoblogger\_%'"
);
foreach ( $options as $option ) {
delete_option( $option );
}
/*
|--------------------------------------------------------------------------
| 3. Delete All Plugin Post Meta
|--------------------------------------------------------------------------
*/
$wpdb->query(
"DELETE FROM {$wpdb->postmeta} WHERE meta_key LIKE '\\_prautoblogger\\_%'"
);
/*
|--------------------------------------------------------------------------
| 4. Delete All Plugin Transients
|--------------------------------------------------------------------------
*/
$wpdb->query(
"DELETE FROM {$wpdb->options} WHERE option_name LIKE '\\_transient\\_prautoblogger\\_%' OR option_name LIKE '\\_transient\\_timeout\\_prautoblogger\\_%'"
);
/*
|--------------------------------------------------------------------------
| 5. Clear Any Remaining Cron Events
|--------------------------------------------------------------------------
*/
$hooks = array(
'prautoblogger_daily_generation',
'prautoblogger_collect_metrics',
'prautoblogger_reap_orphan_research_rows',
'prautoblogger_sync_runware_models',
'prautoblogger_manual_generation',
'prautoblogger_generate_queued_article',
'prautoblogger_generate_from_idea',
'prautoblogger_opik_dispatch',
'prautoblogger_rerun_stage_replay',
'prautoblogger_rerun_from_stage',
);
foreach ( $hooks as $hook ) {
wp_clear_scheduled_hook( $hook );
}