Example #1
0
 /**
  * Execute the controller.
  *
  * @return  string
  *
  * @since   1.0
  */
 public function execute()
 {
     /* @type \JTracker\Application $app */
     $app = $this->getContainer()->get('app');
     $app->getUser()->authorize('manage');
     $project = $app->getProject();
     try {
         $this->model->setProject($project);
         $data = $app->input->get('category', array(), 'array');
         if (isset($data['id'])) {
             $this->model->save($data);
         } else {
             $this->model->add($data);
         }
         // Reload the project.
         $this->model->setProject($project);
         $app->enqueueMessage('The changes have been saved.', 'success');
         $app->redirect($app->get('uri.base.path') . 'category/' . $project->alias);
     } catch (\Exception $exception) {
         $app->enqueueMessage($exception->getMessage(), 'error');
         if ($app->input->get('id')) {
             $app->redirect($app->get('uri.base.path') . 'category/' . $project->alias . '/' . $app->input->get('id') . '/edit');
         } else {
             $app->redirect($app->get('uri.base.path') . 'category/' . $project->alias . '/add');
         }
     }
     parent::execute();
 }
Example #2
0
 /**
  * Method to render the view.
  *
  * @return  string  The rendered view.
  *
  * @throws  \RuntimeException
  *
  * @since  1.0
  */
 public function render()
 {
     // Set the vars to the template.
     $this->renderer->set('state', $this->model->getState());
     $this->renderer->set('project', $this->getProject());
     $this->renderer->set('item', $this->getItem());
     return parent::render();
 }
Example #3
0
 /**
  * Execute the controller.
  *
  * @return  string
  *
  * @since   1.0
  */
 public function execute()
 {
     /* @type \JTracker\Application $application */
     $application = $this->getContainer()->get('app');
     $application->getUser()->authorize('manage');
     $item = $this->model->getItem($application->input->getUint('id'));
     $this->view->setProject($application->getProject());
     $this->model->setProject($application->getProject());
     $this->view->setItem($item);
     return parent::execute();
 }
Example #4
0
 /**
  * Execute the controller.
  *
  * @return  string
  *
  * @since   1.0
  */
 public function execute()
 {
     /* @type \JTracker\Application $application */
     $application = $this->getContainer()->get('app');
     $model = new CategoryModel($this->getContainer()->get('db'));
     try {
         $model->delete($application->input->get('id'));
         $application->enqueueMessage(g11n3t('The category has been deleted'), 'success');
     } catch (\Exception $exception) {
         $application->enqueueMessage($exception->getMessage(), 'error');
     }
     $application->redirect($application->get('uri.base.path') . 'category/' . $application->getProject()->alias);
     return parent::execute();
 }
