Skip to content

Commit

Permalink
Make sure survey is sent AFTER event has completed. (#1069)
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenDufresne authored Sep 27, 2023
1 parent 0f1c5fe commit 0705d22
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,19 +118,20 @@ function is_time_to_send_email( $email_id ) {
return false;
}

if ( 'wcpt-closed' !== $wordcamp_post->post_status ) {
return false;
}

$end_date = $wordcamp_post->meta['End Date (YYYY-mm-dd)'][0];

if ( ! isset( $end_date ) ) {
if ( empty( $end_date ) ) {
log( 'WordCamp missing end date', $email_id, $wordcamp_post );
return false;
}

$date = new \DateTime("@$end_date ");
$current_date = new \DateTime();
$interval = $current_date->diff($date);
$days_difference = $interval->days;
$send_date = $end_date + ( DAYS_AFTER_TO_SEND * DAY_IN_SECONDS );

return DAYS_AFTER_TO_SEND === $days_difference;
return gmdate( 'Y-m-d', $send_date ) === current_time( 'Y-m-d', true );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,20 @@ function is_time_to_send_email( $email_id ) {
return false;
}

if ( 'wcpt-closed' !== $wordcamp_post->post_status ) {
return false;
}

$end_date = $wordcamp_post->meta['End Date (YYYY-mm-dd)'][0];

if ( empty( $end_date ) ) {
// Some sites that are only 1-day events will only have the start date.
$end_date = $wordcamp_post->meta['Start Date (YYYY-mm-dd)'][0];
}

$date = new \DateTime("@$end_date ");
$current_date = new \DateTime();
$interval = $current_date->diff($date);
$days_difference = $interval->days;
$send_date = $end_date + ( DAYS_AFTER_TO_SEND * DAY_IN_SECONDS );

return DAYS_AFTER_TO_SEND === $days_difference;
return gmdate( 'Y-m-d', $send_date ) === current_time( 'Y-m-d', true );
}

/**
Expand Down

0 comments on commit 0705d22

Please sign in to comment.