/** * Show an article * * @param \thebuggenie\core\framework\Request $request */ public function runEditArticle(framework\Request $request) { if (!$this->article->canEdit()) { framework\Context::setMessage('publish_article_error', framework\Context::getI18n()->__('You do not have permission to edit this article')); $this->forward(framework\Context::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(Articles::getTable()->getArticleByName($request['parent_article_name'])); $this->article->setManualName($request['manual_name']); if ($this->article->getArticleType() == Article::TYPE_MANUAL && !$this->article->getName()) { $article_name_prefix = $this->article->getParentArticle() instanceof Article ? $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(framework\Context::getI18n()->__('You need to specify a valid article name')); } if ($request['article_type'] == Article::TYPE_MANUAL && (!$this->article->getManualName() || trim($this->article->getManualName()) == '' || !preg_match('/[\\w:]+/i', $this->article->getManualName()))) { throw new \Exception(framework\Context::getI18n()->__('You need to specify a valid article name')); } if (!$this->preview && framework\Context::getModule('publish')->getSetting('require_change_reason') == 1 && (!$this->change_reason || trim($this->change_reason) == '')) { throw new \Exception(framework\Context::getI18n()->__('You have to provide a reason for the changes')); } if ($this->article->getLastUpdatedDate() != $request['last_modified']) { throw new \Exception(framework\Context::getI18n()->__('The file has been modified since you last opened it')); } if (($article = Article::getByName($request['new_new_article_name'])) && $article instanceof Article && $article->getID() != $request['article_id']) { throw new \Exception(framework\Context::getI18n()->__('An article with that name already exists. Please choose a different article name')); } if (!$this->preview) { $this->article->doSave(array(), $request['change_reason']); framework\Context::setMessage('publish_article_message', framework\Context::getI18n()->__('The article was saved')); $this->forward(framework\Context::getRouting()->generate('publish_article', array('article_name' => $this->article->getName()))); } } catch (\Exception $e) { $this->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 framework\Request $request The request object * * @return null */ public function runInstallStep3(framework\Request $request) { $this->selected_connection_detail = $request['connection_type']; try { if ($this->username = $request['db_username']) { \b2db\Core::setUname($this->username); \b2db\Core::setTablePrefix($request['db_prefix']); if ($this->password = $request->getRawParameter('db_password')) { \b2db\Core::setPasswd($this->password); } if ($this->selected_connection_detail == 'dsn') { if (($this->dsn = $request['db_dsn']) != '') { \b2db\Core::setDSN($this->dsn); } else { throw new \Exception('You must provide a valid DSN'); } } else { if ($this->db_type = $request['db_type']) { \b2db\Core::setDBtype($this->db_type); if ($this->db_hostname = $request['db_hostname']) { \b2db\Core::setHost($this->db_hostname); } else { throw new \Exception('You must provide a database hostname'); } if ($this->db_port = $request['db_port']) { \b2db\Core::setPort($this->db_port); } if ($this->db_databasename = $request['db_name']) { \b2db\Core::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'); } } try { \b2db\Core::doConnect(); } catch (\b2db\Exception $e) { throw new \Exception('There was an error connecting to the database: ' . $e->getMessage()); } if (\b2db\Core::getDBname() == '') { throw new \Exception('You must provide a database to use'); } \b2db\Core::saveConnectionParameters(\THEBUGGENIE_CONFIGURATION_PATH . "b2db.yml"); } else { throw new \Exception('You must provide a database username'); } // Create v4 tables $b2db_entities_path = THEBUGGENIE_CORE_PATH . 'entities' . DS . 'tables' . DS; $tables_created = array(); foreach (scandir($b2db_entities_path) as $tablefile) { if (in_array($tablefile, array('.', '..'))) { continue; } if (($tablename = mb_substr($tablefile, 0, mb_strpos($tablefile, '.'))) != '') { $tablename = "\\thebuggenie\\core\\entities\\tables\\{$tablename}"; $reflection = new \ReflectionClass($tablename); $docblock = $reflection->getDocComment(); $annotationset = new \b2db\AnnotationSet($docblock); if ($annotationset->hasAnnotation('Table')) { \b2db\Core::getTable($tablename)->create(); \b2db\Core::getTable($tablename)->createIndexes(); $tables_created[] = $tablename; } } } sort($tables_created); $this->tables_created = $tables_created; } catch (\Exception $e) { $this->error = $e->getMessage(); } $server_type = strtolower(trim($_SERVER['SERVER_SOFTWARE'])); switch (true) { case stripos($server_type, 'apache') !== false: $this->server_type = 'apache'; break; case stripos($server_type, 'nginx') !== false: $this->server_type = 'nginx'; break; case stripos($server_type, 'iis') !== false: $this->server_type = 'iis'; break; default: $this->server_type = 'unknown'; } $dirname = dirname($_SERVER['PHP_SELF']); if (mb_stristr(PHP_OS, 'WIN')) { $dirname = str_replace("\\", "/", $dirname); /* Windows adds a \ to the URL which we don't want */ } $this->dirname = $dirname != '/' ? $dirname . '/' : $dirname; }
public static function getFromRequest(\thebuggenie\core\framework\Request $request, \thebuggenie\core\entities\SavedSearch $search) { $filters = $request->getRawParameter('fs', array()); if ($request['quicksearch']) { $filters['text']['o'] = '='; } if (framework\Context::isProjectContext()) { $filters['project_id'] = array('o' => '=', 'v' => framework\Context::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 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())); } }
public function runSetPermission(framework\Request $request) { $i18n = framework\Context::getI18n(); if ($this->access_level == framework\Settings::ACCESS_FULL) { $uid = 0; $gid = 0; $tid = 0; switch ($request['target_type']) { case 'user': $uid = $request['item_id']; break; case 'group': $gid = $request['item_id']; break; case 'team': $tid = $request['item_id']; break; } $target_id = $request->getRawParameter('target_id'); switch ($request['mode']) { case 'allowed': framework\Context::setPermission($request['key'], $target_id, $request['target_module'], $uid, $gid, $tid, true); break; case 'denied': framework\Context::setPermission($request['key'], $target_id, $request['target_module'], $uid, $gid, $tid, false); break; case 'unset': framework\Context::removePermission($request['key'], $target_id, $request['target_module'], $uid, $gid, $tid, true, null, 0); break; } return $this->renderJSON(array('content' => $this->getComponentHTML('configuration/permissionsinfoitem', array('key' => $request['key'], 'target_id' => $target_id, 'type' => $request['target_type'], 'mode' => $request['template_mode'], 'item_id' => $request['item_id'], 'module' => $request['target_module'], 'access_level' => $this->access_level)))); } $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array("error" => $i18n->__("You don't have access to modify permissions"))); }
public function runUpdateComment(framework\Request $request) { framework\Context::loadLibrary('ui'); $comment = entities\Comment::getB2DBTable()->selectById($request['comment_id']); if ($comment instanceof entities\Comment) { if (!$comment->canUserEdit(framework\Context::getUser())) { $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('error' => framework\Context::getI18n()->__('You are not allowed to do this'))); } else { if ($request['comment_body'] == '') { $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('error' => framework\Context::getI18n()->__('The comment must have some content'))); } if ($comment->getTarget() instanceof entities\Issue) { framework\Context::setCurrentProject($comment->getTarget()->getProject()); } $comment->setContent($request->getRawParameter('comment_body')); $comment->setIsPublic($request['comment_visibility']); $comment->setSyntax($request['comment_body_syntax']); $comment->setUpdatedBy($this->getUser()->getID()); $comment->save(); framework\Context::loadLibrary('common'); $body = $comment->getParsedContent(); return $this->renderJSON(array('title' => framework\Context::getI18n()->__('Comment edited!'), 'comment_body' => $body)); } } else { $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('error' => framework\Context::getI18n()->__('Comment ID is invalid'))); } }
public function runFindArticles(framework\Request $request) { $this->articlename = $request->getRawParameter('articlename'); if ($this->articlename) { list($this->resultcount, $this->articles) = Article::findArticlesByContentAndProject($this->articlename, framework\Context::getCurrentProject(), 10); } }