From 94ae62ca1458c418bf8cb0a1a200f80c43b7e767 Mon Sep 17 00:00:00 2001 From: paolo Date: Wed, 29 Jun 2016 10:45:32 +0200 Subject: [PATCH] Changed the method postMessage of controller Message, now it works even without recipients --- .../controllers/api/v1/system/Message.php | 1 - application/libraries/MessageLib.php | 39 ++++++++++++------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/application/controllers/api/v1/system/Message.php b/application/controllers/api/v1/system/Message.php index 6b9fdf9ef..e58929a71 100644 --- a/application/controllers/api/v1/system/Message.php +++ b/application/controllers/api/v1/system/Message.php @@ -75,7 +75,6 @@ class Message extends APIv1_Controller if (is_object($validation) && $validation->error == EXIT_SUCCESS) { - $this->messagelib->addRecipient($this->post()['person_id']); $result = $this->messagelib->sendMessage( $this->post()['person_id'], $this->post()['subject'], diff --git a/application/libraries/MessageLib.php b/application/libraries/MessageLib.php index 77d13bed1..f0c25a279 100644 --- a/application/libraries/MessageLib.php +++ b/application/libraries/MessageLib.php @@ -182,33 +182,42 @@ class MessageLib if (!is_numeric($sender_id)) return $this->_invalid_id(MSG_ERR_INVALID_MSG_ID); - if (empty($this->recipients)) - return $this->_error('No Recipients! Use addRecipient()', MSG_ERR_INVALID_RECIPIENTS); - // Start sending Message $this->ci->db->trans_start(false); - //save Message $data = array( 'person_id' => $sender_id, 'subject' => $subject, 'body' => $body, 'priority' => $priority, - 'relationmessage_id' => $relationmessage_id, - 'oe_kurzbz' => $oe_kurzbz); - if (! $msg = $this->ci->MessageModel->insert($data)) - return $this->_error($msg->msg.$msg->retval, MSG_ERR_GENERAL); - $msg_id = $msg->retval; - $this->ci->db->trans_complete(); - if ($this->ci->db->trans_status() === FALSE) + //'relationmessage_id' => $relationmessage_id, + 'oe_kurzbz' => $oe_kurzbz + ); + + $result = $this->ci->MessageModel->insert($data); + if (is_object($result) && $result->error == EXIT_SUCCESS) { - // generate an error... or use the log_message() function to log your error - // General Error Occurred - return $this->_error(); + $msg_id = $result->retval; + $statusData = array( + 'message_id' => $msg_id, + 'person_id' => $sender_id, + 'status' => MSG_STATUS_UNREAD + ); + $result = $this->ci->MsgStatusModel->insert($statusData); + } + + $this->ci->db->trans_complete(); + + if ($this->ci->db->trans_status() === FALSE || (is_object($result) && $result->error != EXIT_SUCCESS)) + { + $this->ci->db->trans_rollback(); + return $this->_error($result->msg, EXIT_ERROR); } else + { + $this->ci->db->trans_commit(); return $this->_success($msg_id); - + } } /**