Files
wp-donations/includes/Actions/Recorder.php
T
shadowdaoandClaude Sonnet 5.5 353f7ca5be
Test and Release / test (push) Successful in 1m28s
Test and Release / release (push) Successful in 7s
Hold donations with flagged donor names for moderation; reconcile lost side effects (schema v6)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-15 17:07:32 -08:00

33 lines
1.1 KiB
PHP

<?php
declare( strict_types=1 );
namespace StreamGoals\Actions;
/** Queues the on-stream actions a completed donation triggers. */
final class Recorder {
/**
* Never throws. Idempotent: replays are ignored by the UNIQUE key on sg_action_events.
*
* @return bool False only when something failed (so the caller must not mark the donation's effects as applied).
*/
public static function forDonation( int $donationId ): bool {
try {
global $wpdb;
$row = $wpdb->get_row( $wpdb->prepare( 'SELECT id, goal_id, base_minor, status FROM ' . $wpdb->prefix . 'sg_donations WHERE id = %d', $donationId ), ARRAY_A );
if ( ! is_array( $row ) || 'completed' !== ( $row['status'] ?? '' ) ) {
return true;
}
$repo = new ActionRepository( $wpdb );
$matches = Matcher::match( (int) $row['base_minor'], $repo->enabledForGoal( (int) $row['goal_id'] ) );
if ( $matches ) {
$repo->recordEvents( $donationId, $matches );
}
return true;
} catch ( \Throwable $e ) {
error_log( 'StreamGoals: Recorder failed for donation ' . $donationId . ': ' . $e->getMessage() ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions
return false;
}
}
}