Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,14 @@ private function get_file_url(
(int) $event_id,
$endpoint,
array(
'type' => 'download',
'event_id' => (int) $event_id,
'person_id' => $person_id,
'post_id' => $post_id,
'post_type' => $post_type,
'policy' => PolicyResolver::resolve( $post_id ),
'created_at' => current_time( 'mysql' ),
'type' => 'download',
'event_id' => (int) $event_id,
'person_id' => $person_id,
'post_id' => $post_id,
'post_type' => $post_type,
'airtable_record_id' => get_post_meta( $post_id, '_airtable_record_id', true ) ?: null,
'policy' => PolicyResolver::resolve( $post_id ),
'created_at' => current_time( 'mysql' ),
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,34 @@ public static function log( array $data ): int|false {

return $wpdb->insert_id;
}

/**
* Return the ID of the most recent redirect event for a person + post.
*
* Used by IntakeController to include the download event ID in the intake
* webhook payload so Make.com can update the correct Downloads record.
*
* @param int $person_id Person ID from wp_gateway_people.
* @param int $post_id Post ID of the downloaded resource.
* @return int|null Row ID, or null if no matching redirect event found.
*/
public static function find_redirect_id( int $person_id, int $post_id ): ?int {
global $wpdb;

$id = $wpdb->get_var(
$wpdb->prepare(
"SELECT id FROM {$wpdb->prefix}gateway_download_events
WHERE person_id = %d
AND post_id = %d
AND event_type = %s
ORDER BY created_at DESC
LIMIT 1",
$person_id,
$post_id,
self::EVENT_REDIRECT
)
);

return null !== $id ? (int) $id : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,15 @@ public function submit( int $post_id, string $person_cookie, string $nonce, arra
(int) $intake_id,
$endpoint,
array(
'type' => 'intake',
'person_id' => $person_id,
'post_id' => $post_id,
'post_type' => $post_type,
'intake_set' => $intake_set,
'responses' => $sanitized,
'created_at' => current_time( 'mysql' ),
'type' => 'intake',
'person_id' => $person_id,
'download_event_id' => DownloadEventRepository::find_redirect_id( $person_id, $post_id ),
'post_id' => $post_id,
'post_type' => $post_type,
'airtable_record_id' => get_post_meta( $post_id, '_airtable_record_id', true ) ?: null,
'intake_set' => $intake_set,
'responses' => $sanitized,
'created_at' => current_time( 'mysql' ),
)
);
}
Expand Down
Loading