示例#1
0
 /**
  * Create and save a new file, optionally sending notifications
  * @param  array $data
  * @param  bool  $notify
  * @return Comment
  */
 public static function create(array $data, $notify = true)
 {
     $item = parent::create($data);
     if ($notify) {
         $notification = \Helper\Notification::instance();
         $notification->issue_file($item->issue_id, $item->id);
     }
     return $item;
 }
示例#2
0
 /**
  * Create and save a new comment
  * @param  array $data
  * @param  bool  $notify
  * @return Comment
  */
 public static function create(array $data, $notify = true)
 {
     if (empty($data['text'])) {
         throw new \Exception("Comment text cannot be empty.");
     }
     $item = parent::create($data);
     if ($notify) {
         $notification = \Helper\Notification::instance();
         $notification->issue_comment($item->issue_id, $item->id);
     }
     return $item;
 }
示例#3
0
 public function reset($f3)
 {
     if ($f3->get("user.id")) {
         $f3->reroute("/");
     } else {
         if ($f3->get("POST.email")) {
             $user = new \Model\User();
             $user->load(array("email = ?", $f3->get("POST.email")));
             if ($user->id && !$user->deleted_date) {
                 $notification = \Helper\Notification::instance();
                 $notification->user_reset($user->id);
                 $f3->set("reset.success", "We've sent an email to " . $f3->get("POST.email") . " with a link to reset your password.");
             } else {
                 $f3->set("reset.error", "No user exists with the email address " . $f3->get("POST.email") . ".");
             }
         }
         unset($user);
         $this->_render("index/reset.html");
     }
 }
示例#4
0
         $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));
         $issue->load(array('name=? AND (deleted_date IS NULL OR deleted_date = "0000-00-00 00:00:00") AND (closed_date IS NULL OR closed_date = "0000-00-00 00:00:00")', $subject));
     }
     if (!empty($issue->id)) {
         $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 {
         $issue->name = $header->subject;
         $issue->description = html_entity_decode(strip_tags($message));
         $issue->author_id = $author;
         $issue->owner_id = $owner;
         $issue->type_id = 1;
         $issue->save();
         $log->write('Saved issue ' . $issue->id);
     }
 }
 if (!empty($issue->id)) {
     // add other recipients as watchers
     if (!empty($header->cc) || count($header->to) > 1) {
         if (!empty($header->cc)) {
示例#5
0
 /**
  * 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);
 }
示例#6
0
 /**
  * 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;
 }
示例#7
0
 public function post($f3)
 {
     if ($_REQUEST) {
         // By default, use standard HTTP POST fields
         $post = $_REQUEST;
     } else {
         // For Redmine compatibility, also accept a JSON object
         try {
             $post = json_decode(file_get_contents('php://input'), true);
         } catch (Exception $e) {
             throw new Exception("Unable to parse input");
         }
         if (!empty($post["issue"])) {
             $post = $post["issue"];
         }
         // Convert Redmine names to Phproject names
         if (!empty($post["subject"])) {
             $post["name"] = $post["subject"];
         }
         if (!empty($post["parent_issue_id"])) {
             $post["parent_id"] = $post["parent_issue_id"];
         }
         if (!empty($post["tracker_id"])) {
             $post["type_id"] = $post["tracker_id"];
         }
         if (!empty($post["assigned_to_id"])) {
             $post["owner_id"] = $post["assigned_to_id"];
         }
         if (!empty($post["fixed_version_id"])) {
             $post["sprint_id"] = $post["fixed_version_id"];
         }
     }
     // Ensure a status ID is added
     if (!empty($post["status_id"])) {
         $post["status"] = $post["status_id"];
     }
     if (empty($post["status"])) {
         $post["status"] = 1;
     }
     // Verify the required "name" field is passed
     if (empty($post["name"])) {
         $f3->error("The 'name' value is required.");
         return;
     }
     // Verify given values are valid (types, statueses, priorities)
     if (!empty($post["type_id"])) {
         $type = new \Model\Issue\Type();
         $type->load($post["type_id"]);
         if (!$type->id) {
             $f3->error("The 'type_id' field is not valid.");
             return;
         }
     }
     if (!empty($post["parent_id"])) {
         $parent = new \Model\Issue();
         $parent->load($post["parent_id"]);
         if (!$parent->id) {
             $f3->error("The 'type_id' field is not valid.");
             return;
         }
     }
     if (!empty($post["status"])) {
         $status = new \Model\Issue\Status();
         $status->load($post["status"]);
         if (!$status->id) {
             $f3->error("The 'status' field is not valid.");
             return;
         }
     }
     if (!empty($post["priority_id"])) {
         $priority = new \Model\Issue\Priority();
         $priority->load(array("value" => $post["priority_id"]));
         if (!$priority->id) {
             $f3->error("The 'priority_id' field is not valid.");
             return;
         }
     }
     // Create a new issue based on the data
     $issue = new \Model\Issue();
     $issue->author_id = !empty($post["author_id"]) ? $post["author_id"] : $this->_userId;
     $issue->name = trim($post["name"]);
     $issue->type_id = empty($post["type_id"]) ? 1 : $post["type_id"];
     $issue->priority_id = empty($post["priority_id"]) ? $f3->get("issue_priority.default") : $post["priority_id"];
     $issue->status = empty($status) ? 1 : $status->id;
     // Set due date if valid
     if (!empty($post["due_date"]) && preg_match("/^[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}( [0-9:]{8})?\$/", $post["due_date"])) {
         $issue->due_date = $post["due_date"];
     } elseif (!empty($post["due_date"]) && ($due_date = strtotime($post["due_date"]))) {
         $issue->due_date = date("Y-m-d", $due_date);
     }
     if (!empty($post["description"])) {
         $issue->description = $post["description"];
     }
     if (!empty($post["parent_id"])) {
         $issue->parent_id = $post["parent_id"];
     }
     if (!empty($post["owner_id"])) {
         $issue->owner_id = $post["owner_id"];
     }
     $issue->save();
     $notification = \Helper\Notification::instance();
     $notification->issue_create($issue->id);
     $this->_printJson(array("issue" => $issue->cast()));
 }
示例#8
0
文件: issue.php 项目: Rayne/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->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->description)) {
             $this->set("description", preg_replace("/([0-9]{3,4}-){3}([0-9]{3,4})/", "************\$2", $this->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->id, $update->id);
         }
     } else {
         // Set closed date if status is closed
         if (!$this->closed_date && $this->status) {
             $status = new Issue\Status();
             $status->load($this->status);
             if ($status->closed) {
                 $this->closed_date = date("Y-m-d H:i:s");
             }
         }
     }
     $return = empty($issue) ? parent::save() : $issue;
     $this->saveTags();
     return $return;
 }