Example #5
0
 /**
  * Setting model state that will be used for filtering.
  *
  * @return  void
  *
  * @since   1.0
  */
 private function setModelState()
 {
     /* @type \JTracker\Application $application */
     $application = $this->getContainer()->get('app');
     $state = $this->model->getState();
     $projectId = $application->getProject()->project_id;
     // Set up filters
     $sort = $application->getUserStateFromRequest('project_' . $projectId . '.filter.sort', 'sort', 'issue', 'word');
     $direction = $application->getUserStateFromRequest('project_' . $projectId . '.filter.direction', 'direction', 'desc', 'word');
     // Update the sort filters from the GET request
     switch (strtolower($sort)) {
         case 'updated':
             $state->set('list.ordering', 'a.modified_date');
             $sort = $sort + 2;
             break;
         default:
             $sort = 0;
     }
     switch (strtoupper($direction)) {
         case 'ASC':
             $state->set('list.direction', 'ASC');
             $sort++;
             break;
         default:
             $state->set('list.direction', 'DESC');
     }
     $state->set('filter.sort', $sort);
     $priority = $application->getUserStateFromRequest('project_' . $projectId . '.filter.priority', 'priority', 0, 'cmd');
     // Update the priority filter from the GET request
     switch (strtolower($priority)) {
         case 'critical':
             $priority = 1;
             break;
         case 'urgent':
             $priority = 2;
             break;
         case 'medium':
             $priority = 3;
             break;
         case 'low':
             $priority = 4;
             break;
         case 'very-low':
             $priority = 5;
             break;
     }
     $state->set('filter.priority', $priority);
     $issuesState = $application->getUserStateFromRequest('project_' . $projectId . '.filter.state', 'state', 'open', 'word');
     // Update the state filter from the GET request
     switch (strtolower($issuesState)) {
         case 'open':
             $issuesState = 0;
             break;
         case 'closed':
             $issuesState = 1;
             break;
     }
     $state->set('filter.state', $issuesState);
     $state->set('filter.status', $application->getUserStateFromRequest('project_' . $projectId . '.filter.status', 'status', 0, 'uint'));
     $state->set('filter.search', $application->getUserStateFromRequest('project_' . $projectId . '.filter.search', 'search', '', 'string'));
     $user = $application->getUserStateFromRequest('project_' . $projectId . '.filter.user', 'user', 0, 'word');
     // Update the user filter from the GET request
     switch ((string) $user) {
         case 'created':
             $user = 1;
             break;
         case 'participated':
             $user = 2;
             break;
     }
     $state->set('filter.user', $user);
     $state->set('filter.created_by', $application->getUserStateFromRequest('project_' . $projectId . '.filter.created_by', 'created_by', '', 'string'));
     $categoryAlias = $application->input->get->get('category', '', 'cmd');
     // Update the category filter from the GET request
     if ($categoryAlias != '' && !is_numeric($categoryAlias)) {
         $categoryId = 0;
         $categoryModel = new CategoryModel($this->getContainer()->get('db'));
         $category = $categoryModel->setProject($application->getProject())->getByAlias($categoryAlias);
         if ($category) {
             $categoryId = $category->id;
         }
     } else {
         $categoryId = $application->getUserStateFromRequest('project_' . $projectId . '.filter.category', 'category', 0, 'int');
     }
     $state->set('filter.category', (int) $categoryId);
     $state->set('filter.label', $application->getUserStateFromRequest('project_' . $projectId . '.filter.label', 'label', 0, 'uint'));
     $state->set('stools-active', $application->input->get('stools-active', 0, 'uint'));
     if ($application->getUser()->username) {
         $state->set('username', $application->getUser()->username);
     }
     // Update the page from the GET request
     $state->set('page', $application->getUserStateFromRequest('project_' . $projectId . '.page', 'page', 1, 'uint'));
     $state->set('filter.tests', $application->getUserStateFromRequest('project_' . $projectId . '.filter.tests', 'tests', 0, 'uint'));
     $state->set('filter.easytest', $application->getUserStateFromRequest('project_' . $projectId . '.filter.easytest', 'easytest', 0, 'uint'));
     $state->set('filter.type', $application->getUserStateFromRequest('project_' . $projectId . '.filter.type', 'type', 0, 'uint'));
     $this->model->setState($state);
 }
