Exemplo n.º 1
0
 public function runUpdateIssueDetails(framework\Request $request)
 {
     $this->forward403if(framework\Context::getCurrentProject()->isArchived());
     $this->error = false;
     try {
         $i18n = framework\Context::getI18n();
         $issue = entities\Issue::getIssueFromLink($request['issue_no']);
         if ($issue->getProject()->getID() != $this->selected_project->getID()) {
             throw new \Exception($i18n->__('This issue is not valid for this project'));
         }
         if (!$issue instanceof entities\Issue) {
             throw new \Exception($i18n->__('Cannot find this issue'));
         }
         $workflow_transition = null;
         if ($passed_transition = $request['workflow_transition']) {
             //echo "looking for transition ";
             $key = str_replace(' ', '', mb_strtolower($passed_transition));
             //echo $key . "\n";
             foreach ($issue->getAvailableWorkflowTransitions() as $transition) {
                 //echo str_replace(' ', '', mb_strtolower($transition->getName())) . "?";
                 if (mb_strpos(str_replace(' ', '', mb_strtolower($transition->getName())), $key) !== false) {
                     $workflow_transition = $transition;
                     //echo "found transition " . $transition->getID();
                     break;
                 }
                 //echo "no";
             }
             if (!$workflow_transition instanceof entities\WorkflowTransition) {
                 throw new \Exception("This transition ({$key}) is not valid");
             }
         }
         $fields = $request->getRawParameter('fields', array());
         $return_values = array();
         if ($workflow_transition instanceof entities\WorkflowTransition) {
             foreach ($fields as $field_key => $field_value) {
                 $classname = "\\thebuggenie\\core\\entities\\" . ucfirst($field_key);
                 $method = "set" . ucfirst($field_key);
                 $choices = $classname::getAll();
                 $found = false;
                 foreach ($choices as $choice_key => $choice) {
                     if (mb_strpos(str_replace(' ', '', mb_strtolower($choice->getName())), str_replace(' ', '', mb_strtolower($field_value))) !== false) {
                         $request->setParameter($field_key . '_id', $choice->getId());
                         break;
                     }
                 }
             }
             $request->setParameter('comment_body', $request['message']);
             $return_values['applied_transition'] = $workflow_transition->getName();
             if ($workflow_transition->validateFromRequest($request)) {
                 $retval = $workflow_transition->transitionIssueToOutgoingStepFromRequest($issue, $request);
                 $return_values['transition_ok'] = $retval === false ? false : true;
             } else {
                 $return_values['transition_ok'] = false;
                 $return_values['message'] = "Please pass all information required for this transition";
             }
         } elseif ($issue->isUpdateable()) {
             foreach ($fields as $field_key => $field_value) {
                 try {
                     if (in_array($field_key, array_merge(array('title', 'state'), entities\Datatype::getAvailableFields(true)))) {
                         switch ($field_key) {
                             case 'state':
                                 $issue->setState($field_value == 'open' ? entities\Issue::STATE_OPEN : entities\Issue::STATE_CLOSED);
                                 break;
                             case 'title':
                                 if ($field_value != '') {
                                     $issue->setTitle($field_value);
                                 } else {
                                     throw new \Exception($i18n->__('Invalid title'));
                                 }
                                 break;
                             case 'shortname':
                             case 'description':
                             case 'reproduction_steps':
                                 $method = "set" . ucfirst($field_key);
                                 $issue->{$method}($field_value);
                                 break;
                             case 'status':
                             case 'resolution':
                             case 'reproducability':
                             case 'priority':
                             case 'severity':
                             case 'category':
                                 $classname = "\\thebuggenie\\core\\entities\\" . ucfirst($field_key);
                                 $method = "set" . ucfirst($field_key);
                                 $choices = $classname::getAll();
                                 $found = false;
                                 foreach ($choices as $choice_key => $choice) {
                                     if (str_replace(' ', '', mb_strtolower($choice->getName())) == str_replace(' ', '', mb_strtolower($field_value))) {
                                         $issue->{$method}($choice);
                                         $found = true;
                                     }
                                 }
                                 if (!$found) {
                                     throw new \Exception('Could not find this value');
                                 }
                                 break;
                             case 'percent_complete':
                                 $issue->setPercentCompleted($field_value);
                                 break;
                             case 'owner':
                             case 'assignee':
                                 $set_method = "set" . ucfirst($field_key);
                                 $unset_method = "un{$set_method}";
                                 switch (mb_strtolower($field_value)) {
                                     case 'me':
                                         $issue->{$set_method}(framework\Context::getUser());
                                         break;
                                     case 'none':
                                         $issue->{$unset_method}();
                                         break;
                                     default:
                                         try {
                                             $user = entities\User::findUser(mb_strtolower($field_value));
                                             if ($user instanceof entities\User) {
                                                 $issue->{$set_method}($user);
                                             }
                                         } catch (\Exception $e) {
                                             throw new \Exception('No such user found');
                                         }
                                         break;
                                 }
                                 break;
                             case 'estimated_time':
                             case 'spent_time':
                                 $set_method = "set" . ucfirst(str_replace('_', '', $field_key));
                                 $issue->{$set_method}($field_value);
                                 break;
                             case 'milestone':
                                 $found = false;
                                 foreach ($this->selected_project->getMilestones() as $milestone) {
                                     if (str_replace(' ', '', mb_strtolower($milestone->getName())) == str_replace(' ', '', mb_strtolower($field_value))) {
                                         $issue->setMilestone($milestone->getID());
                                         $found = true;
                                     }
                                 }
                                 if (!$found) {
                                     throw new \Exception('Could not find this milestone');
                                 }
                                 break;
                             default:
                                 throw new \Exception($i18n->__('Invalid field'));
                         }
                     }
                     $return_values[$field_key] = array('success' => true);
                 } catch (\Exception $e) {
                     $return_values[$field_key] = array('success' => false, 'error' => $e->getMessage());
                 }
             }
         }
         if (!$workflow_transition instanceof entities\WorkflowTransition) {
             $issue->getWorkflow()->moveIssueToMatchingWorkflowStep($issue);
         }
         if (!array_key_exists('transition_ok', $return_values) || $return_values['transition_ok']) {
             $comment = new entities\Comment();
             $comment->setContent($request->getParameter('message', null, false));
             $comment->setPostedBy(framework\Context::getUser()->getID());
             $comment->setTargetID($issue->getID());
             $comment->setTargetType(entities\Comment::TYPE_ISSUE);
             $comment->setModuleName('core');
             $comment->setIsPublic(true);
             $comment->setSystemComment(false);
             $comment->save();
             $issue->setSaveComment($comment);
             $issue->save();
         }
         $this->return_values = $return_values;
     } catch (\Exception $e) {
         //$this->getResponse()->setHttpStatus(400);
         return $this->renderJSON(array('failed' => true, 'error' => $e->getMessage()));
     }
 }
