예제 #1
0
 /**
  * Pre-execute function for search functions
  *
  * @param TBGRequest $request
  */
 public function preExecute(TBGRequest $request, $action)
 {
     $this->forward403unless(TBGContext::getUser()->hasPageAccess('search') && TBGContext::getUser()->canSearchForIssues());
     if ($project_key = $request['project_key']) {
         $project = TBGProject::getByKey($project_key);
     } elseif (is_numeric($request['project_id']) && ($project_id = (int) $request['project_id'])) {
         $project = TBGProjectsTable::getTable()->selectById($project_id);
     } else {
         $project = false;
     }
     if ($project instanceof TBGProject) {
         $this->forward403unless(TBGContext::getUser()->hasProjectPageAccess('project_issues', $project));
         TBGContext::getResponse()->setPage('project_issues');
         TBGContext::setCurrentProject($project);
     }
     $this->search_object = TBGSavedSearch::getFromRequest($request);
     $this->issavedsearch = $this->search_object instanceof TBGSavedSearch && $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->getSearchterm();
     $this->searchtitle = $this->search_object->getTitle();
     if ($this->issavedsearch) {
         if (!($this->search_object instanceof TBGSavedSearch && TBGContext::getUser()->canAccessSavedSearch($this->search_object))) {
             TBGContext::setMessage('search_error', TBGContext::getI18n()->__("You don't have access to this saved search"));
         }
     }
 }
예제 #2
0
 /**
  * The currently selected project in actions where there is one
  *
  * @access protected
  * @property TBGProject $selected_project
  */
 public function preExecute(TBGRequest $request, $action)
 {
     try {
         if ($project_key = $request->getParameter('project_key')) {
             $this->selected_project = TBGProject::getByKey($project_key);
         } elseif ($project_id = (int) $request->getParameter('project_id')) {
             $this->selected_project = TBGContext::factory()->TBGProject($project_id);
         }
         TBGContext::setCurrentProject($this->selected_project);
     } catch (Exception $e) {
     }
 }
예제 #3
0
 public function runProjectCommits(TBGRequest $request)
 {
     $this->selected_project = TBGProject::getByKey($request['project_key']);
     TBGContext::setCurrentProject($this->selected_project);
     if (TBGContext::getModule('vcs_integration')->getSetting('vcs_mode_' . TBGContext::getCurrentProject()->getID()) == TBGVCSIntegration::MODE_DISABLED) {
         return $this->return404(TBGContext::getI18n()->__('VCS Integration has been disabled for this project'));
     }
     $offset = $request->getParameter('offset', 0);
     $this->commits = TBGVCSIntegrationCommit::getByProject($this->selected_project->getID(), 40, $offset);
     if ($offset) {
         return $this->renderJSON(array('content' => $this->getTemplateHTML('vcs_integration/projectcommits', array('commits' => $this->commits, 'selected_project' => $this->selected_project)), 'offset' => $offset + 40));
     }
 }
예제 #4
0
 /**
  * The currently selected project in actions where there is one
  *
  * @access protected
  * @property TBGProject $selected_project
  */
 public function preExecute(TBGRequest $request, $action)
 {
     try {
         if ($project_key = $request['project_key']) {
             $this->selected_project = TBGProject::getByKey($project_key);
         } elseif ($project_id = (int) $request['project_id']) {
             $this->selected_project = TBGContext::factory()->TBGProject($project_id);
         }
         if ($this->selected_project instanceof TBGProject) {
             TBGContext::setCurrentProject($this->selected_project);
         }
     } catch (Exception $e) {
     }
 }