Example #6
0
 /**
  * Method to get a DatabaseQuery object for retrieving the data set from a database for ajax request.
  *
  * @return DatabaseQuery
  *
  * @since 1.0
  */
 protected function getAjaxListQuery()
 {
     $db = $this->getDb();
     $query = $db->getQuery(true);
     $query->select("a.priority, a.issue_number, a.title, a.foreign_number, a.opened_date, a.closed_date, a.modified_date, a.labels, a.merge_state");
     $query->from($db->quoteName('#__issues', 'a'));
     // Join over the status.
     $query->select('s.status AS status_title, s.closed AS closed_status');
     $query->join('LEFT', '#__status AS s ON a.status = s.id');
     $filter = $this->getProject()->project_id;
     if ($filter) {
         $query->where($db->quoteName('a.project_id') . ' = ' . (int) $filter);
     }
     $filter = $this->state->get('filter.search');
     if ($filter) {
         $query = $this->processSearchFilter($query, $filter);
     }
     $filter = $this->state->get('filter.status');
     if ($filter) {
         $query->where($db->quoteName('a.status') . ' = ' . (int) $filter);
     }
     $filter = $this->state->get('filter.state');
     if (is_numeric($filter)) {
         $query->where($db->quoteName('s.closed') . ' = ' . (int) $filter);
     }
     $filter = $this->state->get('filter.priority');
     if ($filter) {
         $query->where($db->quoteName('a.priority') . ' = ' . (int) $filter);
     }
     $filter = $this->state->get('filter.user');
     if ($filter && is_numeric($filter)) {
         $username = $this->state->get('username');
         switch ($filter) {
             case 1:
                 $query->where($db->quoteName('a.opened_by') . ' = ' . $db->quote($username));
                 break;
             case 2:
                 // Join over the activities.
                 $query->join('LEFT', '#__activities AS ac ON a.issue_number = ac.issue_number');
                 $query->where($db->quoteName('ac.user') . ' = ' . $db->quote($username));
                 $query->where($db->quoteName('ac.project_id') . ' = ' . (int) $this->getProject()->project_id);
                 $query->group('a.issue_number');
                 break;
         }
     }
     $filter = $this->state->get('filter.category');
     if ($filter && is_numeric($filter)) {
         $categoryModel = new CategoryModel($db);
         $issues = $categoryModel->getIssueIdsByCategory($filter);
         if ($issues != null) {
             $issueId = array();
             foreach ($issues as $issue) {
                 $issueId[] = $issue->issue_id;
             }
             $issueId = implode(', ', $issueId);
         } else {
             $issueId = 0;
         }
         $query->where($db->quoteName('a.id') . ' IN (' . $issueId . ')');
     }
     $filter = $this->state->get('filter.tests');
     if ($filter && is_numeric($filter)) {
         // Common query elements
         $query->leftJoin($db->quoteName('#__issues_tests', 'it') . 'ON a.id = it.item_id')->where($db->quoteName('a.has_code') . ' = 1')->group('a.issue_number');
         switch ($filter) {
             case 1:
                 $query->where($db->quoteName('it.result') . ' = 1')->having('COUNT(it.item_id) = 1');
                 break;
             case 2:
                 $query->where($db->quoteName('it.result') . ' = 1')->having('COUNT(it.item_id) > 1');
                 break;
             case 3:
                 $query->having('COUNT(it.item_id) = 0');
                 break;
         }
     }
     $filter = $this->state->get('filter.easytest');
     if ($filter && is_numeric($filter)) {
         $query->where($db->quoteName('a.easy') . ' = ' . (int) $filter);
     }
     $ordering = $db->escape($this->state->get('list.ordering', 'a.issue_number'));
     $direction = $db->escape($this->state->get('list.direction', 'DESC'));
     $query->order($ordering . ' ' . $direction);
     return $query;
 }