Exemplo n.º 2
0
 public function setValuesFromRequest(\thebuggenie\core\framework\Request $request)
 {
     if ($request->hasParameter('predefined_search')) {
         $this->setPredefinedVariables($request['predefined_search']);
     } else {
         $this->_templatename = $request->hasParameter('template') && self::isTemplateValid($request['template']) ? $request['template'] : 'results_normal';
         $this->_templateparameter = $request['template_parameter'];
         $this->_issues_per_page = $request->getParameter('issues_per_page', 50);
         $this->_offset = $request->getParameter('offset', 0);
         if ($request['quicksearch']) {
             $this->setSortFields(array(tables\Issues::LAST_UPDATED => 'asc'));
             if ($request['term']) {
                 $request->setParameter('fs', array('text' => array('v' => $request['term'], 'o' => '=')));
             }
         }
         $this->_filters = SearchFilter::getFromRequest($request, $this);
         $this->_applies_to_project = framework\Context::getCurrentProject();
         $this->_columns = $request->getParameter('columns');
         $this->_sortfields = $request->getParameter('sortfields');
         $this->_groupby = $request['groupby'];
         $this->_grouporder = $request->getParameter('grouporder', 'asc');
         if (in_array($this->_templatename, array('results_userpain_singlepainthreshold', 'results_userpain_totalpainthreshold'))) {
             $this->_searchtitle = framework\Context::getI18n()->__('Showing "bug report" issues sorted by user pain, threshold set at %threshold', array('%threshold' => $this->_templateparameter));
             $this->_issues_per_page = 0;
             $this->_groupby = 'user_pain';
             $this->_grouporder = 'desc';
             $this->_filters['issuetype'] = SearchFilter::createFilter('issuetype', array('operator' => '=', 'value' => join(',', tables\IssueTypes::getTable()->getBugReportTypeIDs())));
         } elseif ($this->_templatename == 'results_votes') {
             $this->_searchtitle = framework\Context::getI18n()->__('Showing issues ordered by number of votes');
             $this->_issues_per_page = $request->getParameter('issues_per_page', 100);
             $this->_groupby = 'votes';
             $this->_grouporder = 'desc';
         }
     }
     $this->_setupGenericFilters();
 }
