From 443caa91f27c6ce55a60930b0405e14f71d888d2 Mon Sep 17 00:00:00 2001 From: Paolo Date: Mon, 9 Nov 2020 10:45:25 +0100 Subject: [PATCH 1/5] Messaging sysntem: the internal email account is used only if the user account is older then 24 hours --- application/libraries/MessageLib.php | 42 +++++++++++++++++--- application/models/person/Benutzer_model.php | 4 +- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/application/libraries/MessageLib.php b/application/libraries/MessageLib.php index fd2051f48..1180de9fd 100644 --- a/application/libraries/MessageLib.php +++ b/application/libraries/MessageLib.php @@ -595,11 +595,20 @@ class MessageLib $this->_ci->load->model('person/Benutzer_model', 'BenutzerModel'); // And the receiver has an active account for the given organisation unit - $benutzerResult = $this->_ci->BenutzerModel->getActiveUserByPersonIdAndOrganisationUnit($message->receiver_id, $message->sender_ou); + $benutzerResult = $this->_ci->BenutzerModel->getActiveUserByPersonIdAndOrganisationUnit( + $message->receiver_id, + $message->sender_ou + ); + if (isError($benutzerResult)) return $benutzerResult; // if an error occured then return it - // Use the uid + domain email - if (hasData($benutzerResult)) $message->receiverContact = getData($benutzerResult)[0]->uid .'@'.DOMAIN; + // Checks if the user was NOT created in the last 24 hours + if (getData($benutzerResult)[0]->insertamum > date('Y-m-d H:i:s', strtotime('+1 day'))) + { + // Use the uid + domain email + if (hasData($benutzerResult)) $message->receiverContact = getData($benutzerResult)[0]->uid .'@'.DOMAIN; + } + // otherwise do NOT use the internal email account } // Otherwise try with the private email @@ -676,10 +685,33 @@ class MessageLib $this->_ci->BenutzerModel->addOrder('updateamum', 'DESC'); $this->_ci->BenutzerModel->addOrder('insertamum', 'DESC'); - $benutzerResult = $this->_ci->BenutzerModel->loadWhere(array('person_id' => $message->receiver_id)); + $benutzerResult = $this->_ci->BenutzerModel->loadWhere( + array( + 'person_id' => $message->receiver_id + ) + ); if (isError($benutzerResult)) return $benutzerResult; // if an error occured then return it - $message->receiverContact = getData($benutzerResult)[0]->uid .'@'.DOMAIN; // Use the uid + domain email + // For each benutzer found for this person + foreach (getData($benutzerResult) as $benutzer) + { + // Checks if the user was NOT created in the last 24 hours + if (getData($benutzerResult)[0]->insertamum > date('Y-m-d H:i:s', strtotime('+1 day'))) + { + // Use the uid + domain as email address + $message->receiverContact = getData($benutzerResult)[0]->uid .'@'.DOMAIN; + } + } + + // Otherwise try with the private email + if (isEmptyString($message->receiverContact)) + { + // Then use the private email + $privateEmailResult = $this->_getPrivateEmail($message->receiver_id); + if (isError($privateEmailResult)) return $privateEmailResult; // if an error occured then return it + + if (hasData($privateEmailResult)) $message->receiverContact = getData($privateEmailResult); + } } } } diff --git a/application/models/person/Benutzer_model.php b/application/models/person/Benutzer_model.php index 45edf5122..3c5a6d08a 100644 --- a/application/models/person/Benutzer_model.php +++ b/application/models/person/Benutzer_model.php @@ -23,7 +23,8 @@ class Benutzer_model extends DB_Model */ public function getActiveUserByPersonIdAndOrganisationUnit($person_id, $oe_kurzbz) { - $sql = 'SELECT b.uid + $sql = 'SELECT b.uid, + b.insertamum FROM public.tbl_benutzer b JOIN public.tbl_prestudent ps USING (person_id) JOIN public.tbl_studiengang sg USING (studiengang_kz) @@ -97,3 +98,4 @@ class Benutzer_model extends DB_Model return mb_strtolower(str_replace(' ','_', $str)); } } + From 9d2c004c6d5915b13164e1fc22832218de68f499 Mon Sep 17 00:00:00 2001 From: Paolo Date: Wed, 18 Nov 2020 08:51:48 +0100 Subject: [PATCH 2/5] Checks if the benutzer exists MessageLib->_sendNoticeEmails --- application/libraries/MessageLib.php | 30 ++++++++++++++++++---------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/application/libraries/MessageLib.php b/application/libraries/MessageLib.php index 1180de9fd..8c58d1a90 100644 --- a/application/libraries/MessageLib.php +++ b/application/libraries/MessageLib.php @@ -602,13 +602,17 @@ class MessageLib if (isError($benutzerResult)) return $benutzerResult; // if an error occured then return it - // Checks if the user was NOT created in the last 24 hours - if (getData($benutzerResult)[0]->insertamum > date('Y-m-d H:i:s', strtotime('+1 day'))) + // If an active user for the given organization unit was found + if (hasData($benutzerResult)) { - // Use the uid + domain email - if (hasData($benutzerResult)) $message->receiverContact = getData($benutzerResult)[0]->uid .'@'.DOMAIN; + // Checks if the user was NOT created in the last 24 hours + if (getData($benutzerResult)[0]->insertamum > date('Y-m-d H:i:s', strtotime('+1 day'))) + { + // Use the uid + domain email + $message->receiverContact = getData($benutzerResult)[0]->uid .'@'.DOMAIN; + } + // otherwise do NOT use the internal email account } - // otherwise do NOT use the internal email account } // Otherwise try with the private email @@ -692,14 +696,18 @@ class MessageLib ); if (isError($benutzerResult)) return $benutzerResult; // if an error occured then return it - // For each benutzer found for this person - foreach (getData($benutzerResult) as $benutzer) + // If an active user for the given organization unit was found + if (hasData($benutzerResult)) { - // Checks if the user was NOT created in the last 24 hours - if (getData($benutzerResult)[0]->insertamum > date('Y-m-d H:i:s', strtotime('+1 day'))) + // For each benutzer found for this person + foreach (getData($benutzerResult) as $benutzer) { - // Use the uid + domain as email address - $message->receiverContact = getData($benutzerResult)[0]->uid .'@'.DOMAIN; + // Checks if the user was NOT created in the last 24 hours + if (getData($benutzerResult)[0]->insertamum > date('Y-m-d H:i:s', strtotime('+1 day'))) + { + // Use the uid + domain as email address + $message->receiverContact = getData($benutzerResult)[0]->uid .'@'.DOMAIN; + } } } From 451e0e784382c82088bde507477036186f932008 Mon Sep 17 00:00:00 2001 From: Paolo Date: Thu, 19 Nov 2020 00:09:53 +0100 Subject: [PATCH 3/5] Fixed MessageLib->_sendNoticeEmails: date and array comparisons --- application/libraries/MessageLib.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/application/libraries/MessageLib.php b/application/libraries/MessageLib.php index 8c58d1a90..2970fbd6d 100644 --- a/application/libraries/MessageLib.php +++ b/application/libraries/MessageLib.php @@ -606,7 +606,7 @@ class MessageLib if (hasData($benutzerResult)) { // Checks if the user was NOT created in the last 24 hours - if (getData($benutzerResult)[0]->insertamum > date('Y-m-d H:i:s', strtotime('+1 day'))) + if (getData($benutzerResult)[0]->insertamum > date('Y-m-d H:i:s', strtotime('-1 day'))) { // Use the uid + domain email $message->receiverContact = getData($benutzerResult)[0]->uid .'@'.DOMAIN; @@ -657,7 +657,7 @@ class MessageLib // If there are presetudent if (hasData($prestudentResults)) { - $inArray = true; + $privateOnly = false; $organisationUnits = getData($prestudentResults); // Look if any of the organization units of this prestudent are in the list of the @@ -665,16 +665,21 @@ class MessageLib foreach ($organisationUnits as $organisationUnit) { // If the recipient organisation unit is NOT in the list of organisation units that sent only to private emails + // NOTE: done in this way because it is easyer to check the result of array_search if (array_search($organisationUnit, $this->_ci->config->item(self::CFG_OU_RECEIVERS_PRIVATE)) === false) { - $inArray = false; + // NOP + } + else // otherwise If the recipient organisation unit is the list of organisation units that sent only to private emails + { + $privateOnly = true; break; } } // If the recipient prestudent organization unit is not in in the list of the // organization units that will not send the notice email to the internal account - if (!$inArray) + if ($privateOnly) { // Then use the private email $privateEmailResult = $this->_getPrivateEmail($message->receiver_id); @@ -703,7 +708,7 @@ class MessageLib foreach (getData($benutzerResult) as $benutzer) { // Checks if the user was NOT created in the last 24 hours - if (getData($benutzerResult)[0]->insertamum > date('Y-m-d H:i:s', strtotime('+1 day'))) + if (getData($benutzerResult)[0]->insertamum > date('Y-m-d H:i:s', strtotime('-1 day'))) { // Use the uid + domain as email address $message->receiverContact = getData($benutzerResult)[0]->uid .'@'.DOMAIN; From 119d5d99df73ca398e689bd7f50b926ab497307b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=96sterreicher?= Date: Mon, 23 Nov 2020 16:18:43 +0100 Subject: [PATCH 4/5] Fixed Query to get User for Messages by PersonID and OrganisationUnit --- application/models/person/Benutzer_model.php | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/application/models/person/Benutzer_model.php b/application/models/person/Benutzer_model.php index 3c5a6d08a..c1e76ce38 100644 --- a/application/models/person/Benutzer_model.php +++ b/application/models/person/Benutzer_model.php @@ -23,14 +23,17 @@ class Benutzer_model extends DB_Model */ public function getActiveUserByPersonIdAndOrganisationUnit($person_id, $oe_kurzbz) { - $sql = 'SELECT b.uid, - b.insertamum - FROM public.tbl_benutzer b - JOIN public.tbl_prestudent ps USING (person_id) - JOIN public.tbl_studiengang sg USING (studiengang_kz) - WHERE ps.person_id = ? - AND sg.oe_kurzbz = ? - AND b.aktiv = TRUE'; + $sql = 'SELECT + b.uid, + b.insertamum + FROM + public.tbl_prestudent ps + JOIN public.tbl_studiengang sg USING (studiengang_kz) + JOIN public.tbl_student USING(prestudent_id) + JOIN public.tbl_benutzer b ON(uid = student_uid) + WHERE ps.person_id = ? + AND sg.oe_kurzbz = ? + AND b.aktiv = TRUE'; return $this->execQuery($sql, array($person_id, $oe_kurzbz)); } @@ -98,4 +101,3 @@ class Benutzer_model extends DB_Model return mb_strtolower(str_replace(' ','_', $str)); } } - From 6e5c555a40dcc9b2e28d512e5b8cf2aaf149fc22 Mon Sep 17 00:00:00 2001 From: Paolo Date: Mon, 23 Nov 2020 16:19:23 +0100 Subject: [PATCH 5/5] Fixed MessageLib->_sendNoticeEmail --- application/libraries/MessageLib.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application/libraries/MessageLib.php b/application/libraries/MessageLib.php index 2970fbd6d..db760ec03 100644 --- a/application/libraries/MessageLib.php +++ b/application/libraries/MessageLib.php @@ -606,7 +606,7 @@ class MessageLib if (hasData($benutzerResult)) { // Checks if the user was NOT created in the last 24 hours - if (getData($benutzerResult)[0]->insertamum > date('Y-m-d H:i:s', strtotime('-1 day'))) + if (getData($benutzerResult)[0]->insertamum < date('Y-m-d H:i:s', strtotime('-1 day'))) { // Use the uid + domain email $message->receiverContact = getData($benutzerResult)[0]->uid .'@'.DOMAIN; @@ -708,7 +708,7 @@ class MessageLib foreach (getData($benutzerResult) as $benutzer) { // Checks if the user was NOT created in the last 24 hours - if (getData($benutzerResult)[0]->insertamum > date('Y-m-d H:i:s', strtotime('-1 day'))) + if (getData($benutzerResult)[0]->insertamum < date('Y-m-d H:i:s', strtotime('-1 day'))) { // Use the uid + domain as email address $message->receiverContact = getData($benutzerResult)[0]->uid .'@'.DOMAIN;