Exemplo n.º 1
0
 public function syncWithJira()
 {
     $staff_list = Staff::all();
     Timelog::where('project_id', '=', $this->id)->delete();
     $issue_service = new IssueService(app(ConfigurationInterface::class));
     $start = 0;
     while (1) {
         try {
             $issues = $issue_service->search("project={$this->jira_key} and timespent>0 and updated >= {$this->start_date}", $start, 250, ["key", "worklog"]);
         } catch (JiraException $exception) {
             return false;
         }
         if (count($issues->getIssues()) == 0) {
             break;
         }
         $timelogs = [];
         foreach ($issues->getIssues() as $issue) {
             $jira_work_logs = $issue->fields->worklog->worklogs;
             foreach ($jira_work_logs as $jira_work_log) {
                 if (!isset($jira_work_log->author)) {
                     continue;
                 }
                 $employee = $staff_list->where('email', $jira_work_log->author->emailAddress)->first();
                 if ($employee == null) {
                     continue;
                 }
                 $timelogs[] = ['project_id' => $this->id, 'staff_id' => $employee->id, 'time_spent' => $jira_work_log->timeSpentSeconds, 'jira_id' => $jira_work_log->id, 'started' => $jira_work_log->started];
             }
         }
         Timelog::insert($timelogs);
         $start += count($issues->getIssues());
     }
     return true;
 }