Example #7
0
 /**
  * Execute the controller.
  *
  * @throws \Exception
  * @throws \JTracker\Authentication\Exception\AuthenticationException
  *
  * @return  string  The rendered view.
  *
  * @since   1.0
  */
 public function execute()
 {
     /* @type \JTracker\Application $application */
     $application = $this->getContainer()->get('app');
     $src = $application->input->get('item', array(), 'array');
     $user = $application->getUser();
     $project = $application->getProject();
     $model = new IssueModel($this->getContainer()->get('db'));
     $model->setProject($project);
     $issueNumber = isset($src['issue_number']) ? (int) $src['issue_number'] : 0;
     if (!$issueNumber) {
         throw new \UnexpectedValueException('No issue number received.');
     }
     $item = $model->getItem($issueNumber);
     $data = array();
     if ($user->check('edit')) {
         // The user has full "edit" permission.
         $data = $src;
     } elseif ($user->canEditOwn($item->opened_by)) {
         // The user has "edit own" permission.
         $data['id'] = (int) $src['id'];
         $data['issue_number'] = (int) $src['issue_number'];
         $data['title'] = $src['title'];
         $data['description_raw'] = $src['description_raw'];
         // Take the remaining values from the stored item
         $data['status'] = $item->status;
         $data['priority'] = $item->priority;
         $data['build'] = $item->build;
         $data['rel_number'] = $item->rel_number;
         $data['rel_type'] = $item->rel_type;
         $data['easy'] = $item->easy;
     } else {
         // The user has no "edit" permission.
         throw new AuthenticationException($user, 'edit');
     }
     $gitHub = GithubFactory::getInstance($application);
     if ($project->gh_user && $project->gh_project) {
         // Project is managed on GitHub
         // Check if the state has changed (e.g. open/closed)
         $oldState = $model->getOpenClosed($item->status);
         $state = $model->getOpenClosed($data['status']);
         try {
             $this->updateGitHub($item->issue_number, $data, $state, $oldState);
         } catch (GithubException $exception) {
             // DEBUG - @todo remove in stable
             $dump = ['exception' => $exception->getCode() . ' ' . $exception->getMessage(), 'user' => $project->gh_user, 'project' => $project->gh_project, 'issueNo' => $item->issue_number, 'state' => $state, 'old_state' => $oldState, 'data' => $data];
             var_dump($dump);
             die('Unrecoverable GitHub error - sry ;(');
         }
         // Render the description text using GitHub's markdown renderer.
         $data['description'] = $gitHub->markdown->render($data['description_raw'], 'gfm', $project->gh_user . '/' . $project->gh_project);
     } else {
         // Project is managed by JTracker only
         // Render the description text using GitHub's markdown renderer.
         $data['description'] = $gitHub->markdown->render($src['description_raw'], 'markdown');
     }
     try {
         $data['modified_by'] = $user->username;
         $categoryModel = new CategoryModel($this->getContainer()->get('db'));
         $category['issue_id'] = $data['id'];
         $category['categories'] = $application->input->get('categories', null, 'array');
         $category['modified_by'] = $user->username;
         $category['issue_number'] = $data['issue_number'];
         $category['project_id'] = $project->project_id;
         $categoryModel->updateCategory($category);
         // Save the record.
         $model->save($data);
         $application->enqueueMessage(g11n3t('The changes have been saved.'), 'success')->redirect('/tracker/' . $application->input->get('project_alias') . '/' . $issueNumber);
     } catch (\Exception $exception) {
         $application->enqueueMessage($exception->getMessage(), 'error');
         // @todo preserve data when returning to edit view on failure.
         $application->redirect($application->get('uri.base.path') . 'tracker/' . $application->input->get('project_alias') . '/' . $issueNumber . '/edit');
     }
     return parent::execute();
 }
