コード例 #1
0
 public function componentResults_view()
 {
     $request = new TBGRequest();
     switch ($this->type) {
         case TBGDashboard::DASHBOARD_VIEW_PREDEFINED_SEARCH:
             $request->setParameter('predefined_search', $this->view);
             break;
         case TBGDashboard::DASHBOARD_VIEW_SAVED_SEARCH:
             $request->setParameter('saved_search', $this->view);
             break;
     }
     $request->setParameter('search', $this->search);
     $search = TBGContext::factory()->manufacture('searchActions', uniqid(rand(), true));
     $search->runFindIssues($request);
     $this->issues = $search->issues;
     $this->title = $search->searchtitle;
     $this->parameters = $request->getParameters();
 }
コード例 #2
0
ファイル: actions.class.php プロジェクト: oparoz/thebuggenie
 public function runUpdateIssueDetails(TBGRequest $request)
 {
     $this->forward403if(TBGContext::getCurrentProject()->isArchived());
     $this->error = false;
     try {
         $i18n = TBGContext::getI18n();
         $issue = TBGIssue::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 TBGIssue) {
             die;
         }
         $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 TBGWorkflowTransition) {
                 throw new Exception("This transition ({$key}) is not valid");
             }
         }
         $fields = $request->getRawParameter('fields', array());
         $return_values = array();
         if ($workflow_transition instanceof TBGWorkflowTransition) {
             foreach ($fields as $field_key => $field_value) {
                 $classname = "TBG" . 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'), TBGDatatype::getAvailableFields(true)))) {
                         switch ($field_key) {
                             case 'state':
                                 $issue->setState($field_value == 'open' ? TBGIssue::STATE_OPEN : TBGIssue::STATE_CLOSED);
                                 break;
                             case 'title':
                                 if ($field_value != '') {
                                     $issue->setTitle($field_value);
                                 } else {
                                     throw new Exception($i18n->__('Invalid title'));
                                 }
                                 break;
                             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 = "TBG" . 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}(TBGContext::getUser());
                                         break;
                                     case 'none':
                                         $issue->{$unset_method}();
                                         break;
                                     default:
                                         try {
                                             $user = TBGUser::findUser(mb_strtolower($field_value));
                                             if ($user instanceof TBGUser) {
                                                 $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 TBGWorkflowTransition) {
             $issue->getWorkflow()->moveIssueToMatchingWorkflowStep($issue);
         }
         if (!array_key_exists('transition_ok', $return_values) || $return_values['transition_ok']) {
             $comment = new TBGComment();
             $comment->setTitle('');
             $comment->setContent($request->getParameter('message', null, false));
             $comment->setPostedBy(TBGContext::getUser()->getID());
             $comment->setTargetID($issue->getID());
             $comment->setTargetType(TBGComment::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()));
     }
 }
コード例 #3
0
ファイル: actions.class.php プロジェクト: oparoz/thebuggenie
 public function runUpload(TBGRequest $request)
 {
     $apc_exists = TBGRequest::CanGetUploadStatus();
     if ($apc_exists && !$request['APC_UPLOAD_PROGRESS']) {
         $request->setParameter('APC_UPLOAD_PROGRESS', $request['upload_id']);
     }
     $this->getResponse()->setDecoration(TBGResponse::DECORATE_NONE);
     $canupload = false;
     if ($request['mode'] == 'issue') {
         $issue = TBGContext::factory()->TBGIssue($request['issue_id']);
         $canupload = (bool) ($issue instanceof TBGIssue && $issue->hasAccess() && $issue->canAttachFiles());
     } elseif ($request['mode'] == 'article') {
         $article = TBGWikiArticle::getByName($request['article_name']);
         $canupload = (bool) ($article instanceof TBGWikiArticle && $article->canEdit());
     } else {
         $event = TBGEvent::createNew('core', 'upload', $request['mode']);
         $event->triggerUntilProcessed();
         $canupload = $event->isProcessed() ? (bool) $event->getReturnValue() : true;
     }
     if ($canupload) {
         try {
             $file = TBGContext::getRequest()->handleUpload('uploader_file');
             if ($file instanceof TBGFile) {
                 switch ($request['mode']) {
                     case 'issue':
                         if (!$issue instanceof TBGIssue) {
                             break;
                         }
                         $issue->attachFile($file, $request->getRawParameter('comment'), $request['uploader_file_description']);
                         $issue->save();
                         break;
                     case 'article':
                         if (!$article instanceof TBGWikiArticle) {
                             break;
                         }
                         $article->attachFile($file);
                         break;
                 }
                 if ($apc_exists) {
                     return $this->renderText('ok');
                 }
             }
             $this->error = TBGContext::getI18n()->__('An unhandled error occured with the upload');
         } catch (Exception $e) {
             $this->getResponse()->setHttpStatus(400);
             $this->error = $e->getMessage();
         }
     } else {
         //				$this->getResponse()->setHttpStatus(401);
         $this->error = TBGContext::getI18n()->__('You are not allowed to attach files here');
     }
     if (!$apc_exists) {
         switch ($request['mode']) {
             case 'issue':
                 if (!$issue instanceof TBGIssue) {
                     break;
                 }
                 $this->forward(TBGContext::getRouting()->generate('viewissue', array('project_key' => $issue->getProject()->getKey(), 'issue_no' => $issue->getFormattedIssueNo())));
                 break;
             case 'article':
                 if (!$article instanceof TBGWikiArticle) {
                     break;
                 }
                 $this->forward(TBGContext::getRouting()->generate('publish_article_attachments', array('article_name' => $article->getName())));
                 break;
         }
     }
     TBGLogging::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);
 }