From 8ec6d6233b531670b8be5dea0c14068f892b70a0 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Mon, 1 Sep 2008 20:10:12 -0400 Subject: [PATCH] Upgrade class_notification.php to use emails.php (untested) --- includes/class_notification.php | 93 +++++++++++++++++--------- includes/emails.php | 114 ++++++++++++++++++++++++++++++++ 2 files changed, 174 insertions(+), 33 deletions(-) diff --git a/includes/class_notification.php b/includes/class_notification.php index 5d24e98..0d76fd4 100644 --- a/includes/class_notification.php +++ b/includes/class_notification.php @@ -232,8 +232,9 @@ class NotificationCenter if ($this->users["$userid"]['options'][0] & bugdar::$emailOptions['notifications']['assignedto'] && in_array($userid, $this->roles['-notapplicable-'])) { $user = construct_user_display(bugdar::$userinfo, false); - eval('$part = "' . $this->registry->template->fetch(FetchEmailPath('notice_unassigned.part', $this->_localeFromUserId($userid))) . '";'); - $this->notices["$userid"][] = $part; + + $email = get_email_text('notice_unassigned'); + $this->notices["$userid"][] = sprintf($email['part'], $user); } } @@ -247,8 +248,9 @@ class NotificationCenter if ($this->users["$userid"]['options'][0] & bugdar::$emailOptions['notifications']['assignedto'] && in_array($userid, $this->roles['-notapplicable-'])) { $user = construct_user_display(bugdar::$userinfo, false); - eval('$email = "' . $this->registry->template->fetch(FetchEmailPath('notice_assigned.part', $this->_localeFromUserId($userid))) . '";'); - $this->notices["$userid"][] = $email; + + $email = get_email_text('notice_assigned'); + $this->notices["$userid"][] = sprintf($email['part'], $user); } } @@ -261,10 +263,14 @@ class NotificationCenter private function _noticeStatusChange($old, $new) { $userlist = $this->_fetchUsersWithOnBit('statusresolve'); + + $old = bugdar::$datastore['status'][$old]['status']; + $new = bugdar::$datastore['status'][$new]['status']; + foreach ($userlist as $userid => $user) { - eval('$email = "' . $this->registry->template->fetch(FetchEmailPath('notice_status.part', $this->_localeFromUserId($userid))) . '";'); - $this->notices["$user[userid]"][] = $email; + $email = get_email_text('notice_status'); + $this->notices["$user[userid]"][] = sprintf($email['part'], $new, $old); } } @@ -277,10 +283,14 @@ class NotificationCenter private function _noticeResolutionChange($old, $new) { $userlist = $this->_fetchUsersWithOnBit('statusresolve'); + + $old = bugdar::$datastore['resolution'][$old]['resolution']; + $new = bugdar::$datastore['resolution'][$new]['resolution']; + foreach ($userlist as $userid => $user) { - eval('$email = "' . $this->registry->template->fetch(FetchEmailPath('notice_resolution.part', $this->_localeFromUserId($userid))) . '";'); - $this->notices["$user[userid]"][] = $email; + $email = get_email_text('notice_resolution'); + $this->notices["$user[userid]"][] = sprintf($email['part'], $new, $old); } } @@ -293,10 +303,11 @@ class NotificationCenter private function _noticeDuplicatesChange($old, $new) { $userlist = $this->_fetchUsersWithOnBit('duplicates'); + foreach ($userlist as $userid => $user) { - eval('$email = "' . $this->registry->template->fetch(FetchEmailPath('notice_duplicates.part', $this->_localeFromUserId($userid))) . '";'); - $this->notices["$user[userid]"][] = $email; + $email = get_email_text('notice_duplicates'); + $this->notices["$user[userid]"][] = sprintf($email['part'], $old, $new); } } @@ -309,10 +320,13 @@ class NotificationCenter private function _noticeSeverityChange($old, $new) { $userlist = $this->_fetchUsersWithOnBit('otherfield'); + + $old = bugdar::$datastore['severity'][$old]['severity']; + $new = bugdar::$datastore['severity'][$new]['severity']; + foreach ($userlist as $userid => $user) { - eval('$email = "' . $this->registry->template->fetch(FetchEmailPath('notice_severity.part', $this->_localeFromUserId($userid))) . '";'); - $this->notices["$user[userid]"][] = $email; + $this->notices["$user[userid]"][] = sprintf($email['part'], $old, $new); } } @@ -325,10 +339,14 @@ class NotificationCenter private function _noticePriorityChange($old, $new) { $userlist = $this->_fetchUsersWithOnBit('otherfield'); + + $old = bugdar::$datastore['priority'][$old]['priority']; + $new = bugdar::$datastore['priority'][$new]['priority']; + foreach ($userlist as $userid => $user) { - eval('$email = "' . $this->registry->template->fetch(FetchEmailPath('notice_priority.part', $this->_localeFromUserId($userid))) . '";'); - $this->notices["$user[userid]"][] = $email; + $email = get_email_text('notice_priority'); + $this->notices["$user[userid]"][] = sprintf($email['part'], $old, $new); } } @@ -344,13 +362,16 @@ class NotificationCenter { $userlist = $this->_fetchUsersWithOnBit('otherfield'); - $old = bugdar::$datastore['product']["$old[0]"]['title'] . '/' . ($old[1] ? bugdar::$datastore['product']["$old[1]"]['title'] . '/' : '') . bugdar::$datastore['version']["$old[2]"]['version']; - $new = bugdar::$datastore['product']["$new[0]"]['title'] . '/' . ($new[1] ? bugdar::$datastore['product']["$new[1]"]['title'] . '/' : '') . bugdar::$datastore['version']["$new[2]"]['version']; + $products = &bugdar::$datastore['product']; + $versions = &bugdar::$datastore['version']; + + $old = $products[$old[0]]['title'] . '/' . ($old[1] ? $products[$old[1]]['title'] . '/' : '') . $versions[$old[2]]['version']; + $new = $products[$new[0]]['title'] . '/' . ($new[1] ? $products[$new[1]]['title'] . '/' : '') . $versions[$new[2]]['version']; foreach ($userlist as $userid => $user) { - eval('$email = "' . $this->registry->template->fetch(FetchEmailPath('notice_product.part', $this->_localeFromUserId($userid))) . '";'); - $this->notices["$user[userid]"][] = $email; + $email = get_email_text('notice_product'); + $this->notices["$user[userid]"][] = sprintf($email['part'], $old, $new); } } @@ -366,10 +387,10 @@ class NotificationCenter foreach ($userlist as $userid => $user) { $user = construct_user_display(bugdar::$userinfo, false); - $date = $this->registry->modules['date']->format(bugdar::$options['dateformat'], $comment['dateline']); + $date = BSApp::$date->format(bugdar::$options['dateformat'], $comment['dateline']); - eval('$email = "' . $this->registry->template->fetch(FetchEmailPath('notice_comment.part', $this->_localeFromUserId($userid))) . '";'); - $this->notices["$userid"][] = $email; + $email = get_email_text('notice_comment'); + $this->notices["$userid"][] = sprintf($email['part'], $user, $date, $comment['comment']); } } @@ -385,8 +406,8 @@ class NotificationCenter $userlist = $this->_fetchUsersWithOnBit('otherfield'); foreach ($userlist as $userid => $user) { - eval('$email = "' . $this->registry->template->fetch(FetchEmailPath('notice_other.part', $this->_localeFromUserId($userid))) . '";'); - $this->notices["$user[userid]"][] = $email; + $email = get_email_text('notice_other'); + $this->notices["$user[userid]"][] = sprintf($email['part'], $name, $old, $new); } } @@ -406,8 +427,8 @@ class NotificationCenter $user = construct_user_display(bugdar::$userinfo, false); $obsoletes = implode(', ', (array)$obsolete); - eval('$email = "' . $this->registry->template->fetch(FetchEmailPath('notice_attachment.part', $this->_localeFromUserId($userid))) . '";'); - $this->notices["$userid"][] = $email; + $email = get_email_text('notice_attachment'); + $this->notices["$userid"][] = sprintf($email['part'], $user, $attachment['filename'], $attachment['description'], $attachment['filesize'], $obsoletes, bugdar::$options['trackerurl'], $attachment['attachmentid']); } } @@ -436,8 +457,9 @@ class NotificationCenter $user = construct_user_display(bugdar::$userinfo, false); $this->users["$userInfo[userid]"] = $userInfo; $product = bugdar::$datastore['product']["$bug[product]"]['title'] . '/' . ($bug['component'] ? bugdar::$datastore['product']["$bug[component]"]['title'] . '/' : '') . bugdar::$datastore['version']["$bug[version]"]['version']; - eval('$email = "' . $this->registry->template->fetch(FetchEmailPath('notice_new_bug.part', $this->_localeFromUserId($userInfo['userid']))) . '";'); - $this->notices["$userInfo[userid]"][] = $email; + + $email = get_email_text('notice_new_bug'); + $this->notices["$userInfo[userid]"][] = sprintf($email['part'], $bug['bugid'], $bug['summary'], $user, $product, $comment['comment']); unset($this->users["$userInfo[userid]"]['mask'], $this->users["$userInfo[userid]"]['relation']); } $this->users["$userInfo[userid]"]['options']["$userInfo[relation]"] = $userInfo['mask']; @@ -472,7 +494,7 @@ class NotificationCenter $return = array(); foreach ($masters as $userid) { - $return["$userid"] =& $this->users["$userid"]; + $return["$userid"] = &$this->users["$userid"]; } return $return; @@ -502,14 +524,19 @@ class NotificationCenter $parts = implode("\n\n", $noticelist); - eval('$email = "' . $this->registry->template->fetch(FetchEmailPath('bugnotification.xml', $this->_localeFromUserId($userid))) . '";'); - $email = $this->registry->xml->parse($email, true); - $this->registry->mail->setSubject($email['email']['subject']['value']); - $this->registry->mail->setBodyText($email['email']['bodyText']['value']); + $email = get_email_text('bug_notification'); + + $body = sprintf($email['bodyText'], $this->users[$userid]['displayname'], bugdar::$options['trackertitle'], $this->bug['summary'], $this->bug['bugid'], bugdar::$options['trackerurl'], $parts); + + $mail = new BSMail(); + $mail->setSubject(sprintf($email['subject'], bugdar::$options['trackertitle'], $this->bug['summary'])); + $mail->setBodyText($body); + $mail->setFromAddress(MAIL_FROM_ADDRESS); + $mail->setFromName(MAIL_FROM_NAME); if (!empty($this->users["$userid"]['email'])) { - $this->registry->mail->send($this->users["$userid"]['email'], $this->users["$userid"]['displayname']); + $mail->send($this->users["$userid"]['email'], $this->users["$userid"]['displayname']); } else { diff --git a/includes/emails.php b/includes/emails.php index 98743be..d6d9d02 100644 --- a/includes/emails.php +++ b/includes/emails.php @@ -96,6 +96,120 @@ Here are the notices: If you no longer want to receive email from us, please log into your account and click the "My Controls" tab at the top of the screen to change email preferences. %5$s') + ), + + // assigned to bug + // vars + 'notice_assigned' => array( + 'part' => T('You have been assigned to this bug by %1$s.') + ), + + // unassigned from bug + // vars: changer.displayname + 'notice_unassigned' => array( + 'part' => T('You are no longer assigned to this bug, per %1$s\'s changes.') + ), + + // status change + // vars: new, old + 'notice_status' => array( + 'part' => T('The status of the bug is now "%1$s", from "%2$s".') + ), + + // resolution change + // vars: new, old + 'notice_resolution' => array( + 'part' => T('This bug has been resolved with resolution "%1$s", from "%2$s".') + ), + + // duplicates list change + // vars: old, new + 'notice_duplicates' => array( + 'part' => T('The duplicates list has changed from "%1$s" to "%2$s".') + ), + + // severity change + // vars: old, new + 'notice_severity' => array( + 'part' => T('The severity has been elevated from "%1$s" to "%2$s".') + ), + + // priority change + // vars: old, new + 'notice_priority' => array( + 'part' => T('The priority has been elevatd from "%1$s" to "%2$s".') + ), + + // PCV change + // vars: old, new + 'notice_product' => array( + 'part' => T('The product, component, and version combination has changed from "%1$s" to "%2$s".') + ), + + // new comment + // vars: user, date, comment + 'notice_comment' => array( + 'part' => T('The following comment was added by %1$s on %2$s: +============================================ +%3$s +============================================') + ), + + // other change + // vars: field, old, new + 'notice_other' => array( + 'part' => T('The %1$s field changed from "%2$s" to "%3$s".') + ), + + // new attachment + // vars: username, filename, description, filesize, obsoletes, trackerurl, attachmentid + 'notice_attachment' => array( + 'part' => T('%1$s has uploaded a new attachment: +============================================ +File name: %2$s +Description: %3$s +File size: %4$d Bytes +Makes obsolete: %5$s +View: %6$s/viewattachment.php?attachmentid=%7$d +============================================') + ), + + // new bug + // vars: bugid, summary, reporter, product, initial comment + 'notice_new_bug' => array( + 'part' => T('This bug has been added to the database: +============================================ +Bug ID: %1$d +Summary: %2$s +Reporter: %3$s +Product/Component/Version: %4$s +Initial report: +-------------------------------------------- +%5$s +-------------------------------------------- +============================================') + ), + + // bug notification + // vars: trackertitle, bug.summary + // vars: displayname, trackertitle, bug.summary, bug.id, trackerurl, parts + 'bug_notification' => array( + 'subject' => T('%1$s Bug Notification - %2$s'), + 'bodyText' => T('Hi %1$s, + +You are receiving this email because you have opted to get notifications for the %2$s bug tracker. + +The bug is "%3$s" (id: %4$d) located at %4$s/showreport.php?bugid=%5$d + +Here are the notices: +################################################################### + +%6$s + +################################################################### +If you no longer want to receive email from us, please log into your account and click the "My Controls" tab at the top of the screen to change email preferences. + +%4$s') ) ); -- 2.22.5