Example #8
0
 /**
  * Common function to process the filters for a query based on the model state
  *
  * @param   DatabaseQuery  $query  DatabaseQuery object
  *
  * @return  DatabaseQuery
  *
  * @since   1.0
  */
 private function processStateFilter(DatabaseQuery $query)
 {
     $db = $this->getDb();
     $filter = $this->getProject()->project_id;
     if ($filter) {
         $query->where($db->quoteName('a.project_id') . ' = ' . (int) $filter);
     }
     $filter = $this->state->get('filter.search');
     if ($filter) {
         $query = $this->processSearchFilter($query, $filter);
     }
     $filter = $this->state->get('filter.status');
     if ($filter) {
         $query->where($db->quoteName('a.status') . ' = ' . (int) $filter);
     }
     $filter = $this->state->get('filter.state');
     // State == 2 means "all".
     if (is_numeric($filter) && 2 != $filter) {
         $query->where($db->quoteName('s.closed') . ' = ' . (int) $filter);
     }
     $filter = $this->state->get('filter.priority');
     if ($filter) {
         $query->where($db->quoteName('a.priority') . ' = ' . (int) $filter);
     }
     $filter = $this->state->get('filter.user');
     if ($filter && is_numeric($filter)) {
         $username = $this->state->get('username');
         switch ($filter) {
             case 1:
                 $query->where($db->quoteName('a.opened_by') . ' = ' . $db->quote($username));
                 break;
             case 2:
                 // Join over the activities.
                 $query->join('LEFT', '#__activities AS ac ON a.issue_number = ac.issue_number');
                 $query->where($db->quoteName('ac.user') . ' = ' . $db->quote($username));
                 $query->where($db->quoteName('ac.project_id') . ' = ' . (int) $this->getProject()->project_id);
                 $query->group('a.issue_number');
                 break;
         }
     }
     $filter = $this->state->get('filter.created_by');
     if ($filter) {
         // Clean filter variable
         $filter = $db->quote('%' . $db->escape(StringHelper::strtolower($filter), true) . '%', false);
         $query->where($db->quoteName('a.opened_by') . ' LIKE ' . $filter);
     }
     $filter = $this->state->get('filter.category');
     if ($filter && is_numeric($filter)) {
         $categoryModel = new CategoryModel($db);
         // If the category filter equals -1, that means we want issues without category.
         if ($filter == -1) {
             $issues = $categoryModel->getIssueIdsWithCategory();
         } else {
             $issues = $categoryModel->getIssueIdsByCategory($filter);
         }
         if ($issues != null) {
             $issueId = array();
             foreach ($issues as $issue) {
                 $issueId[] = $issue->issue_id;
             }
             $issueId = implode(', ', $issueId);
         } else {
             $issueId = 0;
         }
         // Handle the no category filter
         if ($filter == -1) {
             $query->where($db->quoteName('a.id') . ' NOT IN (' . $issueId . ')');
         } else {
             $query->where($db->quoteName('a.id') . ' IN (' . $issueId . ')');
         }
     }
     $filter = $this->state->get('filter.label');
     if ($filter && is_numeric($filter)) {
         $query->where('FIND_IN_SET(' . $filter . ', ' . $db->quoteName('a.labels') . ')');
     }
     $filter = $this->state->get('filter.tests');
     if ($filter && is_numeric($filter)) {
         // Common query elements
         $query->leftJoin($db->quoteName('#__issues_tests', 'it') . 'ON a.id = it.item_id')->where($db->quoteName('a.has_code') . ' = 1')->group('a.issue_number');
         switch ($filter) {
             case 1:
                 $query->where($db->quoteName('it.result') . ' = 1')->having('COUNT(it.item_id) = 1');
                 break;
             case 2:
                 $query->where($db->quoteName('it.result') . ' = 1')->having('COUNT(it.item_id) > 1');
                 break;
             case 3:
                 $query->having('COUNT(it.item_id) = 0');
                 break;
         }
     }
     $filter = $this->state->get('filter.easytest');
     if ($filter && is_numeric($filter)) {
         $query->where($db->quoteName('a.easy') . ' = ' . (int) $filter);
     }
     return $query;
 }
