From f2ca863dcbbec10357360f719e23170fbd61633b Mon Sep 17 00:00:00 2001 From: asus Date: Thu, 11 Apr 2024 12:33:27 +0200 Subject: [PATCH] fixed error in handling emails reminder for profs card --- plugins/cipf_plugin/php/_utils_acf_fields.php | 36 +++++++++++++++++++ .../cipf_plugin/php/profs_handle_states.php | 34 +++++------------- 2 files changed, 44 insertions(+), 26 deletions(-) diff --git a/plugins/cipf_plugin/php/_utils_acf_fields.php b/plugins/cipf_plugin/php/_utils_acf_fields.php index a4d4de0..6ff7bc4 100644 --- a/plugins/cipf_plugin/php/_utils_acf_fields.php +++ b/plugins/cipf_plugin/php/_utils_acf_fields.php @@ -784,6 +784,42 @@ function reset_emails_reminders_choices_CIPF($user_id = null) { $acf_id = 'user_'.$user_id; set_acf_field_CIPF($acf_emails_reminders, array(), $acf_id); } +function reset_emails_reminders_expiration_card_CIPF($user_id = null) { + Plgntls::debug_infos(); + $acf_emails_reminders = Cipf::ACF_EMAILS_REMINDERS; + + if (is_null($user_id)) { + $user_id = get_current_user_id(); + } + $acf_id = 'user_'.$user_id; + + $reminders_choices = get_emails_reminders_choices_CIPF($user_id); + foreach ($reminders_choices as $reminder_key => $value) { + $explode_reminder = explode('/', $reminder_key); + $explode_reminder = array_map('trim', $explode_reminder); + if ($explode_reminder[0] === 'card_expiration') { + unset_email_reminder_choice_CIPF($reminder_key, $user_id); + } + } +} +function reset_emails_reminders_deletion_account_CIPF($user_id = null) { + Plgntls::debug_infos(); + $acf_emails_reminders = Cipf::ACF_EMAILS_REMINDERS; + + if (is_null($user_id)) { + $user_id = get_current_user_id(); + } + $acf_id = 'user_'.$user_id; + + $reminders_choices = get_emails_reminders_choices_CIPF($user_id); + foreach ($reminders_choices as $reminder_key => $value) { + $explode_reminder = explode('/', $reminder_key); + $explode_reminder = array_map('trim', $explode_reminder); + if ($explode_reminder[0] === 'account_deletion') { + unset_email_reminder_choice_CIPF($reminder_key, $user_id); + } + } +} diff --git a/plugins/cipf_plugin/php/profs_handle_states.php b/plugins/cipf_plugin/php/profs_handle_states.php index 55b38d7..50809d9 100644 --- a/plugins/cipf_plugin/php/profs_handle_states.php +++ b/plugins/cipf_plugin/php/profs_handle_states.php @@ -80,6 +80,7 @@ function handle_card_expire_CIPF($user_id) { else { set_account_valid_CIPF($user_id); } + reset_emails_reminders_deletion_account_CIPF($user_id); } } @@ -128,7 +129,6 @@ function handle_prof_account_deletion_CIPF($user_id) { */ function handle_reminders_before_card_expire_CIPF($user_id) { Plgntls::debug_infos(); - $card_reminders = Cipf::DURATION_REMINDERS_BEFORE_ACCOUNT_EXPIRE; $emails_reminders = Cipf:: ACF_EMAILS_REMINDERS; if (!isset_acf_card_expiration_CIPF($user_id)) { @@ -142,23 +142,16 @@ function handle_reminders_before_card_expire_CIPF($user_id) { return; } - $is_before_reminders = false; - $reminder_list = array(); - foreach ($card_reminders as $reminder_key => $value) { + $is_before_reminders = true; + $reminders_choices = get_emails_reminders_choices_CIPF($user_id); + foreach ($reminders_choices as $reminder_key => $value) { $duration = get_duration_CIPF($reminder_key, 'card_expiration'); - /* - * if false, this reminder is not for 'card_expiration' - * else, add to 'reminder_list' - * - */ if (false === $duration) { continue; } - $reminder_list[] = $reminder_key; $diff = compare_diff_with_today_CIPF($date_limit, $duration); if ($diff > 0) { - $is_before_reminders = true; continue; } $is_before_reminders = false; @@ -179,9 +172,7 @@ function handle_reminders_before_card_expire_CIPF($user_id) { * */ if ($is_before_reminders) { - foreach ($reminder_list as $reminder) { - unset_email_reminder_choice_CIPF($reminder, $user_id); - } + reset_emails_reminders_expiration_card_CIPF($user_id); } } @@ -203,6 +194,7 @@ function handle_reminders_before_account_deleted_CIPF($user_id) { return; } if (!is_card_date_expired_CIPF($user_id)) { + reset_emails_reminders_deletion_account_CIPF($user_id); return; } $date_limit = get_card_date_expiration_CIPF($user_id); @@ -212,8 +204,7 @@ function handle_reminders_before_account_deleted_CIPF($user_id) { $date_deletion = $date_limit->modify($duration_deletion); - $is_before_reminders = false; - $reminder_list = array(); + $is_before_reminders = true; /* * get the acf reminders, * - continue the ones not for account deletion @@ -224,19 +215,12 @@ function handle_reminders_before_account_deleted_CIPF($user_id) { $reminders_choices = get_emails_reminders_choices_CIPF($user_id); foreach ($reminders_choices as $reminder_key => $value) { $duration = get_duration_CIPF($reminder_key, 'account_deletion'); - /* - * if false, this reminder is not for 'card_expiration' - * else, add to 'reminder_list' - * - */ if (false === $duration) { continue; } - $reminder_list[] = $reminder_key; $diff = compare_diff_with_today_CIPF($date_deletion, $duration); if ($diff > 0) { - $is_before_reminders = true; continue; } $is_before_reminders = false; @@ -260,9 +244,7 @@ function handle_reminders_before_account_deleted_CIPF($user_id) { * */ if ($is_before_reminders) { - foreach ($reminder_list as $reminder) { - unset_email_reminder_choice_CIPF($reminder, $user_id); - } + reset_emails_reminders_deletion_account_CIPF($user_id); } }