diff --git a/src/Config.php b/src/Config.php index a84fdcb..731c9c7 100644 --- a/src/Config.php +++ b/src/Config.php @@ -3,7 +3,7 @@ namespace Aerex\TaskwarriorPlugin; use DavidBadura\Taskwarrior\Taskwarrior; -use Aerex\Taskwarrior\TaskwarriorManager; +use Aerex\TaskwarriorPlugin\TaskwarriorManager; class Config { diff --git a/src/Processors/CalendarComponetInterface.php b/src/Processors/CalendarComponetInterface.php new file mode 100644 index 0000000..c22e5a2 --- /dev/null +++ b/src/Processors/CalendarComponetInterface.php @@ -0,0 +1,15 @@ + diff --git a/src/Processors/ToDo.php b/src/Processors/ToDo.php new file mode 100644 index 0000000..52d4fa9 --- /dev/null +++ b/src/Processors/ToDo.php @@ -0,0 +1,21 @@ + diff --git a/src/Task.php b/src/Task.php new file mode 100644 index 0000000..01b312f --- /dev/null +++ b/src/Task.php @@ -0,0 +1,29 @@ +DESCRIPTION) && isset($ToDoComponent->SUMMARY)){ + $description = $summary; + } else if(!isset($ToDoComponent->DESCRIPTION) && !isset($ToDoComponent->SUMMARY)){ + throw new Exception("Task must have a description or summary"); + } + } + + public + +} diff --git a/src/Properties/TaskwarriorProps.php b/src/Validators/TaskwarriorProps.php similarity index 100% rename from src/Properties/TaskwarriorProps.php rename to src/Validators/TaskwarriorProps.php diff --git a/src/iCalEventProcessor.php b/src/iCalEventProcessor.php index 6dcb6ef..9f0c7b0 100644 --- a/src/iCalEventProcessor.php +++ b/src/iCalEventProcessor.php @@ -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;