Example #9
0
 /**
  * Execute the controller.
  *
  * @return  string  The rendered view.
  *
  * @since   1.0
  * @throws  \JTracker\Authentication\Exception\AuthenticationException
  * @throws  \RuntimeException
  * @throws  \UnexpectedValueException
  */
 public function execute()
 {
     /* @type \JTracker\Application $application */
     $application = $this->getContainer()->get('app');
     $src = $application->input->get('item', array(), 'array');
     $user = $application->getUser();
     $project = $application->getProject();
     $model = new IssueModel($this->getContainer()->get('db'));
     $model->setProject($project);
     $issueNumber = isset($src['issue_number']) ? (int) $src['issue_number'] : 0;
     if (!$issueNumber) {
         throw new \UnexpectedValueException('No issue number received.');
     }
     $item = $model->getItem($issueNumber);
     $data = array();
     if ($user->check('edit')) {
         // The user has full "edit" permission.
         $data = $src;
         // Allow admins to update labels and milestones
         if (!$user->check('manage')) {
             if (!empty($item->labels)) {
                 $data['labels'] = explode(',', $item->labels);
             }
             $data['milestone_id'] = $item->milestone_id;
         }
     } elseif ($user->canEditOwn($item->opened_by)) {
         // The user has "edit own" permission.
         $data['id'] = (int) $src['id'];
         $data['issue_number'] = (int) $src['issue_number'];
         $data['title'] = $src['title'];
         $data['description_raw'] = $src['description_raw'];
         // Take the remaining values from the stored item
         if (!empty($item->labels)) {
             $data['labels'] = explode(',', $item->labels);
         }
         $data['status'] = $item->status;
         $data['priority'] = $item->priority;
         $data['build'] = $item->build;
         $data['rel_number'] = $item->rel_number;
         $data['rel_type'] = $item->rel_type;
         $data['easy'] = $item->easy;
         $data['milestone_id'] = $item->milestone_id;
     } else {
         // The user has no "edit" permission.
         throw new AuthenticationException($user, 'edit');
     }
     $gitHub = GithubFactory::getInstance($application);
     // Check if the state has changed (e.g. open/closed)
     $oldState = $model->getOpenClosed($item->status);
     $state = $model->getOpenClosed($data['status']);
     // Project is managed on GitHub
     if ($project->gh_user && $project->gh_project) {
         // @todo assignee
         $assignee = null;
         // Prepare labels
         $ghLabels = [];
         if (!empty($data['labels'])) {
             foreach ($project->getLabels() as $id => $label) {
                 if (in_array($id, $data['labels'])) {
                     $ghLabels[] = $label->name;
                 }
             }
         }
         // Prepare milestone
         $ghMilestone = null;
         if (!empty($data['milestone_id'])) {
             foreach ($project->getMilestones() as $milestone) {
                 if ($milestone->milestone_id == $data['milestone_id']) {
                     $ghMilestone = $milestone->milestone_number;
                 }
             }
         }
         try {
             $gitHubResponse = $this->updateGitHub($item->issue_number, $data, $state, $oldState, $assignee, $ghMilestone, $ghLabels);
             // Set the modified_date from GitHub (important!)
             $data['modified_date'] = $gitHubResponse->updated_at;
         } catch (GithubException $exception) {
             $this->getContainer()->get('app')->getLogger()->error(sprintf('Error code %1$s received from GitHub when editing an issue with the following data:' . ' GitHub User: %2$s; GitHub Repo: %3$s; Issue Number: %4$s; State: %5$s, Old state: %6$s' . '  The error message returned was: %7$s', $exception->getCode(), $project->gh_user, $project->gh_project, $item->issue_number, $state, $oldState, $exception->getMessage()));
             throw new \RuntimeException('Invalid response from GitHub');
         }
         // Render the description text using GitHub's markdown renderer.
         $data['description'] = $gitHub->markdown->render($data['description_raw'], 'gfm', $project->gh_user . '/' . $project->gh_project);
     } else {
         // Project is managed by JTracker only
         // Render the description text using GitHub's markdown renderer.
         $data['description'] = $gitHub->markdown->render($src['description_raw'], 'markdown');
         $data['modified_date'] = (new Date())->format($this->getContainer()->get('db')->getDateFormat());
     }
     try {
         $data['modified_by'] = $user->username;
         // If the user have edit permission, let him / her modify the categories.
         if ($user->check('edit')) {
             $categoryModel = new CategoryModel($this->getContainer()->get('db'));
             $category['issue_id'] = $data['id'];
             $category['modified_by'] = $user->username;
             $category['categories'] = $application->input->get('categories', null, 'array');
             $category['issue_number'] = $data['issue_number'];
             $category['project_id'] = $project->project_id;
             $categoryModel->updateCategory($category);
         }
         // Pass the old and new states into the save method
         $data['old_state'] = $oldState;
         $data['new_state'] = $state;
         // Values that are not supposed to change.
         $data['commits'] = $item->commits;
         $data['pr_head_sha'] = $item->pr_head_sha;
         // Save the record.
         $model->save($data);
         $comment = $application->input->get('comment', '', 'raw');
         // Save the comment.
         if ($comment) {
             /* @type \JTracker\Github\Github $github */
             $github = $this->getContainer()->get('gitHub');
             $project = $application->getProject();
             $gitHubHelper = new GitHubHelper($github);
             $comment .= $gitHubHelper->getApplicationComment($application, $project, $issueNumber);
             $data = new \stdClass();
             $db = $this->getContainer()->get('db');
             if ($project->gh_user && $project->gh_project) {
                 $gitHubResponse = $github->issues->comments->create($project->gh_user, $project->gh_project, $issueNumber, $comment);
                 if (!isset($gitHubResponse->id)) {
                     throw new \RuntimeException('Invalid response from GitHub');
                 }
                 $data->created_at = $gitHubResponse->created_at;
                 $data->opened_by = $gitHubResponse->user->login;
                 $data->comment_id = $gitHubResponse->id;
                 $data->text_raw = $gitHubResponse->body;
                 $data->text = $github->markdown->render($comment, 'gfm', $project->gh_user . '/' . $project->gh_project);
             } else {
                 $date = new Date();
                 $data->created_at = $date->format($db->getDateFormat());
                 $data->opened_by = $application->getUser()->username;
                 $data->comment_id = '???';
                 $data->text_raw = $comment;
                 $data->text = $github->markdown->render($comment, 'markdown');
             }
             $table = new ActivitiesTable($db);
             $table->event = 'comment';
             $table->created_date = $data->created_at;
             $table->project_id = $project->project_id;
             $table->issue_number = $issueNumber;
             $table->gh_comment_id = $data->comment_id;
             $table->user = $data->opened_by;
             $table->text = $data->text;
             $table->text_raw = $data->text_raw;
             $table->store();
         }
         $application->enqueueMessage('The changes have been saved.', 'success')->redirect('/tracker/' . $application->input->get('project_alias') . '/' . $issueNumber);
     } catch (\RuntimeException $exception) {
         $application->enqueueMessage($exception->getMessage(), 'error');
         // @todo preserve data when returning to edit view on failure.
         $application->redirect($application->get('uri.base.path') . 'tracker/' . $application->input->get('project_alias') . '/' . $issueNumber . '/edit');
     }
     return parent::execute();
 }
