예제 #1
0
 public function runTransitionIssues(framework\Request $request)
 {
     try {
         try {
             $transition = entities\WorkflowTransition::getB2DBTable()->selectById($request['transition_id']);
         } catch (\Exception $e) {
             $this->getResponse()->setHttpStatus(400);
             return $this->renderJSON(array('error' => $this->getI18n()->__('This is not a valid transition')));
         }
         $issue_ids = $request['issue_ids'];
         $status = null;
         $closed = false;
         foreach ($issue_ids as $issue_id) {
             $issue = entities\Issue::getB2DBTable()->selectById((int) $issue_id);
             if (!$issue->isWorkflowTransitionsAvailable() || !$transition->validateFromRequest($request)) {
                 $this->getResponse()->setHttpStatus(400);
                 return $this->renderJSON(array('error' => framework\Context::getI18n()->__('The transition could not be applied to issue %issue_number because of %errors', array('%issue_number' => $issue->getFormattedIssueNo(), '%errors' => join(', ', $transition->getValidationErrors())))));
             }
             try {
                 $transition->transitionIssueToOutgoingStepFromRequest($issue, $request);
             } catch (\Exception $e) {
                 $this->getResponse()->setHttpStatus(400);
                 framework\Logging::log(framework\Logging::LEVEL_WARNING, 'Transition ' . $transition->getID() . ' failed for issue ' . $issue_id);
                 framework\Logging::log(framework\Logging::LEVEL_WARNING, $e->getMessage());
                 return $this->renderJSON(array('error' => $this->getI18n()->__('The transition failed because of an error in the workflow. Check your workflow configuration.')));
             }
             if ($status === null) {
                 $status = $issue->getStatus();
             }
             $closed = $issue->isClosed();
         }
         framework\Context::loadLibrary('common');
         $options = array('issue_ids' => array_keys($issue_ids), 'last_updated' => tbg_formatTime(time(), 20), 'closed' => $closed);
         $options['status'] = array('color' => $status->getColor(), 'name' => $status->getName(), 'id' => $status->getID());
         if ($request->hasParameter('milestone_id')) {
             $milestone = new entities\Milestone($request['milestone_id']);
             $options['milestone_id'] = $milestone->getID();
             $options['milestone_name'] = $milestone->getName();
         }
         foreach (array('resolution', 'priority', 'category', 'severity') as $item) {
             $class = "\\thebuggenie\\core\\entities\\" . ucfirst($item);
             if ($request->hasParameter($item . '_id')) {
                 if ($item_id = $request[$item . '_id']) {
                     $itemobject = new $class($item_id);
                     $itemname = $itemobject->getName();
                 } else {
                     $item_id = 0;
                     $itemname = '-';
                 }
                 $options[$item] = array('name' => $itemname, 'id' => $item_id);
             } else {
                 $method = 'get' . ucfirst($item);
                 $itemname = $issue->{$method}() instanceof $class ? $issue->{$method}()->getName() : '-';
                 $item_id = $issue->{$method}() instanceof $class ? $issue->{$method}()->getID() : 0;
                 $options[$item] = array('name' => $itemname, 'id' => $item_id);
             }
         }
         return $this->renderJSON($options);
     } catch (\Exception $e) {
         $this->getResponse()->setHttpStatus(400);
         framework\Logging::log(framework\Logging::LEVEL_WARNING, $e->getMessage());
         return $this->renderJSON(array('error' => $this->getI18n()->__('An error occured when trying to apply the transition')));
     }
 }
