From 3244ff8f07453a10ed713a4c9a0b1b299d7c4f52 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Mon, 1 Aug 2016 07:23:43 +0000 Subject: [PATCH] added issue owner change notification --- codepot/src/codepot/controllers/issue.php | 18 +++++++++- codepot/src/codepot/models/issuemodel.php | 40 +++++++++++------------ codepot/src/codepot/views/issue_show.php | 2 ++ 3 files changed, 39 insertions(+), 21 deletions(-) diff --git a/codepot/src/codepot/controllers/issue.php b/codepot/src/codepot/controllers/issue.php index 8d3011aa..3fd43c63 100644 --- a/codepot/src/codepot/controllers/issue.php +++ b/codepot/src/codepot/controllers/issue.php @@ -698,6 +698,8 @@ class Issue extends Controller } else { + $issue_url_base = $this->input->post('issue_url_base'); + $change = new stdClass(); $change->type = $this->input->post('issue_change_type'); $change->status = $this->input->post('issue_change_status'); @@ -705,13 +707,27 @@ class Issue extends Controller $change->priority = $this->input->post('issue_change_priority'); $change->comment = $this->input->post('issue_change_comment'); - if ($this->issues->change ($login['id'], $project, $issueid, $change, $is_nonmember) === FALSE) + if ($this->issues->change ($login['id'], $project, $issueid, $change, $is_nonmember, $old_state) === FALSE) { $status = 'error - ' . $this->issues->getErrorMessage(); } else { $status = 'ok'; + + if (CODEPOT_ISSUE_NOTIFICATION && $old_state->owner != $change->owner) + { + // TODO: message localization + $email_subject = sprintf ( + 'Issue #%d - owner change from %s to %s in %s', + $issueid, $old_state->owner, $change->owner, $projectid + ); + + $email_message = $issue_url_base . '/' . $this->converter->AsciiToHex((string)$issueid) . "\r\n" . $email_subject; + $this->projects->emailMessageToMembers ( + $projectid, $this->login, $email_subject, $email_message + ); + } } } } diff --git a/codepot/src/codepot/models/issuemodel.php b/codepot/src/codepot/models/issuemodel.php index 9828c007..1b788a46 100644 --- a/codepot/src/codepot/models/issuemodel.php +++ b/codepot/src/codepot/models/issuemodel.php @@ -269,7 +269,7 @@ class IssueModel extends Model return $result[0]; } - function change ($userid, $project, $id, $change, $disallow_state_change) + function change ($userid, $project, $id, $change, $disallow_state_change, &$old_state) { $now = codepot_nowtodbdate(); @@ -289,29 +289,29 @@ class IssueModel extends Model $maxsno = (empty($result) || $result[0] == NULL)? 0: $result[0]->maxsno; $newsno = $maxsno + 1; - if ($change->comment == '' || $disallow_state_change) + $this->db->where ('projectid', $project->id); + $this->db->where ('id', $id); + $this->db->where ('sno', $maxsno); + $this->db->select('type,status,owner,priority'); + $query = $this->db->get ('issue_change'); + if ($this->db->trans_status() === FALSE) { - $this->db->where ('projectid', $project->id); - $this->db->where ('id', $id); - $this->db->where ('sno', $maxsno); - $this->db->select('type,status,owner,priority'); - $query = $this->db->get ('issue_change'); - if ($this->db->trans_status() === FALSE) - { - $this->errmsg = $this->db->_error_message(); - $this->db->trans_rollback (); - return FALSE; - } + $this->errmsg = $this->db->_error_message(); + $this->db->trans_rollback (); + return FALSE; + } - $result = $query->result(); - if (!empty($result)) + $result = $query->result(); + if (!empty($result)) + { + $old_state = $result[0]; + if ($change->comment == '' || $disallow_state_change) { - $c = $result[0]; - if ($c->type == $change->type && - $c->status == $change->status && - $c->owner == $change->owner && - $c->priority == $change->priority) + if ($old_state->type == $change->type && + $old_state->status == $change->status && + $old_state->owner == $change->owner && + $old_state->priority == $change->priority) { if ($change->comment == '') { diff --git a/codepot/src/codepot/views/issue_show.php b/codepot/src/codepot/views/issue_show.php index 773007cb..35a907e0 100644 --- a/codepot/src/codepot/views/issue_show.php +++ b/codepot/src/codepot/views/issue_show.php @@ -694,6 +694,8 @@ $(function () { var form_data = new FormData(); + form_data.append ('issue_url_base', codepot_merge_path('', 'id}"; ?>')); + form_data.append ('issue_change_type', $('#issue_change_type').val()); form_data.append ('issue_change_status', $('#issue_change_status').val()); form_data.append ('issue_change_priority', $('#issue_change_priority').val());