Example #10
0
 /**
  * Execute the controller.
  *
  * @return  void
  *
  * @since   1.0
  * @throws  \RuntimeException
  */
 public function execute()
 {
     /* @type \JTracker\Application $application */
     $application = $this->getContainer()->get('app');
     $user = $application->getUser();
     $user->authorize('create');
     /* @type \Joomla\Github\Github $gitHub */
     $gitHub = $this->getContainer()->get('gitHub');
     $project = $application->getProject();
     $body = $application->input->get('body', '', 'raw');
     if (!$body) {
         throw new \RuntimeException('No body received.');
     }
     // Prepare issue for the store
     $data = array();
     $data['title'] = $application->input->getString('title');
     $data['milestone_id'] = $application->input->getInt('milestone_id');
     // Process labels
     $labels = [];
     foreach ($application->input->get('labels', [], 'array') as $labelId) {
         // Filter integer
         $labels[] = (int) $labelId;
     }
     /**
      * Store the "No code attached yet" label for CMS issue
      * @todo Remove after #596 is implemented
      */
     if ($project->project_id == 1 && !in_array(39, $labels)) {
         $labels[] = 39;
     }
     $data['labels'] = implode(',', $labels);
     $issueModel = new IssueModel($this->getContainer()->get('db'));
     $issueModel->setProject($project);
     // Project is managed on GitHub
     if ($project->gh_user && $project->gh_project) {
         // @todo assignee
         $assignee = null;
         // Prepare labels
         $ghLabels = [];
         if (!empty($labels)) {
             foreach ($project->getLabels() as $id => $label) {
                 if (in_array($id, $labels)) {
                     $ghLabels[] = $label->name;
                 }
             }
         }
         // Prepare milestone
         $ghMilestone = null;
         if (!empty($data['milestone_id'])) {
             foreach ($project->getMilestones() as $milestone) {
                 if ($milestone->milestone_id == $data['milestone_id']) {
                     $ghMilestone = $milestone->milestone_number;
                 }
             }
         }
         $gitHubResponse = $this->updateGitHub($data['title'], $body, $assignee, $ghMilestone, $ghLabels);
         $data['opened_date'] = $gitHubResponse->created_at;
         $data['modified_date'] = $gitHubResponse->created_at;
         $data['opened_by'] = $gitHubResponse->user->login;
         $data['modified_by'] = $gitHubResponse->user->login;
         $data['number'] = $gitHubResponse->number;
         $data['description'] = $gitHub->markdown->render($body, 'gfm', $project->gh_user . '/' . $project->gh_project);
     } else {
         $data['opened_date'] = (new Date())->format($this->getContainer()->get('db')->getDateFormat());
         $data['modified_date'] = (new Date())->format($this->getContainer()->get('db')->getDateFormat());
         $data['opened_by'] = $user->username;
         $data['modified_by'] = $user->username;
         $data['number'] = $issueModel->getNextNumber();
         $data['description'] = $gitHub->markdown->render($body, 'markdown');
     }
     $data['priority'] = $application->input->getInt('priority');
     $data['build'] = $application->input->getString('build');
     $data['project_id'] = $project->project_id;
     $data['issue_number'] = $data['number'];
     $data['description_raw'] = $body;
     // Store the issue
     try {
         // Save the issues and Get the issue id from model state
         $issue_id = $issueModel->add($data)->getState()->get('issue_id');
         // Save the category for the issue
         $category['issue_id'] = $issue_id;
         $category['categories'] = $application->input->get('categories', null, 'array');
         $categoryModel = new CategoryModel($this->getContainer()->get('db'));
         $categoryModel->saveCategory($category);
     } catch (\RuntimeException $e) {
         $application->enqueueMessage($e->getMessage(), 'error');
         $application->redirect($application->get('uri.base.path') . 'tracker/' . $project->alias . '/add');
     }
     $application->enqueueMessage(g11n3t('Your report has been submitted.'), 'success');
     $application->redirect($application->get('uri.base.path') . 'tracker/' . $project->alias . '/' . $data['number']);
     return;
 }
