* finish task #3562.
This commit is contained in:
@@ -95,7 +95,6 @@ define('TABLE_FILE', '`' . $config->db->prefix . 'file`');
|
||||
define('TABLE_HISTORY', '`' . $config->db->prefix . 'history`');
|
||||
define('TABLE_EXTENSION', '`' . $config->db->prefix . 'extension`');
|
||||
define('TABLE_CRON', '`' . $config->db->prefix . 'cron`');
|
||||
define('TABLE_MAILQUEUE', '`' . $config->db->prefix . 'mailqueue`');
|
||||
define('TABLE_BLOCK', '`' . $config->db->prefix . 'block`');
|
||||
define('TABLE_DOCCONTENT', '`' . $config->db->prefix . 'doccontent`');
|
||||
define('TABLE_TESTSUITE', '`' . $config->db->prefix . 'testsuite`');
|
||||
@@ -104,9 +103,9 @@ define('TABLE_TESTREPORT', '`' . $config->db->prefix . 'testreport`');
|
||||
|
||||
define('TABLE_ENTRY', '`' . $config->db->prefix . 'entry`');
|
||||
define('TABLE_WEBHOOK', '`' . $config->db->prefix . 'webhook`');
|
||||
define('TABLE_WEBHOOKDATAS', '`' . $config->db->prefix . 'webhookdatas`');
|
||||
define('TABLE_LOG', '`' . $config->db->prefix . 'log`');
|
||||
define('TABLE_SCORE', '`' . $config->db->prefix . 'score`');
|
||||
define('TABLE_NOTIFY', '`' . $config->db->prefix . 'notify`');
|
||||
if(!defined('TABLE_LANG')) define('TABLE_LANG', '`' . $config->db->prefix . 'lang`');
|
||||
|
||||
$config->objectTables['product'] = TABLE_PRODUCT;
|
||||
|
||||
@@ -3,3 +3,19 @@ ALTER TABLE `zt_todo` ADD `config` varchar(255) NOT NULL;
|
||||
ALTER TABLE `zt_todo` ADD `cycle` tinyint unsigned NOT NULL DEFAULT '0' AFTER `type`;
|
||||
INSERT INTO `zt_cron` (`m`, `h`, `dom`, `mon`, `dow`, `command`, `remark`, `type`, `buildin`, `status`, `lastTime`) VALUES
|
||||
('1', '1', '*', '*', '*', 'moduleName=todo&methodName=createCycle', '生成周期性待办', 'zentao', 1, 'normal', '0000-00-00 00:00:00');
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `zt_notify` (
|
||||
`id` mediumint unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||
`objectType` varchar(50) NOT NULL,
|
||||
`objectID` mediumint unsigned NOT NULL,
|
||||
`action` mediumint NOT NULL,
|
||||
`toList` varchar(255) NOT NULL,
|
||||
`ccList` text NOT NULL,
|
||||
`subject` varchar(255) NOT NULL,
|
||||
`data` text NOT NULL,
|
||||
`createdBy` char(30) NOT NULL,
|
||||
`createdDate` datetime NOT NULL,
|
||||
`sendTime` datetime NOT NULL,
|
||||
`status` varchar(10) NOT NULL DEFAULT 'wait',
|
||||
`failReason` text NOT NULL
|
||||
) ENGINE='MyISAM' COLLATE 'utf8_general_ci';
|
||||
|
||||
@@ -407,6 +407,22 @@ CREATE TABLE IF NOT EXISTS `zt_module` (
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `module` (`root`,`type`,`path`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||
-- DROP TABLE IF EXISTS `zt_notify`;
|
||||
CREATE TABLE IF NOT EXISTS `zt_notify` (
|
||||
`id` mediumint unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||
`objectType` varchar(50) NOT NULL,
|
||||
`objectID` mediumint unsigned NOT NULL,
|
||||
`action` mediumint NOT NULL,
|
||||
`toList` varchar(255) NOT NULL,
|
||||
`ccList` text NOT NULL,
|
||||
`subject` varchar(255) NOT NULL,
|
||||
`data` text NOT NULL,
|
||||
`createdBy` char(30) NOT NULL,
|
||||
`createdDate` datetime NOT NULL,
|
||||
`sendTime` datetime NOT NULL,
|
||||
`status` varchar(10) NOT NULL DEFAULT 'wait',
|
||||
`failReason` text NOT NULL
|
||||
) ENGINE='MyISAM' COLLATE 'utf8_general_ci';
|
||||
-- DROP TABLE IF EXISTS `zt_product`;
|
||||
CREATE TABLE IF NOT EXISTS `zt_product` (
|
||||
`id` mediumint(8) unsigned NOT NULL auto_increment,
|
||||
|
||||
+13
-13
@@ -316,35 +316,35 @@ class mail extends control
|
||||
{
|
||||
if(!isset($queue->merge) or $queue->merge == false)
|
||||
{
|
||||
$mailStatus = $this->dao->select('*')->from(TABLE_MAILQUEUE)->where('id')->eq($queue->id)->fetch('status');
|
||||
$mailStatus = $this->dao->select('*')->from(TABLE_NOTIFY)->where('id')->eq($queue->id)->fetch('status');
|
||||
if(empty($mailStatus) or $mailStatus != 'wait') continue;
|
||||
}
|
||||
|
||||
$this->dao->update(TABLE_MAILQUEUE)->set('status')->eq('sending')->where('id')->in($queue->id)->exec();
|
||||
$this->mail->send($queue->toList, $queue->subject, $queue->body, $queue->ccList, true);
|
||||
$this->dao->update(TABLE_NOTIFY)->set('status')->eq('sending')->where('id')->in($queue->id)->exec();
|
||||
$this->mail->send($queue->toList, $queue->subject, $queue->data, $queue->ccList, true);
|
||||
|
||||
$data = new stdclass();
|
||||
$data->sendTime = $now;
|
||||
$data->status = 'send';
|
||||
$data->status = 'sended';
|
||||
if($this->mail->isError())
|
||||
{
|
||||
$data->status = 'fail';
|
||||
$data->failReason = join("\n", $this->mail->getError());
|
||||
}
|
||||
$this->dao->update(TABLE_MAILQUEUE)->data($data)->where('id')->in($queue->id)->exec();
|
||||
$this->dao->update(TABLE_NOTIFY)->data($data)->where('id')->in($queue->id)->exec();
|
||||
|
||||
$log .= "Send #$queue->id result is $data->status\n";
|
||||
if($data->status == 'fail') $log .= "reason is $data->failReason\n";
|
||||
}
|
||||
|
||||
/* Delete sended mail. */
|
||||
$lastMail = $this->dao->select('id,status')->from(TABLE_MAILQUEUE)->orderBy('id_desc')->limit(1)->fetch();
|
||||
$lastMail = $this->dao->select('id,status')->from(TABLE_NOTIFY)->where('objectType')->eq('mail')->orderBy('id_desc')->limit(1)->fetch();
|
||||
if(!empty($lastMail) and $lastMail->id > 1000000)
|
||||
{
|
||||
$unSendNum = $this->dao->select('count(id) as count')->from(TABLE_MAILQUEUE)->where('status')->eq('wait')->fetch('count');
|
||||
if($unSendNum == 0) $this->dao->exec('TRUNCATE table ' . TABLE_MAILQUEUE);
|
||||
$unSendNum = $this->dao->select('count(id) as count')->from(TABLE_NOTIFY)->where('status')->eq('wait')->fetch('count');
|
||||
if($unSendNum == 0) $this->dao->exec('TRUNCATE table ' . TABLE_NOTIFY);
|
||||
}
|
||||
$this->dao->delete()->from(TABLE_MAILQUEUE)->where('status')->eq('send')->andWhere('sendTime')->le(date('Y-m-d H:i:s', time() - 2 * 24 * 3600))->exec();
|
||||
$this->dao->delete()->from(TABLE_NOTIFY)->where('status')->eq('sended')->andWhere('sendTime')->le(date('Y-m-d H:i:s', time() - 2 * 24 * 3600))->exec();
|
||||
|
||||
echo $log;
|
||||
echo "OK\n";
|
||||
@@ -366,7 +366,7 @@ class mail extends control
|
||||
}
|
||||
|
||||
if(isset($this->config->mail->async)) $this->config->mail->async = 0;
|
||||
$this->mail->send($queue->toList, $queue->subject, $queue->body, $queue->ccList);
|
||||
$this->mail->send($queue->toList, $queue->subject, $queue->data, $queue->ccList);
|
||||
|
||||
$data = new stdclass();
|
||||
$data->sendTime = helper::now();
|
||||
@@ -377,7 +377,7 @@ class mail extends control
|
||||
$data->status = 'fail';
|
||||
$data->failReason = join("\n", $this->mail->getError());
|
||||
}
|
||||
$this->dao->update(TABLE_MAILQUEUE)->data($data)->where('id')->in($queue->id)->exec();
|
||||
$this->dao->update(TABLE_NOTIFY)->data($data)->where('id')->in($queue->id)->exec();
|
||||
|
||||
if($data->status == 'fail') die(js::alert($data->failReason));
|
||||
echo js::alert($this->lang->mail->noticeResend);
|
||||
@@ -422,7 +422,7 @@ class mail extends control
|
||||
{
|
||||
if($confirm == 'no') die(js::confirm($this->lang->mail->confirmDelete, inlink('delete', "id=$id&confirm=yes")));
|
||||
|
||||
$this->dao->delete()->from(TABLE_MAILQUEUE)->where('id')->eq($id)->exec();
|
||||
$this->dao->delete()->from(TABLE_NOTIFY)->where('id')->eq($id)->exec();
|
||||
die(js::reload('parent'));
|
||||
}
|
||||
|
||||
@@ -444,7 +444,7 @@ class mail extends control
|
||||
$idList = array();
|
||||
if(isset($_GET['idList'])) $idList = explode('|', $_GET['idList']);
|
||||
|
||||
if($idList) $this->dao->delete()->from(TABLE_MAILQUEUE)->where('id')->in($idList)->exec();
|
||||
if($idList) $this->dao->delete()->from(TABLE_NOTIFY)->where('id')->in($idList)->exec();
|
||||
die(js::reload('parent'));
|
||||
}
|
||||
|
||||
|
||||
@@ -45,8 +45,8 @@ $lang->mail->remove = 'Remove';
|
||||
$lang->mail->toList = 'Addressee';
|
||||
$lang->mail->ccList = 'Copy to';
|
||||
$lang->mail->subject = 'Subject';
|
||||
$lang->mail->addedBy = 'Sender';
|
||||
$lang->mail->addedDate = 'Added Date';
|
||||
$lang->mail->createdBy = 'Sender';
|
||||
$lang->mail->createdDate = 'Added Date';
|
||||
$lang->mail->sendTime = 'Send Date';
|
||||
$lang->mail->status = 'Status';
|
||||
$lang->mail->failReason = 'Fail Reason';
|
||||
|
||||
@@ -45,8 +45,8 @@ $lang->mail->remove = '移除';
|
||||
$lang->mail->toList = '收信人';
|
||||
$lang->mail->ccList = '抄送给';
|
||||
$lang->mail->subject = '主题';
|
||||
$lang->mail->addedBy = '发送者';
|
||||
$lang->mail->addedDate = '创建时间';
|
||||
$lang->mail->createdBy = '发送者';
|
||||
$lang->mail->createdDate = '创建时间';
|
||||
$lang->mail->sendTime = '发送时间';
|
||||
$lang->mail->status = '状态';
|
||||
$lang->mail->failReason = '失败原因';
|
||||
|
||||
+19
-18
@@ -514,13 +514,14 @@ class mailModel extends model
|
||||
if(empty($toList) or empty($subject)) return true;
|
||||
|
||||
$data = new stdclass();
|
||||
$data->toList = $toList;
|
||||
$data->ccList = $ccList;
|
||||
$data->subject = $subject;
|
||||
$data->body = $body;
|
||||
$data->addedBy = $this->config->mail->fromName;
|
||||
$data->addedDate = helper::now();
|
||||
$this->dao->insert(TABLE_MAILQUEUE)->data($data)->autocheck()->exec();
|
||||
$data->objectType = 'mail';
|
||||
$data->toList = $toList;
|
||||
$data->ccList = $ccList;
|
||||
$data->subject = $subject;
|
||||
$data->data = $body;
|
||||
$data->createdBy = $this->config->mail->fromName;
|
||||
$data->createdDate = helper::now();
|
||||
$this->dao->insert(TABLE_NOTIFY)->data($data)->autocheck()->exec();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -532,8 +533,8 @@ class mailModel extends model
|
||||
*/
|
||||
public function getQueue($status = '', $orderBy = 'id_desc', $pager = null)
|
||||
{
|
||||
$mails = $this->dao->select('*')->from(TABLE_MAILQUEUE)
|
||||
->where('1=1')
|
||||
$mails = $this->dao->select('*')->from(TABLE_NOTIFY)
|
||||
->where('objectType')->eq('mail')
|
||||
->beginIF($status)->andWhere('status')->eq($status)->fi()
|
||||
->orderBy($orderBy)
|
||||
->page($pager)
|
||||
@@ -562,7 +563,7 @@ class mailModel extends model
|
||||
|
||||
public function getQueueById($queueID)
|
||||
{
|
||||
return $this->dao->select('*')->from(TABLE_MAILQUEUE)->where('id')->eq($queueID)->fetch();
|
||||
return $this->dao->select('*')->from(TABLE_NOTIFY)->where('id')->eq($queueID)->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -599,8 +600,8 @@ class mailModel extends model
|
||||
}
|
||||
|
||||
/* Remove html tail for first mail. */
|
||||
$endPos = strripos($firstMail->body, '</td>');
|
||||
$mail->body = trim(substr($firstMail->body, 0, $endPos));
|
||||
$endPos = strripos($firstMail->data, '</td>');
|
||||
$mail->data = trim(substr($firstMail->data, 0, $endPos));
|
||||
|
||||
/* Merge middle mails. */
|
||||
if($mails)
|
||||
@@ -610,21 +611,21 @@ class mailModel extends model
|
||||
$mail->id .= ',' . $middleMail->id;
|
||||
|
||||
/* Remove html head and tail for middle mails. */
|
||||
$beginPos = strpos($middleMail->body, '</table>');
|
||||
$mailBody = trim(substr($middleMail->body, $beginPos));
|
||||
$beginPos = strpos($middleMail->data, '</table>');
|
||||
$mailBody = trim(substr($middleMail->data, $beginPos));
|
||||
$endPos = strripos($mailBody, '</td>');
|
||||
$mailBody = trim(substr($mailBody, 0, $endPos));
|
||||
|
||||
$mail->body .= ltrim($mailBody, '</table>');
|
||||
$mail->data .= ltrim($mailBody, '</table>');
|
||||
}
|
||||
}
|
||||
|
||||
$mail->id .= ',' . $lastMail->id;
|
||||
|
||||
/* Remove html head for last mail. */
|
||||
$beginPos = strpos($lastMail->body, '</table>');
|
||||
$mailBody = substr($lastMail->body, $beginPos);
|
||||
$mail->body .= trim(ltrim($mailBody, '</table>'));
|
||||
$beginPos = strpos($lastMail->data, '</table>');
|
||||
$mailBody = substr($lastMail->data, $beginPos);
|
||||
$mail->data .= trim(ltrim($mailBody, '</table>'));
|
||||
|
||||
return $mail;
|
||||
}
|
||||
|
||||
@@ -20,13 +20,13 @@
|
||||
<?php $vars = "orderBy=%s&recTotal={$pager->recTotal}&recPerPage={$pager->recPerPage}"; ?>
|
||||
<thead>
|
||||
<tr>
|
||||
<th class='w-id'> <?php common::printOrderLink('id', $orderBy, $vars, $lang->idAB);?></th>
|
||||
<th class='w-80px'> <?php common::printOrderLink('toList', $orderBy, $vars, $lang->mail->toList);?></th>
|
||||
<th class='w-150px'> <?php common::printOrderLink('subject', $orderBy, $vars, $lang->mail->subject);?></th>
|
||||
<th class='w-80px'> <?php common::printOrderLink('addedBy', $orderBy, $vars, $lang->mail->addedBy);?></th>
|
||||
<th class='w-150px'> <?php common::printOrderLink('addedDate', $orderBy, $vars, $lang->mail->addedDate);?></th>
|
||||
<th class='w-150px'> <?php common::printOrderLink('sendTime', $orderBy, $vars, $lang->mail->sendTime);?></th>
|
||||
<th class='w-60px'> <?php common::printOrderLink('status', $orderBy, $vars, $lang->mail->status);?></th>
|
||||
<th class='w-id'> <?php common::printOrderLink('id', $orderBy, $vars, $lang->idAB);?></th>
|
||||
<th class='w-80px'> <?php common::printOrderLink('toList', $orderBy, $vars, $lang->mail->toList);?></th>
|
||||
<th class='w-150px'> <?php common::printOrderLink('subject', $orderBy, $vars, $lang->mail->subject);?></th>
|
||||
<th class='w-80px'> <?php common::printOrderLink('createdBy', $orderBy, $vars, $lang->mail->createdBy);?></th>
|
||||
<th class='w-150px'> <?php common::printOrderLink('createdDate', $orderBy, $vars, $lang->mail->createdDate);?></th>
|
||||
<th class='w-150px'> <?php common::printOrderLink('sendTime', $orderBy, $vars, $lang->mail->sendTime);?></th>
|
||||
<th class='w-60px'> <?php common::printOrderLink('status', $orderBy, $vars, $lang->mail->status);?></th>
|
||||
<th> <?php echo $lang->mail->failReason;?></th>
|
||||
<th class='w-80px'> <?php echo $lang->actions;?></th>
|
||||
</tr>
|
||||
@@ -40,8 +40,8 @@
|
||||
</td>
|
||||
<td><?php echo zget($users, $queue->toList, $queue->toList)?></td>
|
||||
<td class='text-left'><?php echo $queue->subject?></td>
|
||||
<td><?php echo zget($users, $queue->addedBy, $queue->addedBy)?></td>
|
||||
<td><?php echo $queue->addedDate?></td>
|
||||
<td><?php echo zget($users, $queue->createdBy)?></td>
|
||||
<td><?php echo $queue->createdDate?></td>
|
||||
<td><?php echo $queue->sendTime?></td>
|
||||
<td><?php echo zget($lang->mail->statusList, $queue->status, '')?></td>
|
||||
<td class='text-left'><?php echo $queue->failReason?></td>
|
||||
|
||||
@@ -1986,4 +1986,48 @@ class upgradeModel extends model
|
||||
$this->dao->exec("ALTER TABLE `" . TABLE_TEAM . "` DROP `task`");
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move data to notify.
|
||||
*
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function moveData2Notify()
|
||||
{
|
||||
$this->dao->exec('TRUNCATE TABLE ' . TABLE_NOTIFY);
|
||||
$mailQueueTable = '`' . $this->config->db->prefix . 'mailqueue`';
|
||||
$stmt = $this->dao->select('*')->from($mailQueueTable)->query();
|
||||
while($mailQueue = $stmt->fetch())
|
||||
{
|
||||
$notify = new stdclass();
|
||||
$notify->objectType = 'mail';
|
||||
$notify->toList = $mailQueue->toList;
|
||||
$notify->ccList = $mailQueue->ccList;
|
||||
$notify->subject = $mailQueue->subject;
|
||||
$notify->data = $mailQueue->body;
|
||||
$notify->createdBy = $mailQueue->addedBy;
|
||||
$notify->createdDate = $mailQueue->addedDate;
|
||||
$notify->sendTime = $mailQueue->sendTime;
|
||||
$notify->status = $mailQueue->status;
|
||||
$notify->failReason = $mailQueue->failReason;
|
||||
$this->dao->insert(TABLE_NOTIFY)->data($notify)->exec();
|
||||
}
|
||||
|
||||
$webhookDataTable = '`' . $this->config->db->prefix . 'webhookdatas`';
|
||||
$stmt = $this->dao->select('*')->from($webhookDataTable)->query();
|
||||
while($webhookData = $stmt->fetch())
|
||||
{
|
||||
$notify = new stdclass();
|
||||
$notify->objectType = 'webhook';
|
||||
$notify->objectID = $webhookData->webhook;
|
||||
$notify->action = $webhookData->action;
|
||||
$notify->data = $webhookData->data;
|
||||
$notify->createdBy = $webhookData->createdBy;
|
||||
$notify->createdDate = $webhookData->createdDate;
|
||||
$notify->status = $webhookData->status;
|
||||
$this->dao->insert(TABLE_NOTIFY)->data($notify)->exec();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,19 +157,20 @@ class webhook extends control
|
||||
return true;
|
||||
}
|
||||
|
||||
$now = helper::now();
|
||||
foreach($dataList as $data)
|
||||
{
|
||||
$webhook = zget($webhooks, $data->webhook, '');
|
||||
$webhook = zget($webhooks, $data->objectID, '');
|
||||
if($webhook)
|
||||
{
|
||||
$result = $this->webhook->fetchHook($webhook, $data->data);
|
||||
$this->webhook->saveLog($webhook, $data->action, $data->data, $result);
|
||||
}
|
||||
|
||||
$this->dao->update(TABLE_WEBHOOKDATAS)->set('status')->eq('sended')->where('id')->eq($data->id)->exec();
|
||||
$this->dao->update(TABLE_NOTIFY)->set('status')->eq('sended')->set('sendTime')->eq($now)->where('id')->eq($data->id)->exec();
|
||||
}
|
||||
|
||||
$this->dao->delete()->from(TABLE_WEBHOOKDATAS)->where('status')->eq('sended')->exec();
|
||||
$this->dao->delete()->from(TABLE_NOTIFY)->where('status')->eq('sended')->exec();
|
||||
|
||||
echo "OK\n";
|
||||
return true;
|
||||
|
||||
@@ -96,7 +96,7 @@ class webhookModel extends model
|
||||
*/
|
||||
public function getDataList()
|
||||
{
|
||||
return $this->dao->select('*')->from(TABLE_WEBHOOKDATAS)->where('status')->eq('wait')->orderBy('id')->fetchAll('id');
|
||||
return $this->dao->select('*')->from(TABLE_NOTIFY)->where('status')->eq('wait')->andWhere('objectType')->eq('webhook')->orderBy('id')->fetchAll('id');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -435,13 +435,14 @@ class webhookModel extends model
|
||||
public function saveData($webhookID, $actionID, $data)
|
||||
{
|
||||
$webhookData = new stdclass();
|
||||
$webhookData->webhook = $webhookID;
|
||||
$webhookData->objectType = 'webhook';
|
||||
$webhookData->objectID = $webhookID;
|
||||
$webhookData->action = $actionID;
|
||||
$webhookData->data = $data;
|
||||
$webhookData->createdBy = $this->app->user->account;
|
||||
$webhookData->createdDate = helper::now();
|
||||
|
||||
$this->dao->insert(TABLE_WEBHOOKDATAS)->data($webhookData)->exec();
|
||||
$this->dao->insert(TABLE_NOTIFY)->data($webhookData)->exec();
|
||||
return !dao::isError();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user