/** * update an entry * * <code> * $entry = new DayEntry(); * $entry->set("id" 11111); * $entry->set("notes", "Test Support"); * $entry->set("hours", 3); * $entry->set("project_id", 3); * $entry->set("task_id", 14); * $entry->set("spent_at", "Tue, 17 Oct 2006"); * * $api = new HarvestApi(); * * $result = $api->updateEntry($entry); * if ($result->isSuccess()) { * // success logic * } * </code> * * @param DayEntry $entry Day Entry * @return Result */ public function updateEntry(DayEntry $entry) { $url = "daily/update/{$entry->id}"; return $this->performPost($url, $entry->toXML()); }
/** * update an entry * * <code> * $entry = new DayEntry(); * $entry->set("id" 11111); * $entry->set("notes", "Test Support"); * $entry->set("hours", 3); * $entry->set("project_id", 3); * $entry->set("task_id", 14); * $entry->set("spent_at", "Tue, 17 Oct 2006"); * * $api = new HarvestApi(); * * $result = $api->try($entry); * if ($result->isSuccess()) { * // success logic * } * </code> * * @param DayEntry $entry * @param bool $other_user * @return Result * * @see http://www.getharvest.com/api/time-tracking#other-users */ public function updateEntry(DayEntry $entry, $other_user = true) { $url = "daily/update/{$entry->id}"; if ($other_user) { $url .= "?of_user="******"user-id"); } return $this->performPost($url, $entry->toXML()); }
/** * Get redmine issue matching this harvest entry and in the right project. * * @param \Harvest\Model\DayEntry $entry * * @return array|bool * Array of redmine issue information or FALSE if no match found */ protected function getRedmineIssue(DayEntry $entry) { // Load the Redmine issue and check if the Harvest time entry ID is there, if so, skip. $redmine_issue_numbers = []; preg_match('/#([0-9]+)/', $entry->get('notes'), $redmine_issue_numbers); // Strip the leading '#', and take the first entry. $redmine_issue_number = reset($redmine_issue_numbers); $redmine_issue_number = str_replace('#', '', $redmine_issue_number); if (!$redmine_issue_number) { // The resulting value is not a number. $this->userTimeEntryErrors[$entry->get('user-id')]['no-number'][] = ['entry' => $entry]; $this->output->writeln('<comment>Skipping entry, it does not look like there is an issue number here.'); return false; } $this->setRedmineClient(); $issue_api = new Redmine\Api\Issue($this->redmineClient); $redmine_issue = $issue_api->show($redmine_issue_number); if (!$redmine_issue || !isset($redmine_issue['issue']['project']['id'])) { // Issue doesn't exist in Redmine; this is probably a GitHub issue reference. $this->userTimeEntryErrors[$entry->get('user-id')]['missing-issue'][] = ['entry' => $entry]; $this->output->writeln(sprintf('<error>- Could not find Redmine issue %d!</error>', $redmine_issue_number)); $this->errors = true; return false; } // Validate that issue ID exists in project. if (isset($this->projectMap[$entry->get('project-id')])) { $project_names = []; $found = false; foreach ($this->projectMap[$entry->get('project-id')] as $project) { $project_names[] = current($project); if (isset($project[$redmine_issue['issue']['project']['id']])) { $found = true; } } if (!$found) { // The issue number doesn't belong to the Harvest project we are looking at // time entries for, so continue. It's probably a GitHub issue ref. $this->userTimeEntryErrors[$entry->get('user-id')]['issue-not-in-project'][] = ['entry' => $entry]; $this->output->writeln(sprintf('<error>- Issue %d does not exist in the Redmine project(s) %s. Time entry: \'%s\'</error>', $redmine_issue_number, implode(',', $project_names), $entry->toXML())); $this->errors = true; return false; } } return $redmine_issue; }