From 0705d220013d159acc8a21c4946e27f5f305c33f Mon Sep 17 00:00:00 2001 From: Steven Dufresne Date: Wed, 27 Sep 2023 09:31:07 +0900 Subject: [PATCH] Make sure survey is sent AFTER event has completed. (#1069) --- .../camptix-attendee-survey/includes/cron.php | 13 +++++++------ .../includes/debrief-survey/cron.php | 11 ++++++----- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/public_html/wp-content/plugins/camptix-attendee-survey/includes/cron.php b/public_html/wp-content/plugins/camptix-attendee-survey/includes/cron.php index aef4838fe..54c87ef93 100644 --- a/public_html/wp-content/plugins/camptix-attendee-survey/includes/cron.php +++ b/public_html/wp-content/plugins/camptix-attendee-survey/includes/cron.php @@ -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 ); } /** diff --git a/public_html/wp-content/plugins/wordcamp-organizer-survey/includes/debrief-survey/cron.php b/public_html/wp-content/plugins/wordcamp-organizer-survey/includes/debrief-survey/cron.php index 49e95db9f..5eddcaf88 100644 --- a/public_html/wp-content/plugins/wordcamp-organizer-survey/includes/debrief-survey/cron.php +++ b/public_html/wp-content/plugins/wordcamp-organizer-survey/includes/debrief-survey/cron.php @@ -124,6 +124,10 @@ 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 ) ) { @@ -131,12 +135,9 @@ function is_time_to_send_email( $email_id ) { $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 ); } /**