- jobs/MailJob->sendAllMessageEmailNotices changed since parameter default value

- Moved ALT_OE from MessageLib to CL/Messages_model
- MessageLib->_setSentError renamed to _updatedRecipientNoticeEmailInfo
- MessageLib->_sendNoticeEmail changed to have more information about a not sent notice email
- Recipient_model->getNotSentMessages now does not retrieve messages with notice email send failure
This commit is contained in:
Paolo
2020-02-25 16:41:27 +01:00
parent b9d973a6e8
commit a50cc6cba8
4 changed files with 33 additions and 10 deletions
+2 -1
View File
@@ -19,12 +19,13 @@ class MailJob extends JOB_Controller
* Send all the NOT sent notice emails for messaging system
* The parameters are all not mandatory, they could be used to overrides the configs for testing, debug or one shot purposes
*/
public function sendAllMessageEmailNotices($since = null, $numberToSent = null, $numberPerTimeRange = null, $emailTimeRange = null, $emailFromSystem = null)
public function sendAllMessageEmailNotices($since = '1970-01-01', $numberToSent = null, $numberPerTimeRange = null, $emailTimeRange = null, $emailFromSystem = null)
{
$this->logInfo('Send all message email notices started');
// Send them all!
$sendAllEmailNotices = $this->messagelib->sendAllEmailNotices($since, $numberToSent, $numberPerTimeRange, $emailTimeRange, $emailFromSystem);
if (isError($sendAllEmailNotices))
{
$optionalParameters = new stdClass();
+26 -7
View File
@@ -26,8 +26,6 @@ class MessageLib
const EMAIL_KONTAKT_TYPE = 'email'; // Email kontakt type
const SENT_INFO_NEWLINE = '\n'; // tbl_msg_recipient->sentInfo separator
const ALT_OE = 'infocenter'; // alternative organisation unit when no one is found for a presetudent
private $_ci;
/**
@@ -498,7 +496,7 @@ class MessageLib
* Stores the type of error in 'sentinfo' column keeping en eventual previous error
* sent column is set to null
*/
private function _setSentError($message_id, $receiver_id, $sentInfo, $prevSentInfo)
private function _updatedRecipientNoticeEmailInfo($message_id, $receiver_id, $sentInfo, $prevSentInfo)
{
if (!isEmptyString($prevSentInfo))
{
@@ -763,15 +761,15 @@ class MessageLib
if (!$sent)
{
// Set in database why this email is NOT going to be send
$sse = $this->_setSentError(
$sse = $this->_updatedRecipientNoticeEmailInfo(
$messageData->message_id,
$messageData->receiver_id,
'An error occurred while sending the notice email',
$messageData->sentinfo
'An error occurred while sending the notice email', // current info
$messageData->sentinfo // previous info
);
// If database error occurred then return it, otherwise return a logic error
return isError($sse) ? $sse : error('An error occurred while sending the notice email');
return isError($sse) ? $sse : error('An error occurred while updating the recipient notice email info');
}
else // success!
{
@@ -780,6 +778,27 @@ class MessageLib
if (isError($sss)) return $sss; // If database error occurred then return it
}
}
else // Because was not possible to find a valid contact
{
$reason = 'Was not possible to find a valid contact for this user'; // default reason
// In case that the organisation unit does not receive any email notices
if (!isEmptyString($messageData->receiver_ou)) $reason = 'This organization unit does not receive email notices';
// In case that a degree program sent a message to a user without a valid contact or UID
if (!isEmptyString($messageData->sender_ou)) $reason = 'Sent from a degree program to a user that does not have a valid UID or a valid contact';
// Set in database why this email is NOT going to be send
$sse = $this->_updatedRecipientNoticeEmailInfo(
$messageData->message_id,
$messageData->receiver_id,
$reason, // current info
$messageData->sentinfo // previous info
);
// If database error occurred then return it
if (isError($sse)) return $sse;
}
}
return success('Notice emails sent successfully');
+3 -1
View File
@@ -26,6 +26,8 @@ class Messages_model extends CI_Model
const TYPE_PERSONS = 'persons';
const TYPE_PRESTUDENTS = 'prestudents';
const ALT_OE = 'infocenter'; // alternative organisation unit when no one is found for a presetudent
/**
* Constructor
*/
@@ -106,7 +108,7 @@ class Messages_model extends CI_Model
{
$ouOptions .= sprintf(
"\n".'<option value="%s">%s</option>',
is_numeric($ou->prestudent_id) ? $ou->oe_kurzbz : MessageLib::ALT_OE,
is_numeric($ou->prestudent_id) ? $ou->oe_kurzbz : self::ALT_OE,
$ou->bezeichnung . (is_numeric($ou->prestudent_id) ? '' : ' *')
);
}
@@ -205,12 +205,13 @@ class Recipient_model extends DB_Model
* @param limit specifies the max number of messages to get
* @param since specifies from which date messages have to be retrieved
*/
public function getNotSentMessages($limit, $since = '1970-01-01')
public function getNotSentMessages($limit, $since)
{
$query = 'SELECT mm.message_id
FROM public.tbl_msg_recipient mr
JOIN public.tbl_msg_message mm USING (message_id)
WHERE mr.sent IS NULL
AND mr.sentinfo IS NULL
AND mm.insertamum > ?
ORDER BY mr.insertamum ASC
LIMIT ?';