Example #11
0
 /**
  * Execute the controller.
  *
  * @return  void
  *
  * @since   1.0
  * @throws  \Exception
  */
 public function execute()
 {
     /* @type \JTracker\Application $application */
     $application = $this->getContainer()->get('app');
     $user = $application->getUser();
     $user->authorize('create');
     /* @type \Joomla\Github\Github $gitHub */
     $gitHub = $this->getContainer()->get('gitHub');
     $project = $application->getProject();
     $body = $application->input->get('body', '', 'raw');
     // Prepare issue for the store
     $data = array();
     $data['title'] = $application->input->getString('title');
     if (!$body) {
         throw new \Exception('No body received.');
     }
     $issueModel = new IssueModel($this->getContainer()->get('db'));
     $issueModel->setProject($project);
     if ($project->gh_user && $project->gh_project) {
         // Project is managed on GitHub
         $gitHubResponse = $gitHub->issues->create($project->gh_user, $project->gh_project, $data['title'], $body);
         if (!isset($gitHubResponse->id)) {
             throw new \Exception('Invalid response from GitHub');
         }
         $data['opened_date'] = $gitHubResponse->created_at;
         $data['modified_date'] = $gitHubResponse->created_at;
         $data['opened_by'] = $gitHubResponse->user->login;
         $data['modified_by'] = $gitHubResponse->user->login;
         $data['number'] = $gitHubResponse->number;
         $data['description'] = $gitHub->markdown->render($body, 'gfm', $project->gh_user . '/' . $project->gh_project);
     } else {
         // Project is managed by JTracker only
         $data['opened_date'] = (new Date())->format($this->getContainer()->get('db')->getDateFormat());
         $data['modified_date'] = (new Date())->format($this->getContainer()->get('db')->getDateFormat());
         $data['opened_by'] = $user->username;
         $data['modified_by'] = $user->username;
         $data['number'] = $issueModel->getNextNumber();
         $data['description'] = $gitHub->markdown->render($body, 'markdown');
     }
     $data['priority'] = $application->input->getInt('priority');
     $data['build'] = $application->input->getString('build');
     $data['project_id'] = $project->project_id;
     $data['issue_number'] = $data['number'];
     $data['description_raw'] = $body;
     // Store the issue
     try {
         // Save the issues and Get the issue id from model state
         $issue_id = $issueModel->add($data)->getState()->get('issue_id');
         // Save the category for the issue
         $category['issue_id'] = $issue_id;
         $category['categories'] = $application->input->get('categories', null, 'array');
         $categoryModel = new CategoryModel($this->getContainer()->get('db'));
         $categoryModel->saveCategory($category);
     } catch (\Exception $e) {
         $application->enqueueMessage($e->getMessage(), 'error');
         $application->redirect($application->get('uri.base.path') . 'tracker/' . $project->alias . '/add');
     }
     $application->enqueueMessage(g11n3t('Your report has been submitted.'), 'success');
     $application->redirect($application->get('uri.base.path') . 'tracker/' . $project->alias . '/' . $data['number']);
     return;
 }