Пример #1
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;
 }
Пример #2
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;
 }