예제 #1
0
 /**
  * @param \Base $f3
  * @throws \Exception
  */
 public function edit($f3)
 {
     $post = $f3->get("POST");
     $issue = new \Model\Issue();
     $issue->load($post["itemId"]);
     $issue->sprint_id = empty($post["reciever"]["receiverId"]) ? null : $post["reciever"]["receiverId"];
     $issue->save();
     $this->_printJson($issue);
 }
예제 #2
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);
         }
     }
 }
예제 #3
0
 /**
  * Update an existing task
  */
 public function edit($f3, $params)
 {
     $post = $f3->get("POST");
     $issue = new \Model\Issue();
     $issue->load($post["taskId"]);
     if (!empty($post["receiver"])) {
         if ($post["receiver"]["story"]) {
             $issue->parent_id = $post["receiver"]["story"];
         }
         $issue->status = $post["receiver"]["status"];
         $status = new \Model\Issue\Status();
         $status->load($issue->status);
         if ($status->closed) {
             if (!$issue->closed_date) {
                 $issue->closed_date = $this->now();
             }
         } else {
             $issue->closed_date = null;
         }
     } else {
         $issue->name = $post["title"];
         $issue->description = $post["description"];
         $issue->owner_id = $post["assigned"];
         $issue->hours_remaining = $post["hours"];
         $issue->hours_spent += $post["hours_spent"];
         if (!empty($post["hours_spent"]) && !empty($post["burndown"])) {
             $issue->hours_remaining -= $post["hours_spent"];
         }
         if ($issue->hours_remaining < 0) {
             $issue->hours_remaining = 0;
         }
         if (!empty($post["dueDate"])) {
             $issue->due_date = date("Y-m-d", strtotime($post["dueDate"]));
         } else {
             $issue->due_date = null;
         }
         if (!empty($post["repeat_cycle"])) {
             $issue->repeat_cycle = $post["repeat_cycle"];
         }
         $issue->priority = $post["priority"];
         if (!empty($post["storyId"])) {
             $issue->parent_id = $post["storyId"];
         }
         $issue->title = $post["title"];
     }
     if (!empty($post["comment"])) {
         $comment = new \Model\Issue\Comment();
         $comment->user_id = $this->_userId;
         $comment->issue_id = $issue->id;
         if (!empty($post["hours_spent"])) {
             $comment->text = trim($post["comment"]) . sprintf(" (%s %s spent)", $post["hours_spent"], $post["hours_spent"] == 1 ? "hour" : "hours");
         } else {
             $comment->text = $post["comment"];
         }
         $comment->created_date = $this->now();
         $comment->save();
         $issue->update_comment = $comment->id;
     }
     $issue->save();
     $this->_printJson($issue->cast() + array("taskId" => $issue->id));
 }
예제 #4
0
 foreach ($header->to as $to_email) {
     $to = $to_email->mailbox . "@" . $to_email->host;
     $to_user->load(array('email = ? AND deleted_date IS NULL', $to));
     if (!empty($to_user->id)) {
         $owner = $to_user->id;
         break;
     } else {
         $owner = $from_user->id;
     }
 }
 // Find issue IDs in subject
 preg_match("/\\[#([0-9]+)\\] -/", $header->subject, $matches);
 // Get issue instance
 $issue = new \Model\Issue();
 if (!empty($matches[1])) {
     $issue->load(intval($matches[1]));
 }
 if (!$issue->id) {
     $subject = trim(preg_replace("/^((Re|Fwd?):\\s)*/i", "", $header->subject));
     $issue->load(array('name=? AND deleted_date IS NULL AND closed_date IS NULL', $subject));
 }
 if ($issue->id) {
     if (trim($text)) {
         $comment = \Model\Issue\Comment::create(array('user_id' => $from_user->id, 'issue_id' => $issue->id, 'text' => $text));
         $log->write(sprintf("Added comment %s on issue #%s - %s", $comment->id, $issue->id, $issue->name));
     }
 } else {
     $issue = \Model\Issue::create(array('name' => $header->subject, 'description' => $text, 'author_id' => $from_user->id, 'owner_id' => $owner, 'status' => 1, 'type_id' => 1));
     $log->write(sprintf("Created issue #%s - %s", $issue->id, $issue->name));
 }
 // Add other recipients as watchers
