From 1775c86c25a52d6491e41d4fe4ad202051695e93 Mon Sep 17 00:00:00 2001 From: asus Date: Tue, 9 Apr 2024 23:05:11 +0200 Subject: [PATCH] adde event expire card reminder --- plugins/cipf_plugin/cipf_plugin.php | 14 +++++- .../php/_actions_scheduled_events.php | 43 +++++++++++-------- plugins/cipf_plugin/php/_utils_acf_dates.php | 6 +-- .../php/paypal/update_user_payment.php | 1 + 4 files changed, 41 insertions(+), 23 deletions(-) diff --git a/plugins/cipf_plugin/cipf_plugin.php b/plugins/cipf_plugin/cipf_plugin.php index 3318f0b..cae0fa1 100644 --- a/plugins/cipf_plugin/cipf_plugin.php +++ b/plugins/cipf_plugin/cipf_plugin.php @@ -216,7 +216,7 @@ contactez la fipf directement", 'confirmation_subject'=>"[CIPF - paiement changement carte réussi]", 'confirmation_message'=>"paiement changement carte réussi", ], - 'account_will_expire'=>[ + 'card_will_expire'=>[ 'name'=>'prof - la carte va bientot expirer', 'notification_send'=>true, 'notification_to'=>'$$__admin_email__$$', @@ -226,7 +226,7 @@ contactez la fipf directement", 'confirmation_subject'=>"[CIPF - carte va expirer]", 'confirmation_message'=>'votre carte va expirer bientot, renouvellez-la sur $$__base_url__$$', ], - 'account_expired'=>[ + 'card_expired'=>[ 'name'=>'prof - la carte a expiré', 'notification_send'=>true, 'notification_to'=>'$$__admin_email__$$', @@ -236,6 +236,16 @@ contactez la fipf directement", 'confirmation_subject'=>"[CIPF - carte expirée]", 'confirmation_message'=>'votre carte a expiré, renouvelez-la sur $$__base_url__$$', ], + 'account_will_be_deleted'=>[ + 'name'=>'prof - le compte va être supprimé', + 'notification_send'=>true, + 'notification_to'=>'$$__admin_email__$$', + 'notification_subject'=>"[CIPF /prof - compte bientot supprimé]", + 'notification_message'=>'compte bientot supprimé pour $$user_login$$ : $$__author_page_url__$$', + 'confirmation_send'=>true, + 'confirmation_subject'=>"[CIPF - compte bientot supprimé]", + 'confirmation_message'=>'votre compte va bientot être supprimé sur $$__base_url__$$', + ], 'account_deleted'=>[ 'name'=>'prof - le compte a été supprimé', 'notification_send'=>true, diff --git a/plugins/cipf_plugin/php/_actions_scheduled_events.php b/plugins/cipf_plugin/php/_actions_scheduled_events.php index bb63157..6374158 100644 --- a/plugins/cipf_plugin/php/_actions_scheduled_events.php +++ b/plugins/cipf_plugin/php/_actions_scheduled_events.php @@ -89,11 +89,11 @@ function schedule_prof_account_deletion_CIPF($user_id) { if (false === $date_limit) { return; } - $date_limit->modify($duration_deletion); - $delay = $date_limit->getTimestamp(); - wp_schedule_single_event($delay, 'CIPF_schedule_event_prof_account_deletion', array($user_id)); + $new_date = $date_limit->modify($duration_deletion); + $delay = $new_date->getTimestamp(); + wp_schedule_single_event($delay, 'CIPF_prof_account_deletion', array($user_id)); } -add_action('CIPF_schedule_event_prof_account_deletion', 'handle_prof_account_deletion_CIPF'); +add_action('CIPF_prof_account_deletion', 'handle_prof_account_deletion_CIPF'); @@ -104,17 +104,16 @@ add_action('CIPF_schedule_event_prof_account_deletion', 'handle_prof_account_del */ function schedule_deactivate_expired_card_CIPF($user_id) { Plgntls::debug_infos(); - $duration_validity = Cipf::DURATION_CARD_VALIDITY; $date_limit = get_card_date_expiration_CIPF($user_id); if (false === $date_limit) { return; } - $date_limit->modify('+1 day'); - $delay = $date_limit->getTimestamp(); - wp_schedule_single_event($delay, 'CIPF_schedule_event_deactivate_expired_card', array($user_id)); + $new_date = $date_limit->modify('+1 day'); + $delay = $new_date->getTimestamp(); + wp_schedule_single_event($delay, 'CIPF_deactivate_expired_card', array($user_id)); } -add_action('CIPF_schedule_event_deactivate_expired_card', 'handle_card_expire_CIPF'); +add_action('CIPF_deactivate_expired_card', 'handle_card_expire_CIPF'); @@ -122,16 +121,24 @@ add_action('CIPF_schedule_event_deactivate_expired_card', 'handle_card_expire_CI /* * 4. && 5. prof, send email reminder before account expire * -function schedule__CIPF($user_id) { - Plgntls::debug_infos(); - $delay = strtotime('+3 days'); - wp_schedule_single_event($delay, 'scedule_event_CIPF', array($user_id)); -} -function event_CIPF($user_id) { - Plgntls::debug_infos(); -} -add_action('schedule_event_CIPF', 'event_CIPF', 10, 2); */ +function schedule_reminder_before_card_expire_CIPF($user_id) { + Plgntls::debug_infos(); + $card_reminder_1 = Cipf::DURATION_REMINDER_BEFORE_ACCOUNT_EXPIRE_FIRST; + $card_reminder_2 = Cipf::DURATION_REMINDER_BEFORE_ACCOUNT_EXPIRE_LAST; + + $date_limit = get_card_date_expiration_CIPF($user_id); + if (false === $date_limit) { + return; + } + $new_date_1 = $date_limit->modify($card_reminder_1); + $new_date_2 = $date_limit->modify($card_reminder_2); + $delay_1 = $new_date_1->getTimestamp(); + $delay_2 = $new_date_2->getTimestamp(); + wp_schedule_single_event($delay_1, 'CIPF_reminder_before_card_expire', array('card_will_expire', $user_id)); + wp_schedule_single_event($delay_2, 'CIPF_reminder_before_card_expire', array('card_will_expire', $user_id)); +} +add_action('CIPF_reminder_before_card_expire', 'send_emails_CIPF', 10, 2); diff --git a/plugins/cipf_plugin/php/_utils_acf_dates.php b/plugins/cipf_plugin/php/_utils_acf_dates.php index c119efc..97013cf 100644 --- a/plugins/cipf_plugin/php/_utils_acf_dates.php +++ b/plugins/cipf_plugin/php/_utils_acf_dates.php @@ -42,7 +42,7 @@ function get_date_CIPF($acf_date, $user_id) { // compare 2 dates : https://stackoverflow.com/q/8722806/9497573 // also I dont use strtotime to compare 2 ints, // because i don't know if it will fail one day (2000y bug style) - $current_date = date_create_from_format($current_format_field, $current_date_string); + $current_date = date_create_immutable_from_format($current_format_field, $current_date_string); if ($current_date === false) { return false; } @@ -96,10 +96,10 @@ function get_new_date_CIPF($date, $duration) { $current_date = $date; // empty return true for false, null, empty string and array, and 0 if (empty($date)) { - $current_date = date_create('today'); + $current_date = date_create_immutable('today'); } else if (!$current_date instanceof DateTimeInterface) { - $current_date = date_create('today'); + $current_date = date_create_immutable('today'); } /* diff --git a/plugins/cipf_plugin/php/paypal/update_user_payment.php b/plugins/cipf_plugin/php/paypal/update_user_payment.php index 91364d5..c80cda3 100644 --- a/plugins/cipf_plugin/php/paypal/update_user_payment.php +++ b/plugins/cipf_plugin/php/paypal/update_user_payment.php @@ -176,6 +176,7 @@ function success_payment_for_user_CIPF($user_id, $order_id) { update_card_date_expiration_CIPF($user_id); schedule_deactivate_expired_card_CIPF($user_id); schedule_prof_account_deletion_CIPF($user_id); + schedule_reminder_before_card_expire_CIPF($user_id); if (is_card_new_CIPF($user_id)) { set_card_number_CIPF($user_id);