From 4192d32155b63afa20e1972f7a46c12bba2ee953 Mon Sep 17 00:00:00 2001 From: liumengyi Date: Tue, 28 Nov 2023 15:51:54 +0800 Subject: [PATCH] * Refactor message::send. --- module/message/model.php | 30 ++++++++------------------- module/message/test/message.class.php | 15 +++++++------- module/message/test/model/send.php | 17 +++++++++++++-- 3 files changed, 32 insertions(+), 30 deletions(-) diff --git a/module/message/model.php b/module/message/model.php index dc6c0ecf33..5284a7cf83 100755 --- a/module/message/model.php +++ b/module/message/model.php @@ -62,7 +62,8 @@ class messageModel extends model } /** - * Check send. + * 发送消息。 + * Send messages. * * @param string $objectType * @param int $objectID @@ -73,7 +74,7 @@ class messageModel extends model * @access public * @return void */ - public function send($objectType, $objectID, $actionType, $actionID, $actor = '', $extra = '') + public function send(string $objectType, int $objectID, string $actionType, int $actionID, string $actor = '', string $extra = ''): void { if(commonModel::isTutorialMode()) return; @@ -84,22 +85,15 @@ class messageModel extends model if(isset($messageSetting['mail'])) { $actions = $messageSetting['mail']['setting']; - if(isset($actions[$objectType]) and in_array($actionType, $actions[$objectType])) + if(isset($actions[$objectType]) && in_array($actionType, $actions[$objectType])) { /* If it is an api call, get the request method set by the user. */ global $config; $requestType = $config->requestType; - if(defined('RUN_MODE') and RUN_MODE == 'api') + if(defined('RUN_MODE') && RUN_MODE == 'api') { $configRoot = $this->app->getConfigRoot(); - if(file_exists($configRoot . 'my.php')) - { - include $configRoot . 'my.php'; - } - else - { - include $configRoot . 'config.php'; - } + include file_exists($configRoot . 'my.php') ? $configRoot . 'my.php' : $configRoot . 'config.php'; } if($objectType == 'feedback') @@ -111,25 +105,19 @@ class messageModel extends model $this->loadModel('mail')->sendmail($objectID, $actionID); } - if(defined('RUN_MODE') and RUN_MODE == 'api') $config->requestType = $requestType; + if(defined('RUN_MODE') && RUN_MODE == 'api') $config->requestType = $requestType; } } if(isset($messageSetting['webhook'])) { $actions = $messageSetting['webhook']['setting']; - if(isset($actions[$objectType]) and in_array($actionType, $actions[$objectType])) - { - $this->loadModel('webhook')->send($objectType, $objectID, $actionType, $actionID, $actor); - } + if(isset($actions[$objectType]) && in_array($actionType, $actions[$objectType])) $this->loadModel('webhook')->send($objectType, $objectID, $actionType, $actionID, $actor); } if(isset($messageSetting['message'])) { $actions = $messageSetting['message']['setting']; - if(isset($actions[$objectType]) and in_array($actionType, $actions[$objectType])) - { - $this->saveNotice($objectType, $objectID, $actionType, $actionID, $actor); - } + if(isset($actions[$objectType]) && in_array($actionType, $actions[$objectType])) $this->saveNotice($objectType, $objectID, $actionType, $actionID, $actor); } } diff --git a/module/message/test/message.class.php b/module/message/test/message.class.php index ab19b4e004..0f349842cb 100644 --- a/module/message/test/message.class.php +++ b/module/message/test/message.class.php @@ -65,23 +65,24 @@ class messageTest } /** - * Check send. + * 测试发送方法。 + * Test send. * - * @param int $objectType + * @param string $objectType * @param int $objectID - * @param int $actionType + * @param string $actionType * @param int $actionID * @param string $actor * @access public - * @return void + * @return array */ - public function sendTest($objectType, $objectID, $actionType, $actionID, $actor = '') + public function sendTest(string $objectType, int $objectID, string $actionType, int $actionID, string $actor = ''): array { - $objects = $this->objectModel->send($objectType, $objectID, $actionType, $actionID, $actor = ''); + $this->objectModel->send($objectType, $objectID, $actionType, $actionID, $actor); if(dao::isError()) return dao::getError(); - return $objects; + return array(); } /** diff --git a/module/message/test/model/send.php b/module/message/test/model/send.php index f76567a631..a6f0dabf02 100755 --- a/module/message/test/model/send.php +++ b/module/message/test/model/send.php @@ -1,7 +1,14 @@ #!/usr/bin/env php gen(2); +zdTable('notify')->gen(0); +zdTable('action')->gen(2); +zdTable('user')->gen(1); + su('admin'); /** @@ -17,5 +24,11 @@ pid=1 $message = new messageTest(); -r($message->sendTest('todo', '1', 'product', '1', 'admin')) && p() && e('0'); //通过拿取todo表的第一条数据并且将actor赋值admin获取返回值 -r($message->sendTest('todo', '0', 'product', '1', 'admin')) && p() && e('0'); //通过拿取todo表的第0条数据并且将actor赋值admin获取返回值 \ No newline at end of file +$objectType = array('story', 'feedback'); +$objectID = array(2, 0); +$actionType = array('opened', 'nothing'); +$actionID = array(2, 0); +$actor = array('admin', ''); + +r($message->sendTest($objectType[0], $objectID[0], $actionType[0], $actionID[0], $actor[0])) && p(0) && e('0'); // 发送 需求 2 动态 2 的消息 +r($message->sendTest($objectType[1], $objectID[1], $actionType[1], $actionID[1], $actor[1])) && p(0) && e('0'); // 发送 反馈 0 动态 0 的消息