예제 #5
0
<?php

/**
 * Tests the Issue model's core functionality
 * @package  Test
 * @author   Alan Hardman <*****@*****.**>
 */
require_once "base.php";
$test = new Test();
$issue = new Model\Issue();
$test->expect($issue->load(1) && $issue->id == 1, "Issue->load() by Integer");
$test->expect($issue->load(array('id = ?', 1)) && $issue->id == 1, "Issue->load() by String");
$test->expect(is_array($issue->getChildren()), "Issue->getChildren()");
$test->expect(is_array($issue->getAncestors()), "Issue->getAncestors()");
$test->expect($issue->save(false) && $issue->id, "Issue->save() without notifications");
// Output results
showResults($test);
예제 #6
0
 $author = $user->id;
 // find an owner from the recipients
 foreach ($header->to as $owner_email) {
     $user->reset();
     $to = $owner_email->mailbox . "@" . $owner_email->host;
     $user->load(array('email=?', $to));
     if (!empty($user->id)) {
         $owner = $user->id;
         break;
     } else {
         $owner = $author;
     }
 }
 preg_match("/\\[#([0-9]+)\\] -/", $header->subject, $matches);
 $issue = new \Model\Issue();
 !empty($matches[1]) ? $issue->load($matches[1]) : '';
 // post a comment if replying to an issue
 if (!empty($issue->id)) {
     if (!empty($message)) {
         $comment = new \Model\Issue\Comment();
         $comment->user_id = $author;
         $comment->issue_id = $issue->id;
         $comment->text = html_entity_decode(strip_tags($message));
         $comment->created_date = date("Y-m-d H:i:s");
         $comment->save();
         $notification = \Helper\Notification::instance();
         $notification->issue_comment($issue->id, $comment->id);
     }
 } else {
     if (!empty($header->subject)) {
         $subject = trim(preg_replace("/^((Re|Fwd?):\\s)*/i", "", $header->subject));
예제 #7
0
파일: issues.php 프로젝트: Rayne/phproject
 /**
  * POST /issues/upload
  * Upload a file
  *
  * @param \Base $f3
  * @param array $params
  * @throws \Exception
  */
 public function upload($f3, $params)
 {
     $user_id = $this->_userId;
     $issue = new \Model\Issue();
     $issue->load(array("id=? AND deleted_date IS NULL", $f3->get("POST.issue_id")));
     if (!$issue->id) {
         $f3->error(404);
         return;
     }
     $web = \Web::instance();
     $f3->set("UPLOADS", "uploads/" . date("Y") . "/" . date("m") . "/");
     if (!is_dir($f3->get("UPLOADS"))) {
         mkdir($f3->get("UPLOADS"), 0777, true);
     }
     $overwrite = false;
     // set to true to overwrite an existing file; Default: false
     $slug = true;
     // rename file to filesystem-friendly version
     // Make a good name
     $orig_name = preg_replace("/[^A-Z0-9._-]/i", "_", $_FILES['attachment']['name']);
     $_FILES['attachment']['name'] = time() . "_" . $orig_name;
     $i = 0;
     $parts = pathinfo($_FILES['attachment']['name']);
     while (file_exists($f3->get("UPLOADS") . $_FILES['attachment']['name'])) {
         $i++;
         $_FILES['attachment']['name'] = $parts["filename"] . "-" . $i . "." . $parts["extension"];
     }
     $web->receive(function ($file) use($f3, $orig_name, $user_id, $issue) {
         if ($file['size'] > $f3->get("files.maxsize")) {
             return false;
         }
         $newfile = new \Model\Issue\File();
         $newfile->issue_id = $issue->id;
         $newfile->user_id = $user_id;
         $newfile->filename = $orig_name;
         $newfile->disk_filename = $file['name'];
         $newfile->disk_directory = $f3->get("UPLOADS");
         $newfile->filesize = $file['size'];
         $newfile->content_type = $file['type'];
         $newfile->digest = md5_file($file['tmp_name']);
         $newfile->created_date = date("Y-m-d H:i:s");
         $newfile->save();
         $f3->set('file_id', $newfile->id);
         return true;
         // moves file from php tmp dir to upload dir
     }, $overwrite, $slug);
     if ($f3->get("POST.text")) {
         $comment = new \Model\Issue\Comment();
         $comment->user_id = $this->_userId;
         $comment->issue_id = $issue->id;
         $comment->text = $f3->get("POST.text");
         $comment->created_date = $this->now();
         $comment->file_id = $f3->get('file_id');
         $comment->save();
         if (!!$f3->get("POST.notify")) {
             $notification = \Helper\Notification::instance();
             $notification->issue_comment($issue->id, $comment->id);
         }
     } elseif ($newfile->id && !!$f3->get("POST.notify")) {
         $notification = \Helper\Notification::instance();
         $notification->issue_file($issue->id, $f3->get("file_id"));
     }
     $f3->reroute("/issues/" . $issue->id);
 }
예제 #8
0
 public function single_comments_post($f3, $params)
 {
     $issue = new \Model\Issue();
     $issue->load($params["id"]);
     if (!$issue->id) {
         $f3->error(404);
         return;
     }
     $data = array("issue_id" => $issue->id, "user_id" => $this->_userId, "text" => $f3->get("POST.text"));
     $comment = \Model\Issue\Comment::create($data);
     $this->_printJson($comment->cast());
 }
예제 #9
0
 /**
  * Convert an issue ID to a name
  * @param int $id
  * @return string
  */
 public function convertIssueId($id)
 {
     if (isset($this->cache['issue.' . $id])) {
         $issue = $this->cache['issue.' . $id];
     } else {
         $issue = new \Model\Issue();
         $issue->load($id);
         $this->cache['issue.' . $id] = $issue;
     }
     return $issue->name;
 }
예제 #10
0
파일: issue.php 프로젝트: svenbw/phproject
 /**
  * Log issue update, send notifications
  * @param  boolean $notify
  * @return Issue
  */
 public function save($notify = true)
 {
     $f3 = \Base::instance();
     // Catch empty sprint at the lowest level here
     if ($this->get("sprint_id") === 0) {
         $this->set("sprint_id", null);
     }
     // Censor credit card numbers if enabled
     if ($f3->get("security.block_ccs")) {
         if (preg_match("/([0-9]{3,4}-){3}[0-9]{3,4}/", $this->get("description"))) {
             $this->set("description", preg_replace("/([0-9]{3,4}-){3}([0-9]{3,4})/", "************\$2", $this->get("description")));
         }
     }
     // Make dates correct
     if ($this->due_date) {
         $this->due_date = date("Y-m-d", strtotime($this->due_date));
     } else {
         $this->due_date = null;
     }
     if ($this->start_date) {
         $this->start_date = date("Y-m-d", strtotime($this->start_date));
     } else {
         $this->start_date = null;
     }
     // Check if updating or inserting
     if ($this->query) {
         // Save issue updates and send notifications
         $update = $this->_saveUpdate($notify);
         $issue = parent::save();
         if ($notify && $update && $update->id && $update->notify) {
             $notification = \Helper\Notification::instance();
             $notification->issue_update($this->get("id"), $update->id);
         }
     } else {
         // Move task to a sprint if the parent is in a sprint
         if ($this->get("parent_id") && !$this->get("sprint_id")) {
             $parent = new \Model\Issue();
             $parent->load($this->get("parent_id"));
             if ($parent->sprint_id) {
                 $this->set("sprint_id", $parent->sprint_id);
             }
         }
         // Save issue and send notifications
         $issue = parent::save();
         if ($notify) {
             $notification = \Helper\Notification::instance();
             $notification->issue_create($issue->id);
         }
         return $issue;
     }
     $this->saveTags();
     return empty($issue) ? parent::save() : $issue;
 }