/** * 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); } } }
/** * GET /issues/@id/history * AJAX call for issue history * * @param \Base $f3 * @param array $params */ public function single_history($f3, $params) { // Build updates array $updates_array = array(); $update_model = new \Model\Custom("issue_update_detail"); $updates = $update_model->find(array("issue_id = ?", $params["id"]), array("order" => "created_date DESC")); foreach ($updates as $update) { $update_array = $update->cast(); $update_field_model = new \Model\Issue\Update\Field(); $update_array["changes"] = $update_field_model->find(array("issue_update_id = ?", $update["id"])); $updates_array[] = $update_array; } $f3->set("updates", $updates_array); $this->_printJson(array("total" => count($updates), "html" => $this->_cleanJson(\Helper\View::instance()->render("issues/single/history.html")))); }