Hold donations with flagged donor names for moderation; reconcile lost side effects (schema v6)
Test and Release / test (push) Successful in 1m28s
Test and Release / release (push) Successful in 7s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
shadowdaoandClaude Sonnet 5.5 committed 2026-11-15 17:07:32 -08:00
1 parent 473fe192cd
commit 353f7ca5be
16 files changed
+681 -41

No files matched your search

+33 -5
View File
@@ -8,10 +8,10 @@ namespace StreamGoals\Core;
*/
final class Installer {
public const DB_VERSION = '5';
public const DB_VERSION = '6';
public static function activate(): void {
self::install_schema();
self::install_schema( get_option( 'sg_db_version' ) );
if ( false === get_option( 'sg_settings' ) ) {
add_option( 'sg_settings', Settings::defaults(), '', false );
}
@@ -20,12 +20,33 @@ final class Installer {
/** Run on plugins_loaded so upgrades apply without re-activation. */
public static function maybe_upgrade(): void {
if ( get_option( 'sg_db_version' ) !== self::DB_VERSION ) {
self::install_schema();
$from = get_option( 'sg_db_version' );
if ( $from !== self::DB_VERSION ) {
self::install_schema( $from );
}
}
private static function install_schema(): void {
/** Schema v6 added sg_donations.effects_applied_at; rows completed before that must not be replayed. */
public static function needsEffectsBackfill( mixed $from ): bool {
return false === $from || '' === $from || version_compare( (string) $from, '6', '<' );
}
/**
* One-time upgrade step: every donation that is ALREADY completed had its side effects applied by the code that
* completed it (or was lost before this feature existed and is not worth replaying), so stamp it. Without this the
* reconciler would replay the whole history. Only touches NULL rows, so re-running is harmless. False on DB error.
*/
public static function backfill_effects_applied(): bool {
global $wpdb;
$n = $wpdb->query( $wpdb->prepare(
'UPDATE ' . $wpdb->prefix . "sg_donations SET effects_applied_at = %s WHERE status = 'completed' AND effects_applied_at IS NULL",
gmdate( 'Y-m-d H:i:s' )
) );
return false !== $n;
}
/** @param mixed $from Previously installed sg_db_version (false when never installed). */
private static function install_schema( mixed $from = false ): void {
global $wpdb;
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
$c = $wpdb->get_charset_collate();
@@ -59,6 +80,8 @@ final class Installer {
message VARCHAR(500) NOT NULL DEFAULT '',
status VARCHAR(12) NOT NULL DEFAULT 'pending',
moderation VARCHAR(10) NOT NULL DEFAULT 'approved',
moderation_flags VARCHAR(16) NOT NULL DEFAULT '',
effects_applied_at DATETIME NULL,
created_at DATETIME NOT NULL,
PRIMARY KEY (id),
UNIQUE KEY capture (paypal_capture_id),
@@ -159,6 +182,11 @@ final class Installer {
KEY reached_donation (reached_donation_id)
) $c;" );
// Backfill BEFORE recording the new version: if it fails, the next load retries instead of replaying history.
if ( self::needsEffectsBackfill( $from ) && ! self::backfill_effects_applied() ) {
return;
}
update_option( 'sg_db_version', self::DB_VERSION );
}
}