示例#1
0
 /**
  * Send an email to watchers with the file info
  * @param  int $issue_id
  * @param  int $file_id
  */
 public function issue_file($issue_id, $file_id)
 {
     $f3 = \Base::instance();
     if ($f3->get("mail.from")) {
         $log = new \Log("mail.log");
         // Get issue and comment data
         $issue = new \Model\Issue();
         $issue->load($issue_id);
         $file = new \Model\Issue\File\Detail();
         $file->load($file_id);
         // This should catch a bug I can't currently find the source of. --Alan
         if ($file->issue_id != $issue->id) {
             return;
         }
         // Get issue parent if set
         if ($issue->parent_id) {
             $parent = new \Model\Issue();
             $parent->load($issue->parent_id);
             $f3->set("parent", $parent);
         }
         // Get recipient list and remove current user
         $recipients = $this->_issue_watchers($issue_id);
         $recipients = array_diff($recipients, array($file->user_email));
         // Render message body
         $f3->set("issue", $issue);
         $f3->set("file", $file);
         $text = $this->_render("notification/file.txt");
         $body = $this->_render("notification/file.html");
         $subject = "[#{$issue->id}] - {$file->user_name} attached a file to {$issue->name}";
         // Send to recipients
         foreach ($recipients as $recipient) {
             $this->utf8mail($recipient, $subject, $body, $text);
             $log->write("Sent file notification to: " . $recipient);
         }
     }
 }