refactor: extract ical processor code into an interface type
This commit is contained in:
@@ -61,6 +61,7 @@ class iCalEventProcessor {
|
||||
|
||||
public function importTask(VTodo $ToDoComponent = null){
|
||||
|
||||
echo $ToDoComponent->serialize();
|
||||
if(!isset($ToDoComponent)){
|
||||
$this->logger->error("vCal ToDo component is not defined");
|
||||
throw new Exception("vCal Todo component is not defined");
|
||||
@@ -68,43 +69,71 @@ class iCalEventProcessor {
|
||||
|
||||
|
||||
if($this->taskwarrior->exists($ToDoComponent->UID)){
|
||||
$this->logger->error("Event already exists " . (string)$ToDoComponent->UID);
|
||||
$this->taskwarrior->updateTask($ToDoComponent);
|
||||
$this->logger->error("Updating task " . (string)$ToDoComponent->UID);
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
$task = $this->taskwarrior->createiCalTask($ToDoComponent->UID);
|
||||
|
||||
// get description
|
||||
if(!isset($ToDoComponent->DESCRIPTION) && isset($ToDoComponent->SUMMARY)){
|
||||
$description = $summary;
|
||||
} else if(!isset($ToDoComponent->DESCRIPTION) && !isset($ToDoComponent->SUMMARY)){
|
||||
throw new Exception("Task must have a description or summary");
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
$start = $ToDoComponent->DSTART;
|
||||
$entry = $ToDoComponent->DSTAMP;
|
||||
$modified = $ToDoComponent->{'LAST-MODIFIED'};
|
||||
$end = $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
|
||||
// get start time
|
||||
if(!isset($ToDoComponent->DTSTAMP) && isset($ToDoComponent->DSTART)){
|
||||
$start = $this->taskwarrior->convertToCarbonDateTime($ToDoComponent->DTSTAMP);
|
||||
$entry = $start;
|
||||
} else if (!isset($ToDoComponent->DTSTAMP) && !isset($ToDoComponent->DSTART)){
|
||||
throw new Exception("Task must have an entry or start time");
|
||||
} else {
|
||||
$entry = $this->taskwarrior->convertToCarbonDateTime($ToDoComponent->DTSTAMP);
|
||||
}
|
||||
|
||||
$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);
|
||||
|
||||
if(isset($ToDoComponent->DSTART)){
|
||||
$start = $this->taskwarrior->convertToCarbonDateTime($ToDoComponent->DSTART);
|
||||
$this->taskwarrior->setValue($task, $this->taskwarrior::START, $start);
|
||||
}
|
||||
|
||||
if(isset($ToDoComponent->{'LAST-MODIFIED'})){
|
||||
$modified = $this->taskwarrior->convertToCarbonDateTime($ToDoComponent->{'LAST-MODIFIED'});
|
||||
$this->taskwarrior->setValue($task, $this->taskwarrior::MODIFIED, $modified);
|
||||
}
|
||||
|
||||
if(isset($ToDoComponent->DTEND)){
|
||||
$end = $this->taskwarrior->convertToCarbonDateTime($ToDoComponent->DTEND);
|
||||
$this->taskwarrior->setValue($task, $this->taskwarrior::MODIFIED, $modified);
|
||||
}
|
||||
|
||||
if(isset($ToDoComponent->DUE)){
|
||||
$due = $this->taskwarrior->convertToCarbonDateTime($ToDoComponent->DUE);
|
||||
$task->setDue($due);
|
||||
}
|
||||
|
||||
if(isset($ToDoComponent->DTEND)){
|
||||
$end = $this->taskwarrior->convertToCarbonDateTime($ToDoComponent->DTEND);
|
||||
$this->taskwarrior->setValue($task, $this->taskwarrior::END, $end);
|
||||
}
|
||||
|
||||
if(isset($ToDoComponent->CATEGORIES)){
|
||||
$tags = $this->taskwarrior->convertToStringArray($ToDoComponent->CATEGORIES);
|
||||
$task->setTags($tags);
|
||||
}
|
||||
|
||||
$this->taskwarrior->save($task);
|
||||
|
||||
} catch(Exception $e){
|
||||
echo $e->getMessage();
|
||||
|
||||
$this->logger->error($e->message);
|
||||
throw $e;
|
||||
|
||||
|
Reference in New Issue
Block a user