예제 #2
0
 public function runBulkUpdateIssues(framework\Request $request)
 {
     $issue_ids = $request['issue_ids'];
     $options = array('issue_ids' => array_values($issue_ids));
     framework\Context::loadLibrary('common');
     $options['last_updated'] = tbg_formatTime(time(), 20);
     if (!empty($issue_ids)) {
         $options['bulk_action'] = $request['bulk_action'];
         switch ($request['bulk_action']) {
             case 'assign_milestone':
                 $milestone = null;
                 if ($request['milestone'] == 'new') {
                     $milestone = new entities\Milestone();
                     $milestone->setProject(framework\Context::getCurrentProject());
                     $milestone->setName($request['milestone_name']);
                     $milestone->save();
                     $options['milestone_url'] = framework\Context::getRouting()->generate('agile_milestone', array('project_key' => $milestone->getProject()->getKey(), 'milestone_id' => $milestone->getID()));
                 } elseif ($request['milestone']) {
                     $milestone = new entities\Milestone($request['milestone']);
                 }
                 $milestone_id = $milestone instanceof entities\Milestone ? $milestone->getID() : null;
                 foreach (array_keys($issue_ids) as $issue_id) {
                     if (is_numeric($issue_id)) {
                         $issue = new entities\Issue($issue_id);
                         $issue->setMilestone($milestone_id);
                         $issue->save();
                     }
                 }
                 $options['milestone_id'] = $milestone_id;
                 $options['milestone_name'] = $milestone_id ? $milestone->getName() : '-';
                 break;
             case 'set_status':
                 if (is_numeric($request['status'])) {
                     $status = new entities\Status($request['status']);
                     foreach (array_keys($issue_ids) as $issue_id) {
                         if (is_numeric($issue_id)) {
                             $issue = new entities\Issue($issue_id);
                             $issue->setStatus($status->getID());
                             $issue->save();
                         }
                     }
                     $options['status'] = array('color' => $status->getColor(), 'name' => $status->getName(), 'id' => $status->getID());
                 }
                 break;
             case 'set_severity':
                 if (is_numeric($request['severity'])) {
                     $severity = $request['severity'] ? new entities\Severity($request['severity']) : null;
                     foreach (array_keys($issue_ids) as $issue_id) {
                         if (is_numeric($issue_id)) {
                             $issue = new entities\Issue($issue_id);
                             $severity_id = $severity instanceof entities\Severity ? $severity->getID() : 0;
                             $issue->setSeverity($severity_id);
                             $issue->save();
                         }
                     }
                     $options['severity'] = array('name' => $severity instanceof entities\Severity ? $severity->getName() : '-', 'id' => $severity instanceof entities\Severity ? $severity->getID() : 0);
                 }
                 break;
             case 'set_resolution':
                 if (is_numeric($request['resolution'])) {
                     $resolution = $request['resolution'] ? new entities\Resolution($request['resolution']) : null;
                     foreach (array_keys($issue_ids) as $issue_id) {
                         if (is_numeric($issue_id)) {
                             $issue = new entities\Issue($issue_id);
                             $resolution_id = $resolution instanceof entities\Resolution ? $resolution->getID() : 0;
                             $issue->setResolution($resolution_id);
                             $issue->save();
                         }
                     }
                     $options['resolution'] = array('name' => $resolution instanceof entities\Resolution ? $resolution->getName() : '-', 'id' => $resolution instanceof entities\Resolution ? $resolution->getID() : 0);
                 }
                 break;
             case 'set_priority':
                 if (is_numeric($request['priority'])) {
                     $priority = $request['priority'] ? new entities\Priority($request['priority']) : null;
                     foreach (array_keys($issue_ids) as $issue_id) {
                         if (is_numeric($issue_id)) {
                             $issue = new entities\Issue($issue_id);
                             $priority_id = $priority instanceof entities\Priority ? $priority->getID() : 0;
                             $issue->setPriority($priority_id);
                             $issue->save();
                         }
                     }
                     $options['priority'] = array('name' => $priority instanceof entities\Priority ? $priority->getName() : '-', 'id' => $priority instanceof entities\Priority ? $priority->getID() : 0);
                 }
                 break;
             case 'set_category':
                 if (is_numeric($request['category'])) {
                     $category = $request['category'] ? new entities\Category($request['category']) : null;
                     foreach (array_keys($issue_ids) as $issue_id) {
                         if (is_numeric($issue_id)) {
                             $issue = new entities\Issue($issue_id);
                             $category_id = $category instanceof entities\Category ? $category->getID() : 0;
                             $issue->setCategory($category_id);
                             $issue->save();
                         }
                     }
                     $options['category'] = array('name' => $category instanceof entities\Category ? $category->getName() : '-', 'id' => $category instanceof entities\Category ? $category->getID() : 0);
                 }
                 break;
         }
     }
     return $this->renderJSON($options);
 }