- CL/Messages_model-> sendReply applied workaround for Infocenter

- MailJob now extends JOB_Controller and writes logs in DB
- MailJob->sendMessages renamed to sendAllMessageEmailNotices
- sendAllMessageEmailNotices now accept new parameter since to restrict number of messages
- MessageLib->sendAllEmailNotices now accept new parameter since and adapted to use new MessageLib->_sendNoticeEmails
- Recipient_model->getMessages renamed to getNotSentMessages
- Now accepts only limit and since as parameters
- Changed query to retrieve only message ids
This commit is contained in:
Paolo
2020-02-21 16:59:25 +01:00
parent c1adc94204
commit 304d7727f0
4 changed files with 55 additions and 85 deletions
+25 -17
View File
@@ -1,20 +1,8 @@
<?php
/**
* FH-Complete
*
* @package FHC-API
* @author FHC-Team
* @copyright Copyright (c) 2016, fhcomplete.org
* @license GPLv3
* @link http://fhcomplete.org
* @since Version 1.0
* @filesource
*/
// ------------------------------------------------------------------------
if (!defined("BASEPATH")) exit("No direct script access allowed");
class MailJob extends CLI_Controller
class MailJob extends JOB_Controller
{
/**
* API constructor
@@ -28,11 +16,31 @@ class MailJob extends CLI_Controller
}
/**
* Send all not sent messages
* Parameters are used to overrride messages and mail configuration
* 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 sendMessages($numberToSent = null, $numberPerTimeRange = null, $emailTimeRange = null, $emailFromSystem = null)
public function sendAllMessageEmailNotices($since = null, $numberToSent = null, $numberPerTimeRange = null, $emailTimeRange = null, $emailFromSystem = null)
{
$this->messagelib->sendAllNotices($numberToSent, $numberPerTimeRange, $emailTimeRange, $emailFromSystem);
$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();
$optionalParameters->$since = $since;
$optionalParameters->$numberToSent = $numberToSent;
$optionalParameters->$numberPerTimeRange = $numberPerTimeRange;
$optionalParameters->$emailTimeRange = $emailTimeRange;
$optionalParameters->$emailFromSystem = $emailFromSystem;
$this->logError($sendAllEmailNotices->retval, $optionalParameters);
}
elseif (!hasData($sendAllEmailNotices))
{
$this->logInfo('There were no unsent messages');
}
$this->logInfo('Send all message email notices ended');
}
}
+15 -11
View File
@@ -139,27 +139,31 @@ class MessageLib
// Public methods called by a job
/**
* Gets all NOT sent messages from DB and sends for each of them the notice email
* Does not return anything, it logs info and errors on CI logs and in tbl_msg_recipient table
* Gets all messages for which notice emails are still not sent from DB and sends for each of them the notice email
* Wrapper for _sendNoticeEmail.
*/
public function sendAllEmailNotices($numberToSent, $numberPerTimeRange, $emailTimeRange, $emailFromSystem)
public function sendAllEmailNotices($since, $numberToSent, $numberPerTimeRange, $emailTimeRange, $emailFromSystem)
{
// Overrides MailLib configs with the given parameters
$this->_ci->maillib->overrideConfigs($numberToSent, $numberPerTimeRange, $emailTimeRange, $emailFromSystem);
// Retrieves a certain amount of NOT sent messages, the amount is given by maillib->email_number_to_sent
$messagesResult = $this->_ci->RecipientModel->getMessages(
self::EMAIL_KONTAKT_TYPE,
null,
$this->_ci->maillib->getEmailNumberToSent()
// Retrieves a certain amount of NOT sent messages
$messagesResult = $this->_ci->RecipientModel->getNotSentMessages(
$this->_ci->maillib->getEmailNumberToSent(),
$since
);
if (isError($messagesResult)) terminateWithError(getData($messagesResult)); // If an error occurred then log it and terminate
if (isError($messagesResult) || !hasData($messagesResult)) return $messagesResult;
$sendNotice = $this->_sendNoticeEmails(getData($messagesResult));
// Collects all the message ids in an array
$messageIds = array();
foreach (getData($messagesResult) as $message)
{
$messageIds[] = $message->message_id;
}
if (isError($sendNotice)) terminateWithError(getData($sendNotice)); // If an error occurred then log it and terminate
// Send'em all
return $this->_sendNoticeEmails($messageIds);
}
//------------------------------------------------------------------------------------------------------------------
+2 -1
View File
@@ -509,7 +509,8 @@ class Messages_model extends CI_Model
if (!hasData($message)) return error('No messages were saved in database');
// Write log entry
$personLog = $this->_personLog($sender_id, $receiver_id, getData($message)[0]);
// NOTE: $receiver_id and $sender_id are switched!!! Currently this is a workaround
$personLog = $this->_personLog($receiver_id, $sender_id, getData($message)[0]);
if (isError($personLog)) return $personLog;
return success('Messages sent successfully');
+13 -56
View File
@@ -199,66 +199,23 @@ class Recipient_model extends DB_Model
}
/**
* getMessages
* Gets all messages for which notice emails are still not sent
*
* Gets all the messages to be sent
*
* @param kontaktType specifies the type of the kontakt to get
* @param sent specifies the status of the messages to get (NULL never sent, otherwise the shipping date)
* @param limit specifies the number of messages to get
* @param message_id specifies a single message
* @param kontaktType specifies the type of the kontakt to get (email,...)
* @param limit specifies the max number of messages to get
* @param since specifies from which date messages have to be retrieved
*/
public function getMessages($kontaktType, $message_id = null, $limit = 1)
public function getNotSentMessages($limit, $since = '1970-01-01')
{
$query = 'SELECT mm.message_id,
ks.kontakt as sender,
kr.kontakt as receiver,
mu.mitarbeiter_uid as employeeContact,
ms.mitarbeiter_uid as senderemployeeContact,
mr.person_id as receiver_id,
mr.token,
mm.subject,
mm.body,
mr.sentinfo,
mr.oe_kurzbz
FROM public.tbl_msg_recipient mr INNER JOIN public.tbl_msg_message mm USING (message_id)
LEFT JOIN (
SELECT person_id, kontakt FROM public.tbl_kontakt WHERE zustellung = true AND kontakttyp = ?
) ks ON (ks.person_id = mm.person_id)
LEFT JOIN (
SELECT person_id, kontakt FROM public.tbl_kontakt WHERE zustellung = true AND kontakttyp = ?
) kr ON (kr.person_id = mr.person_id)
LEFT JOIN (
SELECT b.person_id,
m.mitarbeiter_uid
FROM public.tbl_benutzer b INNER JOIN public.tbl_mitarbeiter m ON(b.uid = m.mitarbeiter_uid)
WHERE b.aktiv = TRUE
) mu ON (mu.person_id = mr.person_id)
LEFT JOIN (
SELECT b.person_id,
m.mitarbeiter_uid
FROM public.tbl_benutzer b INNER JOIN public.tbl_mitarbeiter m ON(b.uid = m.mitarbeiter_uid)
WHERE b.aktiv = TRUE
) ms ON (ms.person_id = mm.person_id)
WHERE mr.sent IS NULL';
$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 mm.insertamum > ?
ORDER BY mr.insertamum ASC
LIMIT ?';
$parametersArray = array($kontaktType, $kontaktType);
if (is_numeric($message_id))
{
array_push($parametersArray, $message_id);
$query .= ' AND mm.message_id = ?';
}
$query .= ' ORDER BY mr.insertamum ASC';
if (is_numeric($limit))
{
$query .= ' LIMIT ?';
array_push($parametersArray, $limit);
}
return $this->execQuery($query, $parametersArray);
return $this->execQuery($query, array($since, $limit));
}
/**