예제 #5
0
 /**
  * Pre-execute function
  *
  * @param TBGRequest $request
  */
 public function preExecute(TBGRequest $request, $action)
 {
     $this->article = null;
     $this->article_name = $request['article_name'];
     $this->article_id = (int) $request['article_id'];
     $this->special = false;
     if ($request->hasParameter('article_name') && mb_strpos($request['article_name'], ':') !== false) {
         $this->article_name = $this->_getArticleNameDetails($request['article_name']);
     } else {
         try {
             if ($project_key = $request['project_key']) {
                 $this->selected_project = TBGProject::getByKey($project_key);
             } elseif ($project_id = (int) $request['project_id']) {
                 $this->selected_project = TBGProjectsTable::getTable()->selectById($project_id);
             }
         } catch (Exception $e) {
         }
     }
     if (!$this->special) {
         if ($this->article_id) {
             $this->article = TBGArticlesTable::getTable()->selectById($this->article_id);
         } elseif ($this->article_name) {
             $this->article = TBGArticlesTable::getTable()->getArticleByName($this->article_name);
         }
         if (!$this->article instanceof TBGWikiArticle) {
             $this->article = new TBGWikiArticle();
             if ($this->article_name) {
                 $this->article->setName($this->article_name);
             } elseif ($request->hasParameter('parent_article_name')) {
                 $this->article->setParentArticle(TBGArticlesTable::getTable()->getArticleByName($request['parent_article_name']));
                 $this->_getArticleNameDetails($request['parent_article_name']);
                 if ($this->article->getParentArticle() instanceof TBGWikiArticle) {
                     if ($this->article->getParentArticle()->getArticleType() == TBGWikiArticle::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 TBGProject) {
         if (!$this->selected_project->hasAccess()) {
             $this->forward403();
         } else {
             TBGContext::setCurrentProject($this->selected_project);
         }
     }
 }
예제 #6
0
 /**
  * Pre-execute function for search functions
  *
  * @param TBGRequest $request
  */
 public function preExecute(TBGRequest $request, $action)
 {
     $this->forward403unless(TBGContext::getUser()->hasPageAccess('search') && TBGContext::getUser()->canSearchForIssues());
     if ($request->hasParameter('project_key')) {
         if (($project = TBGProject::getByKey($request->getParameter('project_key'))) instanceof TBGProject) {
             $this->forward403unless(TBGContext::getUser()->hasProjectPageAccess('project_issues', $project->getID()));
             TBGContext::getResponse()->setPage('project_issues');
             TBGContext::setCurrentProject($project);
         }
     }
     $filters = $request->getParameter('filters', array());
     $this->searchterm = null;
     if (array_key_exists('text', $filters) && array_key_exists('value', $filters['text'])) {
         $this->searchterm = $filters['text']['value'];
     }
 }
예제 #7
0
 /**
  * Pre-execute function
  *
  * @param TBGRequest $request
  */
 public function preExecute(TBGRequest $request, $action)
 {
     $this->getResponse()->setPage('wiki');
     $i18n = TBGContext::getI18n();
     $this->article = null;
     $this->article_name = $request->getParameter('article_name');
     if ($request->hasParameter('article_name') && strpos($request->getParameter('article_name'), ':') !== false) {
         $namespace = substr($this->article_name, 0, strpos($this->article_name, ':'));
         $article_name = substr($this->article_name, strpos($this->article_name, ':') + 1);
         if ($namespace == 'Category') {
             $namespace = substr($article_name, 0, strpos($article_name, ':'));
             $article_name = substr($article_name, strpos($article_name, ':') + 1);
         }
         if ($namespace != '') {
             $key = strtolower($namespace);
             $row = TBGProjectsTable::getTable()->getByKey($key);
             if ($row instanceof B2DBRow) {
                 $project = TBGContext::factory()->TBGProject($row->get(TBGProjectsTable::ID), $row);
                 if ($project instanceof TBGProject) {
                     $this->forward403unless($project->hasAccess());
                 }
                 TBGContext::setCurrentProject($project);
             }
         }
     } else {
         try {
             if ($project_key = $request->getParameter('project_key')) {
                 $row = TBGProjectsTable::getTable()->getByKey($project_key);
                 $this->selected_project = TBGContext::factory()->TBGProject($row->get(TBGProjectsTable::ID), $row);
             } elseif ($project_id = (int) $request->getParameter('project_id')) {
                 $this->selected_project = TBGContext::factory()->TBGProject($project_id);
             }
             if ($this->selected_project instanceof TBGProject) {
                 $this->forward403unless($this->selected_project->hasAccess());
             }
             TBGContext::setCurrentProject($this->selected_project);
         } catch (Exception $e) {
         }
     }
     if ($row = TBGArticlesTable::getTable()->getArticleByName($this->article_name)) {
         $this->article = PublishFactory::article($row->get(TBGArticlesTable::ID), $row);
     }
 }
예제 #8
0
 /**
  * Pre-execute function
  *
  * @param TBGRequest 	$request
  * @param string		$action
  */
 public function preExecute(TBGRequest $request, $action)
 {
     if ($project_id = $request['project_id']) {
         try {
             $this->selected_project = TBGContext::factory()->TBGProject($project_id);
         } catch (Exception $e) {
         }
     } elseif ($project_key = $request['project_key']) {
         try {
             $this->selected_project = TBGProject::getByKey($project_key);
         } catch (Exception $e) {
         }
     }
     if ($this->selected_project instanceof TBGProject) {
         TBGContext::setCurrentProject($this->selected_project);
         $this->project_key = $this->selected_project->getKey();
     } else {
         $this->return404(TBGContext::getI18n()->__('This project does not exist'));
     }
 }
예제 #9
0
 public function runDashboardView(TBGRequest $request)
 {
     $view = new TBGDashboardView($request['view_id']);
     if ($view->getTargetType() == TBGDashboardView::TYPE_PROJECT) {
         TBGContext::setCurrentProject(new TBGProject($view->getProjectID()));
     }
     return $this->renderJSON(array('content' => $this->returnComponentHTML($view->getTemplate(), array('view' => $view))));
 }
예제 #10
0
 public static function processCommit(TBGProject $project, $commit_msg, $old_rev, $new_rev, $date = null, $changed, $author, $branch = null)
 {
     $output = '';
     TBGContext::setCurrentProject($project);
     if ($project->isArchived()) {
         return;
     }
     try {
         TBGContext::getI18n();
     } catch (Exception $e) {
         TBGContext::reinitializeI18n(null);
     }
     // Is VCS Integration enabled?
     if (TBGSettings::get('vcs_mode_' . $project->getID(), 'vcs_integration') == TBGVCSIntegration::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 = TBGIssue::getIssuesFromTextByRegex($commit_msg);
     $issues = $parsed_commit["issues"];
     $transitions = $parsed_commit["transitions"];
     // If no issues exist, we may not be able to continue
     //			if (count($issues) == 0)
     //			{
     //				$output .= '[VCS '.$project->getKey().'] This project only accepts commits which affect issues' . "\n";
     //				return $output;
     //			}
     // 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
      */
     if (preg_match("/(?<=<)(.*)(?=>)/", $author, $matches)) {
         $email = $matches[0];
         // a)
         $user = TBGUsersTable::getTable()->getByEmail($email);
         if (!$user instanceof TBGUser) {
             // Not found by email
             preg_match("/(?<=^)(.*)(?= <)/", $author, $matches);
             $author = $matches[0];
         }
     }
     // b)
     if (!$user instanceof TBGUser) {
         $user = TBGUsersTable::getTable()->getByRealname($author);
     }
     // c)
     if (!$user instanceof TBGUser) {
         $user = TBGUsersTable::getTable()->getByBuddyname($author);
     }
     // d)
     if (!$user instanceof TBGUser) {
         $user = TBGUsersTable::getTable()->getByUsername($author);
     }
     // e)
     if (!$user instanceof TBGUser) {
         $user = TBGSettings::getDefaultUser();
     }
     TBGContext::setUser($user);
     TBGSettings::forceSettingsReload();
     TBGContext::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 TBGVCSIntegrationCommit();
     $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);
     }
     $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 TBGVCSIntegrationIssueLink();
         $inst->setIssue($issue);
         $inst->setCommit($commit);
         $inst->save();
         // Process all commit-message transitions for an issue.
         foreach ($transitions[$issue->getFormattedIssueNo()] as $transition) {
             if (TBGSettings::get('vcs_workflow_' . $project->getID(), 'vcs_integration') == TBGVCSIntegration::WORKFLOW_ENABLED) {
                 TBGContext::setUser($user);
                 TBGSettings::forceSettingsReload();
                 TBGContext::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 = TBGResolution::getResolutionByKeyish($value)) instanceof TBGResolution) {
                                             TBGContext::getRequest()->setParameter('resolution_id', $resolution->getID());
                                         }
                                         break;
                                     case 'status':
                                         if (($status = TBGStatus::getStatusByKeyish($value)) instanceof TBGStatus) {
                                             TBGContext::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(TBGContext::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 TBGVCSIntegrationFile();
         $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";
     }
     TBGEvent::createNew('vcs_integration', 'new_commit')->trigger(array('commit' => $commit));
     return $output;
 }
 public function addNewCommit($project, $commit_msg, $old_rev, $new_rev, $date = null, $changed, $author)
 {
     /* Find issues to update */
     $fixes_grep = "#((bug|issue|ticket|fix|fixes|fixed|fixing|applies to|closes|references|ref|addresses|re|see|according to|also see)\\s\\#?(([A-Z0-9]+\\-)?\\d+))#ie";
     $output = '';
     $f_issues = array();
     try {
         TBGContext::getI18n();
     } catch (Exception $e) {
         TBGContext::reinitializei18n();
     }
     try {
         $project = new TBGProject($project);
     } catch (Exception $e) {
         return TBGContext::getI18n()->__('Error: Invalid project ID');
     }
     if (preg_match_all($fixes_grep, $commit_msg, $f_issues)) {
         // Github
         if (is_array($changed)) {
             $entries = $changed;
             $changed = '';
             // Now handle changed files
             foreach ($entries[0] as $file) {
                 $changed .= 'M' . $file . "\n";
             }
             // Now handle new files
             foreach ($entries[1] as $file) {
                 $changed .= 'A' . $file . "\n";
             }
             // Now handle deleted files
             foreach ($entries[2] as $file) {
                 $changed .= 'D' . $file . "\n";
             }
         }
         $f_issues = array_unique($f_issues[3]);
         $file_lines = preg_split('/[\\n\\r]+/', $changed);
         $files = array();
         foreach ($file_lines as $aline) {
             $action = substr($aline, 0, 1);
             if ($action == "A" || $action == "U" || $action == "D" || $action == "M") {
                 $theline = trim(substr($aline, 1));
                 $files[] = array($action, $theline);
             }
         }
         foreach ($f_issues as $issue_no) {
             TBGContext::setCurrentProject($project);
             $theIssue = TBGIssue::getIssueFromLink($issue_no, true);
             if ($theIssue instanceof TBGIssue) {
                 $uid = 0;
                 /*
                  * 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 just say the user is id 0 (unknown user).
                  */
                 if (preg_match("/(?<=<)(.*)(?=>)/", $author, $matches)) {
                     $email = $matches[0];
                     // a)
                     $crit = new B2DBCriteria();
                     $crit->setFromTable(TBGUsersTable::getTable());
                     $crit->addSelectionColumn(TBGUsersTable::ID);
                     $crit->addWhere(TBGUsersTable::EMAIL, $email);
                     $row = TBGUsersTable::getTable()->doSelectOne($crit);
                     if ($row != null) {
                         $uid = $row->get(TBGUsersTable::ID);
                     } else {
                         // Not found by email
                         preg_match("/(?<=^)(.*)(?= <)/", $author, $matches);
                         $author = $matches[0];
                     }
                 }
                 // b)
                 if ($uid == 0) {
                     $crit = new B2DBCriteria();
                     $crit->setFromTable(TBGUsersTable::getTable());
                     $crit->addSelectionColumn(TBGUsersTable::ID);
                     $crit->addWhere(TBGUsersTable::REALNAME, $author);
                     $row = TBGUsersTable::getTable()->doSelectOne($crit);
                     if ($row != null) {
                         $uid = $row->get(TBGUsersTable::ID);
                     }
                 }
                 // c)
                 if ($uid == 0) {
                     $crit = new B2DBCriteria();
                     $crit->setFromTable(TBGUsersTable::getTable());
                     $crit->addSelectionColumn(TBGUsersTable::ID);
                     $crit->addWhere(TBGUsersTable::BUDDYNAME, $author);
                     $row = TBGUsersTable::getTable()->doSelectOne($crit);
                     if ($row != null) {
                         $uid = $row->get(TBGUsersTable::ID);
                     }
                 }
                 // d)
                 if ($uid == 0) {
                     $crit = new B2DBCriteria();
                     $crit->setFromTable(TBGUsersTable::getTable());
                     $crit->addSelectionColumn(TBGUsersTable::ID);
                     $crit->addWhere(TBGUsersTable::UNAME, $author);
                     $row = TBGUsersTable::getTable()->doSelectOne($crit);
                     if ($row != null) {
                         $uid = $row->get(TBGUsersTable::ID);
                     }
                 }
                 $theIssue->addSystemComment(TBGContext::getI18n()->__('Issue updated from code repository'), TBGContext::getI18n()->__('This issue has been updated with the latest changes from the code repository.<source>%commit_msg%</source>', array('%commit_msg%' => $commit_msg)), $uid);
                 foreach ($files as $afile) {
                     if ($date == null) {
                         $date = time();
                     }
                     TBGVCSIntegrationTable::addEntry($theIssue->getID(), $afile[0], $commit_msg, $afile[1], $new_rev, $old_rev, $uid, $date);
                 }
                 $output .= 'Updated ' . $theIssue->getFormattedIssueNo() . "\n";
             } else {
                 $output .= 'Can\'t find ' . $issue_no . ' so not updating that one.' . "\n";
             }
         }
     }
     return $output;
 }
예제 #12
0
 protected function _loadSelectedProjectAndIssueTypeFromRequestForReportIssueAction(TBGRequest $request)
 {
     try {
         if ($project_key = $request->getParameter('project_key')) {
             $this->selected_project = TBGProject::getByKey($project_key);
         } elseif ($project_id = $request->getParameter('project_id')) {
             $this->selected_project = TBGContext::factory()->TBGProject($project_id);
         }
     } catch (Exception $e) {
     }
     if ($this->selected_project instanceof TBGProject) {
         TBGContext::setCurrentProject($this->selected_project);
     }
     if ($this->selected_project instanceof TBGProject) {
         $this->issuetypes = $this->selected_project->getIssuetypeScheme()->getIssuetypes();
     } else {
         $this->issuetypes = TBGIssuetype::getAll();
     }
     if ($request->hasParameter('issuetype')) {
         $this->selected_issuetype = TBGIssuetype::getIssuetypeByKeyish($request->getParameter('issuetype'));
     }
     if (!$this->selected_issuetype instanceof TBGIssuetype) {
         $this->issuetype_id = $request->getParameter('issuetype_id');
         if ($this->issuetype_id) {
             try {
                 $this->selected_issuetype = TBGContext::factory()->TBGIssuetype($this->issuetype_id);
             } catch (Exception $e) {
             }
         }
     } else {
         $this->issuetype_id = $this->selected_issuetype->getID();
     }
 }