* Refactor for send object mail.
This commit is contained in:
@@ -39,4 +39,3 @@ if(file_exists($extViewFile))
|
||||
</table>
|
||||
</body>
|
||||
</html><?php // close tags in mail.header.html.php ?>
|
||||
<?php if($onlybody) $_GET['onlybody'] = 'yes';?>
|
||||
|
||||
@@ -1,8 +1,3 @@
|
||||
<?php
|
||||
$onlybody = isonlybody() ? true : false;
|
||||
if($onlybody) $_GET['onlybody'] = 'no';
|
||||
?>
|
||||
|
||||
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
|
||||
<html xmlns='http://www.w3.org/1999/xhtml'>
|
||||
<head>
|
||||
|
||||
@@ -807,7 +807,7 @@ class docModel extends model
|
||||
$this->dao->update(TABLE_DOC)->set('version')->eq($doc->version)->where('id')->eq($doc->id)->exec();
|
||||
}
|
||||
|
||||
$doc->title = isset($docContent->title) ? $docContent->title : '';
|
||||
$doc->title = isset($docContent->title) ? $docContent->title : $doc->title;
|
||||
$doc->digest = isset($docContent->digest) ? $docContent->digest : '';
|
||||
$doc->content = isset($docContent->content) ? $docContent->content : '';
|
||||
$doc->contentType = isset($docContent->type) ? $docContent->type : '';
|
||||
|
||||
+3
-51
@@ -221,14 +221,14 @@ class mail extends control
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function browse($orderBy = 'id_desc', $recTotal = 0, $recPerPage = 100, $pageID = 1)
|
||||
public function browse(string $orderBy = 'id_desc', int $recTotal = 0, int $recPerPage = 100, int $pageID = 1)
|
||||
{
|
||||
$this->app->loadClass('pager', $static = true);
|
||||
$pager = new pager($recTotal, $recPerPage, $pageID);
|
||||
|
||||
$this->view->title = $this->lang->mail->browse;
|
||||
|
||||
$this->view->queueList = $this->mail->getQueue(null, $orderBy, $pager);
|
||||
$this->view->queueList = $this->mail->getQueue('all', $orderBy, $pager);
|
||||
$this->view->pager = $pager;
|
||||
$this->view->orderBy = $orderBy;
|
||||
$this->view->users = $this->loadModel('user')->getPairs('noletter');
|
||||
@@ -243,7 +243,7 @@ class mail extends control
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function delete($id)
|
||||
public function delete(int $id)
|
||||
{
|
||||
$this->dao->delete()->from(TABLE_NOTIFY)->where('id')->eq($id)->exec();
|
||||
return $this->send(array('result' => 'success', 'callback' => 'loadCurrentPage()'));
|
||||
@@ -264,52 +264,4 @@ class mail extends control
|
||||
$this->dao->delete()->from(TABLE_NOTIFY)->where('id')->in($idList)->exec();
|
||||
return $this->send(array('result' => 'success', 'callback' => 'loadCurrentPage()'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sendcloud user.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function sendcloudUser()
|
||||
{
|
||||
if($this->config->mail->mta != 'sendcloud') return print(js::locate('back'));
|
||||
|
||||
$this->mta = $this->mail->setMTA();
|
||||
if($_POST)
|
||||
{
|
||||
$data = fixer::input('post')->get();
|
||||
$action = $data->action;
|
||||
$listName = $action == 'delete' ? 'syncedList' : 'unsyncList';
|
||||
|
||||
$users = array_unique($data->$listName);
|
||||
if(empty($users)) return print(js::reload('parent'));
|
||||
|
||||
$realnameAndEmails = $this->loadModel('user')->getRealNameAndEmails($users);
|
||||
$actionedEmail = array();
|
||||
foreach($realnameAndEmails as $realnameAndEmail)
|
||||
{
|
||||
$email = $realnameAndEmail->email;
|
||||
if(isset($actionedEmail[$email])) continue;
|
||||
|
||||
$result = $this->mail->syncSendCloud($action, $email, $realnameAndEmail->realname);
|
||||
if(!$result->result)
|
||||
{
|
||||
echo js::alert($this->lang->mail->sendCloudFail . str_replace("'", '"', $result->message) . "(CODE: $result->statusCode)");
|
||||
return print(js::reload('parent'));
|
||||
}
|
||||
|
||||
$actionedEmail[$email] = $email;
|
||||
}
|
||||
|
||||
echo js::alert($this->lang->mail->sendCloudSuccess);
|
||||
return print(js::reload('parent'));
|
||||
}
|
||||
|
||||
$this->view->title = $this->lang->mail->sendcloudUser;
|
||||
|
||||
$this->view->members = $this->mta->memberList();
|
||||
$this->view->users = $this->loadModel('user')->getList();
|
||||
$this->display();
|
||||
}
|
||||
}
|
||||
|
||||
+24
-149
@@ -310,8 +310,8 @@ class mailModel extends model
|
||||
/**
|
||||
* Set cc.
|
||||
*
|
||||
* @param string $ccList
|
||||
* @param array $emails
|
||||
* @param array $ccList
|
||||
* @param array $emails
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
@@ -455,20 +455,22 @@ class mailModel extends model
|
||||
/**
|
||||
* Get queue.
|
||||
*
|
||||
* @param string $status
|
||||
* @param string $status all|wait|fail
|
||||
* @param string $orderBy
|
||||
* @param object $pager
|
||||
* @param bool $mergeByUser
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getQueue(string $status = '', string $orderBy = 'id_desc', object|null $pager = null): array
|
||||
public function getQueue(string $status = 'all', string $orderBy = 'id_desc', object|null $pager = null, bool $mergeByUser = true): array
|
||||
{
|
||||
$mails = $this->dao->select('*')->from(TABLE_NOTIFY)
|
||||
->where('objectType')->eq('mail')
|
||||
->beginIF($status)->andWhere('status')->eq($status)->fi()
|
||||
->beginIF(!empty($status) && $status != 'all')->andWhere('status')->eq($status)->fi()
|
||||
->orderBy($orderBy)
|
||||
->page($pager)
|
||||
->fetchAll('id');
|
||||
if(!$mergeByUser) return $mails;
|
||||
|
||||
/* Group mails by toList and ccList. */
|
||||
$groupMails = array();
|
||||
@@ -553,35 +555,6 @@ class mailModel extends model
|
||||
return $mail;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sync to sendCloud
|
||||
*
|
||||
* @param string $action
|
||||
* @param string $email
|
||||
* @param string $userName
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function syncSendCloud($action, $email, $userName = '')
|
||||
{
|
||||
$result = '';
|
||||
if($action == 'delete')
|
||||
{
|
||||
$result = $this->mta->deleteMember($email);
|
||||
}
|
||||
elseif($action == 'sync')
|
||||
{
|
||||
$member = new stdclass();
|
||||
$member->nickName = $email;
|
||||
$member->email = $email;
|
||||
$member->userName = $userName;
|
||||
|
||||
$result = $this->mta->addMember($member);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send mail.
|
||||
*
|
||||
@@ -590,119 +563,24 @@ class mailModel extends model
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function sendmail($objectID, $actionID)
|
||||
public function sendmail(int $objectID, int $actionID): void
|
||||
{
|
||||
if(empty($objectID) or empty($actionID)) return;
|
||||
|
||||
/* Load module and get vars. */
|
||||
$this->loadModel('action');
|
||||
$action = $this->action->getById($actionID);
|
||||
$history = $this->action->getHistory($actionID);
|
||||
$action = $this->mailZen->getActionForMail($actionID);
|
||||
$objectType = $action->objectType;
|
||||
$object = $objectType == 'kanbancard' ? $this->loadModel('kanban')->getCardByID($objectID) : $this->loadModel($objectType)->getByID($objectID);
|
||||
$nameFields = $this->config->action->objectNameFields[$objectType];
|
||||
$title = zget($object, $nameFields, '');
|
||||
$subject = $this->getSubject($objectType, $object, $title, $action->action);
|
||||
$object = $this->mailZen->getObjectForMail($objectType, $objectID);
|
||||
$title = $this->mailZen->getObjectTitle($object, $objectType);
|
||||
$domain = zget($this->config->mail, 'domain', common::getSysURL());
|
||||
|
||||
if(empty($title)) $action->appendLink = '';
|
||||
if($title and $action->appendLink) $action->appendLink = html::a($domain . helper::createLink($action->objectType, 'view', "id={$action->appendLink}"), "#{$action->appendLink} {$title}");
|
||||
|
||||
if($objectType == 'review' and empty($object->auditedBy)) return;
|
||||
|
||||
if($objectType == 'doc' && $object->contentType == 'markdown')
|
||||
{
|
||||
$object->content = commonModel::processMarkdown($object->content);
|
||||
$object->content = str_replace("<table>", "<table style='border-collapse: collapse;'>", $object->content);
|
||||
$object->content = str_replace("<th>", "<th style='word-break: break-word; border:1px solid #000;'>", $object->content);
|
||||
$object->content = str_replace("<td>", "<td style='word-break: break-word; border:1px solid #000;'>", $object->content);
|
||||
}
|
||||
|
||||
$action->history = isset($history[$actionID]) ? $history[$actionID] : array();
|
||||
$action->appendLink = '';
|
||||
if(strpos($action->extra, ':') !== false)
|
||||
{
|
||||
list($extra, $id) = explode(':', $action->extra);
|
||||
$action->extra = $extra;
|
||||
if($title)
|
||||
{
|
||||
$action->appendLink = html::a($domain . helper::createLink($action->objectType, 'view', "id=$id", 'html'), "#$id " . $title);
|
||||
}
|
||||
}
|
||||
|
||||
if($objectType == 'review') $this->app->loadLang('baseline');
|
||||
|
||||
/* Get mail content. */
|
||||
if($objectType == 'kanbancard') $objectType = 'kanban';
|
||||
|
||||
$modulePath = $this->app->getModulePath('', $objectType);
|
||||
$oldcwd = getcwd();
|
||||
$viewFile = $modulePath . 'view/sendmail.html.php';
|
||||
chdir($modulePath . 'view');
|
||||
if(file_exists($modulePath . 'ext/view/sendmail.html.php'))
|
||||
{
|
||||
$viewFile = $modulePath . 'ext/view/sendmail.html.php';
|
||||
chdir($modulePath . 'ext/view');
|
||||
}
|
||||
ob_start();
|
||||
if($objectType != 'mr') include $viewFile;
|
||||
foreach(glob($modulePath . 'ext/view/sendmail.*.html.hook.php') as $hookFile) include $hookFile;
|
||||
$mailContent = ob_get_contents();
|
||||
ob_end_clean();
|
||||
chdir($oldcwd);
|
||||
|
||||
/* Get the sender. */
|
||||
if($objectType == 'story' or $objectType == 'meeting')
|
||||
{
|
||||
$sendUsers = $this->{$objectType}->getToAndCcList($object, $action->action);
|
||||
}
|
||||
elseif($objectType == 'review')
|
||||
{
|
||||
$sendUsers = array($object->auditedBy, '');
|
||||
}
|
||||
elseif($objectType == 'ticket')
|
||||
{
|
||||
$sendUsers = $this->{$objectType}->getToAndCcList($object, $action);
|
||||
}
|
||||
else
|
||||
{
|
||||
$sendUsers = $this->{$objectType}->getToAndCcList($object);
|
||||
}
|
||||
|
||||
if(!$sendUsers) return;
|
||||
list($toList, $ccList) = $sendUsers;
|
||||
|
||||
/* Send it. */
|
||||
if($objectType == 'mr')
|
||||
{
|
||||
$MRLink = common::getSysURL() . helper::createLink('mr', 'view', "id={$object->id}");
|
||||
if($action->action == 'compilepass')
|
||||
{
|
||||
$mailContent = sprintf($this->lang->mr->toCreatedMessage, $MRLink, $title);
|
||||
$this->send($toList, $subject, $mailContent);
|
||||
|
||||
$mailContent = sprintf($this->lang->mr->toReviewerMessage, $MRLink, $title);
|
||||
$this->send($ccList, $subject, $mailContent);
|
||||
|
||||
/* Create a todo item for this MR. */
|
||||
$this->loadModel('mr')->apiCreateMRTodo($object->gitlabID, $object->targetProject, $object->mriid);
|
||||
}
|
||||
elseif($action->action == 'compilefail')
|
||||
{
|
||||
$mailContent = sprintf($this->lang->mr->failMessage, $MRLink, $title);
|
||||
$this->send($toList, $subject, $mailContent, $ccList);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if($objectType == 'ticket')
|
||||
{
|
||||
$emails = $this->loadModel('ticket')->getContactEmails($objectID, $toList, $ccList, $action->action == 'closed');
|
||||
$this->send($toList, $subject, $mailContent, $ccList, false, $emails);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->send($toList, $subject, $mailContent, $ccList);
|
||||
}
|
||||
}
|
||||
if($this->isError()) error_log(implode("\n", $this->getError()));
|
||||
$this->mailZen->sendBasedOnType($objectType, $object, $action);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -715,7 +593,7 @@ class mailModel extends model
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getSubject($objectType, $object, $title, $actionType)
|
||||
public function getSubject(string $objectType, object $object, string $title, string $actionType): string
|
||||
{
|
||||
$suffix = '';
|
||||
$subject = '';
|
||||
@@ -727,24 +605,21 @@ class mailModel extends model
|
||||
|
||||
if($actionType == 'opened') $titleType = 'create';
|
||||
if($actionType == 'closed') $titleType = 'close';
|
||||
|
||||
$subject = sprintf($this->lang->testtask->mail->{$titleType}->title, $this->app->user->realname, $object->id, $object->name);
|
||||
return sprintf($this->lang->testtask->mail->{$titleType}->title, $this->app->user->realname, $object->id, $object->name);
|
||||
}
|
||||
elseif($objectType == 'doc')
|
||||
|
||||
if($objectType == 'doc')
|
||||
{
|
||||
$this->app->loadLang('doc');
|
||||
|
||||
if($actionType == 'created') $titleType = 'create';
|
||||
$subject = sprintf($this->lang->doc->mail->{$titleType}->title, $this->app->user->realname, $object->id, $object->title);
|
||||
return sprintf($this->lang->doc->mail->{$titleType}->title, $this->app->user->realname, $object->id, $object->title);
|
||||
}
|
||||
else
|
||||
{
|
||||
if($objectType == 'story' or $objectType == 'bug') $suffix = empty($object->product) ? '' : ' - ' . $this->loadModel('product')->getById($object->product)->name;
|
||||
if($objectType == 'task') $suffix = empty($object->execution) ? '' : ' - ' . $this->loadModel('execution')->getById($object->execution)->name;
|
||||
|
||||
$subject = strtoupper($objectType) . ' #' . $object->id . ' ' . $title . $suffix;
|
||||
}
|
||||
return $subject;
|
||||
if($objectType == 'story' or $objectType == 'bug') $suffix = empty($object->product) ? '' : ' - ' . $this->loadModel('product')->getById($object->product)->name;
|
||||
if($objectType == 'task') $suffix = empty($object->execution) ? '' : ' - ' . $this->loadModel('execution')->getById($object->execution)->name;
|
||||
|
||||
return strtoupper($objectType) . ' #' . $object->id . ' ' . $title . $suffix;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,8 +10,9 @@ cid=0
|
||||
- 按照收件人分组获取邮件列表个数 @8
|
||||
- 按照收件人分组获取发送失败的邮件数量 @4
|
||||
- 按照收件人分组获取待发送的邮件数量 @4
|
||||
- 不合并邮件,检查队列数量 @9
|
||||
- 按照收件人分组获取第一条待发送的邮件内容
|
||||
- 第0条的data属性 @用户创建了任务1
|
||||
- 第0条的data属性 @用户创建了任务9用户创建了任务1
|
||||
- 第0条的subject属性 @主题9|主题1
|
||||
- 按照收件人分组获取第二条待发送的邮件内容
|
||||
- 第1条的data属性 @用户创建了任务7
|
||||
@@ -25,7 +26,6 @@ su('admin');
|
||||
$notify = zdTable('notify');
|
||||
$notify->toList->range('1-8')->prefix('user');
|
||||
$notify->gen(9);
|
||||
zdTable('notify')->gen(10);
|
||||
|
||||
$mail = new mailTest();
|
||||
|
||||
@@ -33,9 +33,11 @@ $result1 = count($mail->getQueueTest());
|
||||
$result2 = count($mail->getQueueTest('fail'));
|
||||
$result3 = count($mail->getQueueTest('wait'));
|
||||
$result4 = $mail->getQueueTest('wait');
|
||||
$result5 = count($mail->objectModel->getQueue('all', 'id_desc', null, false));
|
||||
|
||||
r($result1) && p() && e('8'); //按照收件人分组获取邮件列表个数
|
||||
r($result2) && p() && e('4'); //按照收件人分组获取发送失败的邮件数量
|
||||
r($result3) && p() && e('4'); //按照收件人分组获取待发送的邮件数量
|
||||
r($result1) && p() && e('8'); //按照收件人分组获取邮件列表个数
|
||||
r($result2) && p() && e('4'); //按照收件人分组获取发送失败的邮件数量
|
||||
r($result3) && p() && e('4'); //按照收件人分组获取待发送的邮件数量
|
||||
r($result5) && p() && e('9'); //不合并邮件,检查队列数量
|
||||
r($result4) && p('0:data,subject') && e('用户创建了任务9用户创建了任务1,主题9|主题1'); //按照收件人分组获取第一条待发送的邮件内容
|
||||
r($result4) && p('1:data,subject') && e('用户创建了任务7,主题7'); //按照收件人分组获取第二条待发送的邮件内容
|
||||
|
||||
@@ -4,21 +4,30 @@
|
||||
/**
|
||||
|
||||
title=测试 mailModel->getSubject();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
获取关闭测试单时邮件主题 >> admin关闭了测试单 #1:测试单1
|
||||
获取创建文档时的邮件主题 >> admin创建了文档 #1:文档标题901
|
||||
获取操作需求时的邮件主题 >> STORY #1 test - 正常产品1
|
||||
获取操作任务时的邮件主题 >> TASK #1 test - 迭代1
|
||||
获取操作BUG时的邮件主题 >> BUG #1 test - 正常产品1
|
||||
cid=0
|
||||
|
||||
*/
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/mail.class.php';
|
||||
su('admin');
|
||||
|
||||
$testtask = zdTable('testtask');
|
||||
$testtask->createdBy->range('admin');
|
||||
$testtask->createdDate->range('`' . date('Y-m-d H:i:s') . '`');
|
||||
$testtask->gen(2);
|
||||
zdTable('doc')->gen(2);
|
||||
zdTable('docaction')->gen(0);
|
||||
zdTable('task')->gen(2);
|
||||
zdTable('story')->gen(2);
|
||||
zdTable('bug')->gen(2);
|
||||
zdTable('product')->gen(2);
|
||||
$project = zdTable('project');
|
||||
$project->id->range('101-105');
|
||||
$project->name->range('1-5')->prefix('迭代');
|
||||
$project->gen(2);
|
||||
|
||||
$mail = new mailTest();
|
||||
$mail->objectModel->app->user->realname = '管理员';
|
||||
|
||||
$result1 = $mail->getSubjectTest('testtask', 1, '123', 'closed');
|
||||
$result2 = $mail->getSubjectTest('doc', 1, 'test', 'created');
|
||||
@@ -26,8 +35,8 @@ $result3 = $mail->getSubjectTest('story', 1, 'test', 'created');
|
||||
$result4 = $mail->getSubjectTest('task', 1, 'test', 'created');
|
||||
$result5 = $mail->getSubjectTest('bug', 1, 'test', 'created');
|
||||
|
||||
r($result1) && p() && e('admin关闭了测试单 #1:测试单1'); //获取关闭测试单时邮件主题
|
||||
r($result2) && p() && e('admin创建了文档 #1:文档标题901'); //获取创建文档时的邮件主题
|
||||
r($result3) && p() && e('STORY #1 test - 正常产品1'); //获取操作需求时的邮件主题
|
||||
r($result4) && p() && e('TASK #1 test - 迭代1'); //获取操作任务时的邮件主题
|
||||
r($result5) && p() && e('BUG #1 test - 正常产品1'); //获取操作BUG时的邮件主题
|
||||
r($result1 == '管理员关闭了测试单 #1:测试单1') && p() && e('1'); //获取关闭测试单时邮件主题
|
||||
r($result2 == '管理员创建了文档 #1:文档标题1') && p() && e('1'); //获取创建文档时的邮件主题
|
||||
r($result3 == 'STORY #1 test - 正常产品1') && p() && e('1'); //获取操作需求时的邮件主题
|
||||
r($result4 == 'TASK #1 test - 迭代1') && p() && e('1'); //获取操作任务时的邮件主题
|
||||
r($result5 == 'BUG #1 test - 正常产品1') && p() && e('1'); //获取操作BUG时的邮件主题
|
||||
|
||||
Reference in New Issue
Block a user