Hold donations with flagged donor names for moderation; reconcile lost side effects (schema v6)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
473fe192cd
commit
353f7ca5be
16 files changed
+681
-41
No files matched your search
@@ -6,21 +6,27 @@ 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. */
|
||||
public static function forDonation( int $donationId ): void {
|
||||
/**
|
||||
* 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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user