Exemplo n.º 3
0
 public function runUpload(framework\Request $request)
 {
     $apc_exists = framework\Request::CanGetUploadStatus();
     if ($apc_exists && !$request['APC_UPLOAD_PROGRESS']) {
         $request->setParameter('APC_UPLOAD_PROGRESS', $request['upload_id']);
     }
     $this->getResponse()->setDecoration(\thebuggenie\core\framework\Response::DECORATE_NONE);
     $canupload = false;
     if ($request['mode'] == 'issue') {
         $issue = entities\Issue::getB2DBTable()->selectById($request['issue_id']);
         $canupload = (bool) ($issue instanceof entities\Issue && $issue->hasAccess() && $issue->canAttachFiles());
     } elseif ($request['mode'] == 'article') {
         $article = \thebuggenie\modules\publish\entities\Article::getByID($request['article_id']);
         $canupload = (bool) ($article instanceof \thebuggenie\modules\publish\entities\Article && $article->canEdit());
     } else {
         $event = \thebuggenie\core\framework\Event::createNew('core', 'upload', $request['mode']);
         $event->triggerUntilProcessed();
         $canupload = $event->isProcessed() ? (bool) $event->getReturnValue() : true;
     }
     if ($canupload) {
         try {
             $file = framework\Context::getRequest()->handleUpload('uploader_file');
             if ($file instanceof entities\File) {
                 switch ($request['mode']) {
                     case 'issue':
                         if (!$issue instanceof entities\Issue) {
                             break;
                         }
                         $issue->attachFile($file, $request->getRawParameter('comment'), $request['uploader_file_description']);
                         $issue->save();
                         break;
                     case 'article':
                         if (!$article instanceof \thebuggenie\modules\publish\entities\Article) {
                             break;
                         }
                         $article->attachFile($file);
                         break;
                 }
                 if ($apc_exists) {
                     return $this->renderText('ok');
                 }
             }
             $this->error = framework\Context::getI18n()->__('An unhandled error occured with the upload');
         } catch (\Exception $e) {
             $this->getResponse()->setHttpStatus(400);
             $this->error = $e->getMessage();
         }
     } else {
         $this->error = framework\Context::getI18n()->__('You are not allowed to attach files here');
     }
     if (!$apc_exists) {
         switch ($request['mode']) {
             case 'issue':
                 if (!$issue instanceof entities\Issue) {
                     break;
                 }
                 $this->forward(framework\Context::getRouting()->generate('viewissue', array('project_key' => $issue->getProject()->getKey(), 'issue_no' => $issue->getFormattedIssueNo())));
                 break;
             case 'article':
                 if (!$article instanceof \thebuggenie\modules\publish\entities\Article) {
                     break;
                 }
                 $this->forward(framework\Context::getRouting()->generate('publish_article_attachments', array('article_id' => $article->getID())));
                 break;
         }
     }
     framework\Logging::log('marking upload ' . $request['APC_UPLOAD_PROGRESS'] . ' as completed with error ' . $this->error);
     $request->markUploadAsFinishedWithError($request['APC_UPLOAD_PROGRESS'], $this->error);
     return $this->renderText($request['APC_UPLOAD_PROGRESS'] . ': ' . $this->error);
 }