/** * Pre-execute function for search functions * * @param framework\Request $request */ public function preExecute(framework\Request $request, $action) { $this->forward403unless(framework\Context::getUser()->hasPageAccess('search') && framework\Context::getUser()->canSearchForIssues()); if ($project_key = $request['project_key']) { $project = entities\Project::getByKey($project_key); } elseif (is_numeric($request['project_id']) && ($project_id = (int) $request['project_id'])) { $project = tables\Projects::getTable()->selectById($project_id); } else { $project = false; } if ($project instanceof entities\Project) { $this->forward403unless(framework\Context::getUser()->hasProjectPageAccess('project_issues', $project)); framework\Context::getResponse()->setPage('project_issues'); framework\Context::setCurrentProject($project); } $this->search_object = entities\SavedSearch::getFromRequest($request); $this->issavedsearch = $this->search_object instanceof entities\SavedSearch && $this->search_object->getB2DBID(); $this->show_results = $this->issavedsearch || $request->hasParameter('quicksearch') || $request->hasParameter('fs') || $request->getParameter('search', false) ? true : false; $this->searchterm = $this->search_object instanceof entities\SavedSearch ? $this->search_object->getSearchterm() : ''; $this->searchtitle = $this->search_object instanceof entities\SavedSearch ? $this->search_object->getTitle() : ''; if ($this->issavedsearch) { if (!($this->search_object instanceof entities\SavedSearch && framework\Context::getUser()->canAccessSavedSearch($this->search_object))) { framework\Context::setMessage('search_error', framework\Context::getI18n()->__("You don't have access to this saved search")); } } }
public function runProjectCommitsMore(framework\Request $request) { $this->forward403unless($request->isPost()); $this->selected_project = Project::getByKey($request['project_key']); framework\Context::setCurrentProject($this->selected_project); if (framework\Context::getModule('vcs_integration')->getSetting('vcs_mode_' . framework\Context::getCurrentProject()->getID()) == Vcs_integration::MODE_DISABLED) { return $this->return404(framework\Context::getI18n()->__('VCS Integration has been disabled for this project')); } $offset = $request->getParameter('offset', 0); $this->commits = Commit::getByProject($this->selected_project->getID(), 40, $offset, $request->getParameter('branchname'), $request->getParameter('gitlab_repos_nss')); return $this->renderJSON(array('content' => $this->getComponentHTML('vcs_integration/projectcommits', array('commits' => $this->commits, 'selected_project' => $this->selected_project)), 'offset' => $offset + 40)); }
/** * The currently selected project in actions where there is one * * @access protected * @property entities\Project $selected_project */ public function preExecute(framework\Request $request, $action) { try { if ($project_key = $request['project_key']) { $this->selected_project = entities\Project::getByKey($project_key); } elseif ($project_id = (int) $request['project_id']) { $this->selected_project = entities\Project::getB2DBTable()->selectByID($project_id); } if ($this->selected_project instanceof entities\Project) { framework\Context::setCurrentProject($this->selected_project); } } catch (\Exception $e) { } }
/** * Pre-execute function * * @param \thebuggenie\core\framework\Request $request */ public function preExecute(framework\Request $request, $action) { $this->article = null; $this->article_name = $request->getRawParameter('article_name'); $this->article_id = (int) $request['article_id']; $this->special = false; if (!is_null($this->article_name) && mb_strpos($this->article_name, ':') !== false) { $this->article_name = $this->_getArticleNameDetails($this->article_name); } else { try { if ($project_key = $request['project_key']) { $this->selected_project = \thebuggenie\core\entities\Project::getByKey($project_key); } elseif ($project_id = (int) $request['project_id']) { $this->selected_project = \thebuggenie\core\entities\tables\Projects::getTable()->selectById($project_id); } } catch (\Exception $e) { } } if (!$this->special) { if ($this->article_id) { $this->article = Articles::getTable()->selectById($this->article_id); } elseif ($this->article_name) { $this->article = Articles::getTable()->getArticleByName($this->article_name); } if (!$this->article instanceof Article) { $this->article = new Article(); if ($this->article_name) { $this->article->setName($this->article_name); } elseif ($request->hasParameter('parent_article_name')) { $parent_article_name = $request->getRawParameter('parent_article_name'); $this->article->setParentArticle(Articles::getTable()->getArticleByName($parent_article_name)); $this->_getArticleNameDetails($parent_article_name); if ($this->article->getParentArticle() instanceof Article) { if ($this->article->getParentArticle()->getArticleType() == Article::TYPE_WIKI) { $this->article->setName($this->article->getParentArticle()->getName() . ':'); } $this->article->setArticleType($this->article->getParentArticle()->getArticleType()); } } $this->article->setContentSyntax($this->getUser()->getPreferredWikiSyntax(true)); } } if ($this->selected_project instanceof \thebuggenie\core\entities\Project) { if (!$this->selected_project->hasAccess()) { $this->forward403(); } else { framework\Context::setCurrentProject($this->selected_project); } } }
/** * Pre-execute function * * @param framework\Request $request * @param string $action */ public function preExecute(framework\Request $request, $action) { try { if ($project_id = $request['project_id']) { $this->selected_project = entities\Project::getB2DBTable()->selectById($project_id); } elseif ($project_key = $request['project_key']) { $this->selected_project = entities\Project::getByKey($project_key); } } catch (\Exception $e) { } if (!$this->selected_project instanceof entities\Project) { return $this->return404(framework\Context::getI18n()->__('This project does not exist')); } framework\Context::setCurrentProject($this->selected_project); $this->project_key = $this->selected_project->getKey(); }
/** * The currently selected project in actions where there is one * * @access protected * @property entities\Project $selected_project */ public function preExecute(framework\Request $request, $action) { try { // Default to JSON if nothing is specified. $newFormat = $request->getParameter('format', 'json'); $this->getResponse()->setTemplate(mb_strtolower($action) . '.' . $newFormat . '.php'); $this->getResponse()->setupResponseContentType($newFormat); if ($project_key = $request['project_key']) { $this->selected_project = entities\Project::getByKey($project_key); } elseif ($project_id = (int) $request['project_id']) { $this->selected_project = entities\Project::getB2DBTable()->selectByID($project_id); } if ($this->selected_project instanceof entities\Project) { framework\Context::setCurrentProject($this->selected_project); } $this->render_detail = !isset($request['nodetail']); } catch (\Exception $e) { $this->getResponse()->setHttpStatus(500); return $this->renderJSON(array('error' => 'An exception occurred: ' . $e)); } }
public static function processCommit(\thebuggenie\core\entities\Project $project, $commit_msg, $old_rev, $new_rev, $date = null, $changed, $author, $branch = null, \Closure $callback = null) { $output = ''; framework\Context::setCurrentProject($project); if ($project->isArchived()) { return; } if (Commits::getTable()->isProjectCommitProcessed($new_rev, $project->getID())) { return; } try { framework\Context::getI18n(); } catch (\Exception $e) { framework\Context::reinitializeI18n(null); } // Is VCS Integration enabled? if (framework\Settings::get('vcs_mode_' . $project->getID(), 'vcs_integration') == self::MODE_DISABLED) { $output .= '[VCS ' . $project->getKey() . '] This project does not use VCS Integration' . "\n"; return $output; } // Parse the commit message, and obtain the issues and transitions for issues. $parsed_commit = \thebuggenie\core\entities\Issue::getIssuesFromTextByRegex($commit_msg); $issues = $parsed_commit["issues"]; $transitions = $parsed_commit["transitions"]; // Build list of affected files $file_lines = preg_split('/[\\n\\r]+/', $changed); $files = array(); foreach ($file_lines as $aline) { $action = mb_substr($aline, 0, 1); if ($action == "A" || $action == "U" || $action == "D" || $action == "M") { $theline = trim(mb_substr($aline, 1)); $files[] = array($action, $theline); } } // Find author of commit, fallback is guest /* * Some VCSes use a different format of storing the committer's name. Systems like bzr, git and hg use the format * Joe Bloggs <*****@*****.**>, instead of a classic username. Therefore a user will be found via 4 queries: * a) First we extract the email if there is one, and find a user with that email * b) If one is not found - or if no email was specified, then instead test against the real name (using the name part if there was an email) * c) the username or full name is checked against the friendly name field * d) and if we still havent found one, then we check against the username * e) and if we STILL havent found one, we use the guest user */ // a) $user = \thebuggenie\core\entities\tables\Users::getTable()->getByEmail($author); if (!$user instanceof \thebuggenie\core\entities\User && preg_match("/(?<=<)(.*)(?=>)/", $author, $matches)) { $email = $matches[0]; // a2) $user = \thebuggenie\core\entities\tables\Users::getTable()->getByEmail($email); if (!$user instanceof \thebuggenie\core\entities\User) { // Not found by email preg_match("/(?<=^)(.*)(?= <)/", $author, $matches); $author = $matches[0]; } } // b) if (!$user instanceof \thebuggenie\core\entities\User) { $user = \thebuggenie\core\entities\tables\Users::getTable()->getByRealname($author); } // c) if (!$user instanceof \thebuggenie\core\entities\User) { $user = \thebuggenie\core\entities\tables\Users::getTable()->getByBuddyname($author); } // d) if (!$user instanceof \thebuggenie\core\entities\User) { $user = \thebuggenie\core\entities\tables\Users::getTable()->getByUsername($author); } // e) if (!$user instanceof \thebuggenie\core\entities\User) { $user = framework\Settings::getDefaultUser(); } framework\Context::setUser($user); framework\Settings::forceSettingsReload(); framework\Context::cacheAllPermissions(); $output .= '[VCS ' . $project->getKey() . '] Commit to be logged by user ' . $user->getName() . "\n"; if ($date == null) { $date = NOW; } // Create the commit data $commit = new Commit(); $commit->setAuthor($user); $commit->setDate($date); $commit->setLog($commit_msg); $commit->setPreviousRevision($old_rev); $commit->setRevision($new_rev); $commit->setProject($project); if ($branch !== null) { $data = 'branch:' . $branch; $commit->setMiscData($data); } if ($callback !== null) { $commit = $callback($commit); } $commit->save(); $output .= '[VCS ' . $project->getKey() . '] Commit logged with revision ' . $commit->getRevision() . "\n"; // Iterate over affected issues and update them. foreach ($issues as $issue) { $inst = new IssueLink(); $inst->setIssue($issue); $inst->setCommit($commit); $inst->save(); // Process all commit-message transitions for an issue. foreach ($transitions[$issue->getFormattedIssueNo()] as $transition) { if (framework\Settings::get('vcs_workflow_' . $project->getID(), 'vcs_integration') == self::WORKFLOW_ENABLED) { framework\Context::setUser($user); framework\Settings::forceSettingsReload(); framework\Context::cacheAllPermissions(); if ($issue->isWorkflowTransitionsAvailable()) { // Go through the list of possible transitions for an issue. Only // process transitions that are applicable to issue's workflow. foreach ($issue->getAvailableWorkflowTransitions() as $possible_transition) { if (mb_strtolower($possible_transition->getName()) == mb_strtolower($transition[0])) { $output .= '[VCS ' . $project->getKey() . '] Running transition ' . $transition[0] . ' on issue ' . $issue->getFormattedIssueNo() . "\n"; // String representation of parameters. Used for log message. $parameters_string = ""; // Iterate over the list of this transition's parameters, and // set them. foreach ($transition[1] as $parameter => $value) { $parameters_string .= "{$parameter}={$value} "; switch ($parameter) { case 'resolution': if (($resolution = \thebuggenie\core\entities\Resolution::getByKeyish($value)) instanceof \thebuggenie\core\entities\Resolution) { framework\Context::getRequest()->setParameter('resolution_id', $resolution->getID()); } break; case 'status': if (($status = \thebuggenie\core\entities\Status::getByKeyish($value)) instanceof \thebuggenie\core\entities\Status) { framework\Context::getRequest()->setParameter('status_id', $status->getID()); } break; } } // Run the transition. $possible_transition->transitionIssueToOutgoingStepWithoutRequest($issue); // Log an informative message about the transition. $output .= '[VCS ' . $project->getKey() . '] Ran transition ' . $possible_transition->getName() . ' with parameters \'' . $parameters_string . '\' on issue ' . $issue->getFormattedIssueNo() . "\n"; } } } } } $issue->addSystemComment(framework\Context::getI18n()->__('This issue has been updated with the latest changes from the code repository.<source>%commit_msg</source>', array('%commit_msg' => $commit_msg)), $user->getID()); $output .= '[VCS ' . $project->getKey() . '] Updated issue ' . $issue->getFormattedIssueNo() . "\n"; } // Create file links foreach ($files as $afile) { // index 0 is action, index 1 is file $inst = new File(); $inst->setAction($afile[0]); $inst->setFile($afile[1]); $inst->setCommit($commit); $inst->save(); $output .= '[VCS ' . $project->getKey() . '] Added with action ' . $afile[0] . ' file ' . $afile[1] . "\n"; } framework\Event::createNew('vcs_integration', 'new_commit')->trigger(array('commit' => $commit)); return $output; }
public function runProjectIssueCommitsMore(framework\Request $request) { $this->forward403unless($request->isPost()); $this->selected_project = Project::getByKey($request['project_key']); framework\Context::setCurrentProject($this->selected_project); if (framework\Context::getModule('vcs_integration')->getSetting('vcs_mode_' . framework\Context::getCurrentProject()->getID()) == Vcs_integration::MODE_DISABLED) { return $this->return404(framework\Context::getI18n()->__('VCS Integration has been disabled for this project')); } $issue = Issues::getTable()->getByProjectIDAndIssueNo($this->selected_project->getID(), $request['issue_no']); $links = IssueLink::getCommitsByIssue($issue, $request->getParameter('limit', 0), $request->getParameter('offset', 0)); return $this->renderJSON(array('content' => $this->getComponentHTML('vcs_integration/issuecommits', array("projectId" => $this->selected_project->getID(), "links" => $links)))); }
public function runDashboardView(framework\Request $request) { $view = entities\DashboardView::getB2DBTable()->selectById($request['view_id']); if (!$view instanceof entities\DashboardView) { return $this->renderJSON(array('content' => 'invalid view')); } if ($view->getTargetType() == entities\DashboardView::TYPE_PROJECT) { framework\Context::setCurrentProject($view->getDashboard()->getProject()); } return $this->renderJSON(array('content' => $this->returnComponentHTML($view->getTemplate(), array('view' => $view)))); }