diff --git a/src/IDF/Issue.php b/src/IDF/Issue.php index 9341947..5dd57c2 100644 --- a/src/IDF/Issue.php +++ b/src/IDF/Issue.php @@ -136,7 +136,7 @@ class IDF_Issue extends Pluf_Model } - function preSave() + function preSave($create=false) { if ($this->id == '') { $this->creation_dtime = gmdate('Y-m-d H:i:s'); @@ -144,7 +144,7 @@ class IDF_Issue extends Pluf_Model $this->modif_dtime = gmdate('Y-m-d H:i:s'); } - function postSave() + function postSave($create=false) { // This will be used to fire the indexing or send a // notification email to the interested people, etc. diff --git a/src/IDF/IssueComment.php b/src/IDF/IssueComment.php index 65ff644..cb9d79a 100644 --- a/src/IDF/IssueComment.php +++ b/src/IDF/IssueComment.php @@ -90,7 +90,7 @@ class IDF_IssueComment extends Pluf_Model function changedIssue() { - return count($this->changes) > 0; + return (is_array($this->changes) and count($this->changes) > 0); } function _toIndex() @@ -98,14 +98,14 @@ class IDF_IssueComment extends Pluf_Model return $this->content; } - function preSave() + function preSave($create=false) { if ($this->id == '') { $this->creation_dtime = gmdate('Y-m-d H:i:s'); } } - function postSave() + function postSave($create=false) { // This will be used to fire the indexing or send a // notification email to the interested people, etc. diff --git a/src/IDF/Project.php b/src/IDF/Project.php index f1d946e..06fcb54 100644 --- a/src/IDF/Project.php +++ b/src/IDF/Project.php @@ -90,7 +90,7 @@ class IDF_Project extends Pluf_Model } - function preSave() + function preSave($create=false) { if ($this->id == '') { $this->creation_dtime = gmdate('Y-m-d H:i:s'); diff --git a/src/IDF/Tag.php b/src/IDF/Tag.php index 30703ff..3c44bfb 100644 --- a/src/IDF/Tag.php +++ b/src/IDF/Tag.php @@ -89,7 +89,7 @@ class IDF_Tag extends Pluf_Model ); } - function preSave() + function preSave($create=false) { $this->lcname = mb_strtolower($this->name); } diff --git a/src/IDF/Upload.php b/src/IDF/Upload.php index 4af3e28..2b80c04 100644 --- a/src/IDF/Upload.php +++ b/src/IDF/Upload.php @@ -133,7 +133,7 @@ class IDF_Upload extends Pluf_Model return ''; } - function preSave() + function preSave($create=false) { if ($this->id == '') { $this->creation_dtime = gmdate('Y-m-d H:i:s'); diff --git a/src/IDF/Views/Issue.php b/src/IDF/Views/Issue.php index 7e4a361..6ddb8f2 100644 --- a/src/IDF/Views/Issue.php +++ b/src/IDF/Views/Issue.php @@ -144,6 +144,24 @@ class IDF_Views_Issue $urlissue = Pluf_HTTP_URL_urlForView('IDF_Views_Issue::view', array($prj->shortname, $issue->id)); $request->user->setMessage(sprintf(__('Issue %d has been created.'), $urlissue, $issue->id)); + if (null != $issue->get_owner() and $issue->owner != $issue->submitter) { + $comments = $issue->get_comments_list(array('order' => 'id ASC')); + $context = new Pluf_Template_Context( + array( + 'issue' => $issue, + 'comment' => $comments[0], + 'project' => $prj, + 'url_base' => Pluf::f('url_base'), + ) + ); + $oemail = $issue->get_owner()->email; + $email = new Pluf_Mail(Pluf::f('from_email'), $oemail, + sprintf(__('Issue %s - %s (InDefero)'), + $issue->id, $issue->summary)); + $tmpl = new Pluf_Template('issues/issue-created-email.txt'); + $email->addTextMessage($tmpl->render($context)); + $email->sendMail(); + } return new Pluf_HTTP_Response_Redirect($url); } } else { @@ -186,6 +204,38 @@ class IDF_Views_Issue $urlissue = Pluf_HTTP_URL_urlForView('IDF_Views_Issue::view', array($prj->shortname, $issue->id)); $request->user->setMessage(sprintf(__('Issue %d has been updated.'), $urlissue, $issue->id)); + // Get the list of interested person + owner + submitter + $interested = $issue->get_interested_list(); + if (!Pluf_Model_InArray($issue->get_submitter(), $interested)) { + $interested[] = $issue->get_submitter(); + } + if (null != $issue->get_owner() and + !Pluf_Model_InArray($issue->get_owner(), $interested)) { + $interested[] = $issue->get_owner(); + } + $comments = $issue->get_comments_list(array('order' => 'id DESC')); + $context = new Pluf_Template_Context( + array( + 'issue' => $issue, + 'comments' => $comments, + 'project' => $prj, + 'url_base' => Pluf::f('url_base'), + ) + ); + $tmpl = new Pluf_Template('issues/issue-updated-email.txt'); + $text_email = $tmpl->render($context); + $email = new Pluf_Mail_Batch(Pluf::f('from_email')); + foreach ($interested as $user) { + if ($user->id != $request->user->id) { + $email->setSubject(sprintf(__('Updated Issue %s - %s (InDefero)'), + $issue->id, $issue->summary)); + $email->setTo($user->email); + $email->setReturnPath(Pluf::f('from_email')); + $email->addTextMessage($text_email); + $email->sendMail(); + } + } + $email->close(); return new Pluf_HTTP_Response_Redirect($url); } } else { diff --git a/src/IDF/templates/issues/issue-created-email.txt b/src/IDF/templates/issues/issue-created-email.txt new file mode 100644 index 0000000..da8f3c2 --- /dev/null +++ b/src/IDF/templates/issues/issue-created-email.txt @@ -0,0 +1,18 @@ +{trans 'Hello,'} + +{blocktrans}A new issue has been created and assigned +to you:{/blocktrans} + +{$issue.id} - {$issue.summary|safe} +{trans 'Project:'} {$project.name|safe} +{trans 'Status:'} {$issue.get_status.name|safe} +{trans 'Reported by:'} {$issue.get_submitter|safe} +{assign $tags = $issue.get_tags_list()}{if $tags.count()}{trans 'Labels:'} +{foreach $tags as $tag} {$tag.class|safe}:{$tag.name|safe} +{/foreach}{/if} +{trans 'Description:'} + +{$comment.content|safe} + +-- +{trans 'Issue:'} {$url_base}{url 'IDF_Views_Issue::view', array($project.shortname, $issue.id)} diff --git a/src/IDF/templates/issues/issue-updated-email.txt b/src/IDF/templates/issues/issue-updated-email.txt new file mode 100644 index 0000000..d996aae --- /dev/null +++ b/src/IDF/templates/issues/issue-updated-email.txt @@ -0,0 +1,24 @@ +{trans 'Hello,'} + +{blocktrans}The following issue has been updated:{/blocktrans} + +{$issue.id} - {$issue.summary|safe} +{trans 'Project:'} {$project.name|safe} +{trans 'Status:'} {$issue.get_status.name} +{trans 'Reported by:'} {$issue.get_submitter|safe} +{trans 'URL:'} {$url_base}{url 'IDF_Views_Issue::view', array($project.shortname, $issue.id)} +{assign $tags = $issue.get_tags_list()}{if $tags.count()}{trans 'Labels:'} +{foreach $tags as $tag} {$tag.class|safe}:{$tag.name|safe} +{/foreach} +{/if}{trans 'Comments (last first):'} + +{foreach $comments as $c}{assign $who = $c.get_submitter()}# {blocktrans}By {$who|safe}, {$c.creation_dtime|date}:{/blocktrans} + +{if strlen($c.content) > 0}{$c.content|safe}{else}{trans '(No comments were given for this change.)'}{/if}{if $c.changedIssue()} +{foreach $c.changes as $w => $v} + {if $w == 'su'}{trans 'Summary:'}{/if}{if $w == 'st'}{trans 'Status:'}{/if}{if $w == 'ow'}{trans 'Owner:'}{/if}{if $w == 'lb'}{trans 'Labels:'}{/if} {if $w == 'lb'}{assign $l = implode(', ', $v)}{$l}{else}{$v}{/if}{/foreach}{/if} + +{/foreach} + +-- +{trans 'Issue:'} {$url_base}{url 'IDF_Views_Issue::view', array($project.shortname, $issue.id)}