Exemple #1
0
 /**
  * Send an email to watchers detailing the updated fields
  * @param  int $issue_id
  * @param  int $update_id
  */
 public function issue_update($issue_id, $update_id)
 {
     $f3 = \Base::instance();
     if ($f3->get("mail.from")) {
         $log = new \Log("mail.log");
         // Get issue and update data
         $issue = new \Model\Issue();
         $issue->load($issue_id);
         $f3->set("issue", $issue);
         $update = new \Model\Custom("issue_update_detail");
         $update->load($update_id);
         // Get issue parent if set
         if ($issue->parent_id) {
             $parent = new \Model\Issue();
             $parent->load($issue->parent_id);
             $f3->set("parent", $parent);
         }
         // Avoid errors from bad calls
         if (!$issue->id || !$update->id) {
             return false;
         }
         $changes = new \Model\Issue\Update\Field();
         $f3->set("changes", $changes->find(array("issue_update_id = ?", $update->id)));
         // Get recipient list and remove update user
         $recipients = $this->_issue_watchers($issue_id);
         $recipients = array_diff($recipients, array($update->user_email));
         // Render message body
         $f3->set("issue", $issue);
         $f3->set("update", $update);
         $text = $this->_render("notification/update.txt");
         $body = $this->_render("notification/update.html");
         $changes->load(array("issue_update_id = ? AND `field` = 'closed_date' AND old_value = '' and new_value != ''", $update->id));
         if ($changes && $changes->id) {
             $subject = "[#{$issue->id}] - {$issue->name} closed";
         } else {
             $subject = "[#{$issue->id}] - {$issue->name} updated";
         }
         // Send to recipients
         foreach ($recipients as $recipient) {
             $this->utf8mail($recipient, $subject, $body, $text);
             $log->write("Sent update notification to: " . $recipient);
         }
     }
 }