refactor: leverage Task and TaskManager external api methods to create task

refactor: remove uneeded configuration
This commit is contained in:
2018-10-28 00:11:01 -05:00
parent 5201db7d22
commit 88a78aeae7
4 changed files with 138 additions and 87 deletions

View File

@@ -69,24 +69,35 @@ class iCalEventProcessor {
if($this->taskwarrior->exists($ToDoComponent->UID)){
$this->logger->error("Event already exists " . (string)$ToDoComponent->UID);
throw new Exception\BadRequest("Event already exists " . $ToDoComponent->UID);
}
try {
$this->taskwarrior->setUUID($ToDoComponent->UID);
$this->taskwarrior->setEntryTime($ToDoComponent->DSTAMP);
$this->taskwarrior->setDueDate($ToDoComponent->DUE);
$this->taskwarrior->setModifiedTime($ToDoComponent->{'LAST-MODIFIED'});
$this->taskwarrior->setStartTime($ToDoComponent->DSTART);
$this->taskwarrior->setEndTime($ToDoComponent->DTEND);
$this->taskwarrior->setSummary($ToDoComponent->DESCRIPTION);
$this->taskwarrior->setCategories($ToDoComponent->CATEGORIES);
$this->taskwarrior->setDescription($ToDoComponent->DESCRIPTION);
$this->taskwarrior->build();
$this->taskwarrior->save();
// parse iCalendar event times to DateTime objects
$entry = $this->taskwarrior->parseiCalDateTime($ToDoComponent->DSTAMP);
$start = $this->taskwarrior->parseiCalDateTime($ToDoComponent->DSTART);
$modified = $this->taskwarrior->parseiCalDateTime($ToDoComponent->{'LAST-MODIFIED'});
$end = $this->taskwarrior->parseiCalDateTime($ToDoComponent->DTEND);
$task = $this->taskwarrior->createTask($ToDoComponent->UID);
$tags = $this->taskwarrior->convertToStringArray($ToDoComponent->CATEGORIES);
$task->setTags($tags);
$task->setDue($ToDoComponent->DUE->getDateTime());
$task->setDescription($ToDoComponent->DESCRIPTION);
// override protected taskwarrior properties using iCal event
$this->taskwarrior->setValue($task, $this->taskwarrior::ENTRY, $entry);
$this->taskwarrior->setValue($task, $this->taskwarrior::START, $start);
$this->taskwarrior->setValue($task, $this->taskwarrior::MODIFIED, $modified);
$this->taskwarrior->setValue($task, $this->taskwarrior::END, $end);
$this->taskwarrior->save($task);
} catch(Exception $e){
$this->logger->error($e->message);