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())); } }
/** * Runs the action for the third step of the installation * where it tests the connection, sets up the database and the initial scope * * @param TBGRequest $request The request object * * @return null */ public function runInstallStep3(TBGRequest $request) { $this->selected_connection_detail = $request->getParameter('connection_type'); try { if ($this->username = $request->getParameter('db_username')) { B2DB::setUname($this->username); B2DB::setTablePrefix($request->getParameter('db_prefix')); if ($this->password = $request->getRawParameter('db_password')) { B2DB::setPasswd($this->password); } if ($this->selected_connection_detail == 'dsn') { if (($this->dsn = $request->getParameter('db_dsn')) != '') { B2DB::setDSN($this->dsn); } else { throw new Exception('You must provide a valid DSN'); } } else { if ($this->db_type = $request->getParameter('db_type')) { B2DB::setDBtype($this->db_type); if ($this->db_hostname = $request->getParameter('db_hostname')) { B2DB::setHost($this->db_hostname); } else { throw new Exception('You must provide a database hostname'); } if ($this->db_port = $request->getParameter('db_port')) { B2DB::setPort($this->db_port); } if ($this->db_databasename = $request->getParameter('db_name')) { B2DB::setDBname($this->db_databasename); } else { throw new Exception('You must provide a database to use'); } } else { throw new Exception('You must provide a database type'); } } B2DB::initialize(THEBUGGENIE_CORE_PATH . 'b2db_bootstrap.inc.php'); $engine_path = B2DB::getEngineClassPath(); if ($engine_path !== null) { TBGContext::addClasspath($engine_path); } else { throw new Exception("Cannot initialize the B2DB engine"); } B2DB::doConnect(); if (B2DB::getDBname() == '') { throw new Exception('You must provide a database to use'); } B2DB::saveConnectionParameters(THEBUGGENIE_CORE_PATH . 'b2db_bootstrap.inc.php'); } else { throw new Exception('You must provide a database username'); } // Add table classes to classpath $tables_path = THEBUGGENIE_CORE_PATH . 'classes' . DS . 'B2DB' . DS; TBGContext::addClasspath($tables_path); $tables_path_handle = opendir($tables_path); $tables_created = array(); while ($table_class_file = readdir($tables_path_handle)) { if (($tablename = substr($table_class_file, 0, strpos($table_class_file, '.'))) != '') { B2DB::getTable($tablename)->create(); $tables_created[] = $tablename; } } sort($tables_created); $this->tables_created = $tables_created; //TBGScope::setupInitialScope(); } catch (Exception $e) { //throw $e; $this->error = $e->getMessage(); } }
public static function getFromRequest(TBGRequest $request, TBGSavedSearch $search) { $filters = $request->getRawParameter('fs', array()); if ($request['quicksearch']) { $filters['text']['o'] = '='; } if (TBGContext::isProjectContext()) { $filters['project_id'] = array('o' => '=', 'v' => TBGContext::getCurrentProject()->getID()); } $return_filters = array(); foreach ($filters as $key => $details) { if (!isset($details['o'])) { foreach ($details as $subdetails) { $return_filters[$key][] = self::createFilter($key, $subdetails, $search); } } else { $return_filters[$key] = self::createFilter($key, $details, $search); } } return $return_filters; }
public function runUpdateComment(TBGRequest $request) { TBGContext::loadLibrary('ui'); $comment = TBGContext::factory()->TBGComment($request['comment_id']); if ($comment instanceof TBGcomment) { if (!$comment->canUserEditComment()) { $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('error' => TBGContext::getI18n()->__('You are not allowed to do this'))); } else { if ($request['comment_body'] == '') { $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('error' => TBGContext::getI18n()->__('The comment must have some content'))); } $comment->setContent($request->getRawParameter('comment_body')); if ($request['comment_title'] == '') { $comment->setTitle(TBGContext::getI18n()->__('Untitled comment')); } else { $comment->setTitle($request['comment_title']); } $comment->setIsPublic($request['comment_visibility']); $comment->setSyntax((int) $request['comment_body_syntax']); $comment->setUpdatedBy($this->getUser()->getID()); $comment->save(); TBGContext::loadLibrary('common'); $body = $comment->getParsedContent(); return $this->renderJSON(array('title' => TBGContext::getI18n()->__('Comment edited!'), 'comment_title' => $comment->getTitle(), 'comment_body' => $body)); } } else { $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('error' => TBGContext::getI18n()->__('Comment ID is invalid'))); } }
/** * Show an article * * @param TBGRequest $request */ public function runEditArticle(TBGRequest $request) { $article_name = $this->article instanceof TBGWikiArticle ? $this->article->getName() : $request->getParameter('article_name'); if (!TBGContext::getModule('publish')->canUserEditArticle($article_name)) { TBGContext::setMessage('publish_article_error', TBGContext::getI18n()->__('You do not have permission to edit this article')); $this->forward(TBGContext::getRouting()->generate('publish_article', array('article_name' => $article_name))); } if ($request->isMethod(TBGRequest::POST)) { if ($request->hasParameter('new_article_name') && $request->getParameter('new_article_name') != '') { if ($request->hasParameter('change_reason') && trim($request->getParameter('change_reason')) != '') { try { if ($request->getParameter('article_id')) { if (($article = PublishFactory::article($request->getParameter('article_id'))) && $article instanceof TBGWikiArticle) { if ($article->getLastUpdatedDate() != $request->getParameter('last_modified')) { $this->error = TBGContext::getI18n()->__('The file has been modified since you last opened it'); } else { try { $article->setName($request->getParameter('new_article_name')); $article->setContent($request->getRawParameter('new_article_content')); if ($request->getParameter('preview')) { $this->article = $article; } else { $article->doSave(array(), $request->getParameter('change_reason')); TBGContext::setMessage('publish_article_message', TBGContext::getI18n()->__('The article was saved')); $this->forward(TBGContext::getRouting()->generate('publish_article', array('article_name' => $article->getName()))); } } catch (Exception $e) { $this->error = $e->getMessage(); } } } } } catch (Exception $e) { } if (($article = TBGWikiArticle::getByName($request->getParameter('new_article_name'))) && $article instanceof TBGWikiArticle && $article->getID() != $request->getParameter('article_id')) { $this->error = TBGContext::getI18n()->__('An article with that name already exists. Please choose a different article name'); } elseif (!$article instanceof TBGWikiArticle) { if ($request->getParameter('preview')) { $article = new TBGWikiArticle(); $article->setContent($request->getRawParameter('new_article_content')); $article->setName($request->getParameter('new_article_name')); $this->article = $article; } else { $article_id = TBGWikiArticle::createNew($request->getParameter('new_article_name'), $request->getRawParameter('new_article_content', ''), true); $this->forward(TBGContext::getRouting()->generate('publish_article', array('article_name' => $request->getParameter('new_article_name')))); } } } else { $this->error = TBGContext::getI18n()->__('You have to provide a reason for the changes'); } } else { $this->error = TBGContext::getI18n()->__('You need to specify the article name'); } } $this->preview = (bool) $request->getParameter('preview'); $this->article_title = null; $this->article_content = null; $this->article_intro = null; $this->change_reason = null; if ($this->article instanceof TBGWikiArticle) { $this->article_title = $this->article->getTitle(); $this->article_content = $this->article->getContent(); if ($request->isMethod(TBGRequest::POST)) { if ($request->hasParameter('new_article_name')) { $this->article_title = $request->getParameter('new_article_name'); } if ($request->hasParameter('new_article_content')) { $this->article_content = $request->getRawParameter('new_article_content'); } if ($request->hasParameter('change_reason')) { $this->change_reason = $request->getParameter('change_reason'); } } } else { if ($request->hasParameter('new_article_content')) { $this->article_content = $request->getRawParameter('new_article_content'); } TBGContext::loadLibrary('publish'); $this->article_title = str_replace(array(':', '_'), array(' ', ' '), get_spaced_name($this->article_name)); } }
/** * Show an article * * @param TBGRequest $request */ public function runEditArticle(TBGRequest $request) { if (!$this->article->canEdit()) { TBGContext::setMessage('publish_article_error', TBGContext::getI18n()->__('You do not have permission to edit this article')); $this->forward(TBGContext::getRouting()->generate('publish_article', array('article_name' => $this->article_name))); } $this->article_route = $this->article->getID() ? 'publish_article_edit' : 'publish_article_new'; $this->article_route_params = $this->article->getID() ? array('article_name' => $this->article_name) : array(); if ($request->isPost()) { $this->preview = (bool) $request['preview']; $this->change_reason = $request['change_reason']; try { $this->article->setArticleType($request['article_type']); $this->article->setName($request['new_article_name']); $this->article->setParentArticle(TBGArticlesTable::getTable()->getArticleByName($request['parent_article_name'])); $this->article->setManualName($request['manual_name']); if ($this->article->getArticleType() == TBGWikiArticle::TYPE_MANUAL && !$this->article->getName()) { $article_name_prefix = $this->article->getParentArticle() instanceof TBGWikiArticle ? $this->article->getParentArticle()->getName() . ':' : $request['parent_article_name']; $this->article->setName(str_replace(' ', '', $article_name_prefix . $this->article->getManualName())); } $this->article->setContentSyntax($request['article_content_syntax']); $this->article->setContent($request->getRawParameter('article_content')); if (!$this->article->getName() || trim($this->article->getName()) == '' || !preg_match('/[\\w:]+/i', $this->article->getName())) { throw new Exception(TBGContext::getI18n()->__('You need to specify a valid article name')); } if ($request['article_type'] == TBGWikiArticle::TYPE_MANUAL && (!$this->article->getManualName() || trim($this->article->getManualName()) == '' || !preg_match('/[\\w:]+/i', $this->article->getManualName()))) { throw new Exception(TBGContext::getI18n()->__('You need to specify a valid article name')); } if (TBGPublish::getModule()->getSetting('require_change_reason') == 1 && (!$this->change_reason || trim($this->change_reason) == '')) { throw new Exception(TBGContext::getI18n()->__('You have to provide a reason for the changes')); } if ($this->article->getLastUpdatedDate() != $request['last_modified']) { throw new Exception(TBGContext::getI18n()->__('The file has been modified since you last opened it')); } if (($article = TBGWikiArticle::getByName($request['new_new_article_name'])) && $article instanceof TBGWikiArticle && $article->getID() != $request['article_id']) { throw new Exception(TBGContext::getI18n()->__('An article with that name already exists. Please choose a different article name')); } if (!$this->preview) { $this->article->doSave(array(), $request['change_reason']); TBGContext::setMessage('publish_article_message', TBGContext::getI18n()->__('The article was saved')); $this->forward(TBGContext::getRouting()->generate('publish_article', array('article_name' => $this->article->getName()))); } } catch (Exception $e) { $this->error = $e->getMessage(); } } }