refactor: remove builder class and use concrete class
tests: added more unit tests for event processor
This commit is contained in:
114
src/iCalEventProcessor.php
Normal file
114
src/iCalEventProcessor.php
Normal file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
namespace Aerex\TaskwarriorPlugin;
|
||||
|
||||
use Aerex\TaskwarriorPlugin\Config;
|
||||
use Sabre\DAV\Exception;
|
||||
use Sabre\VObject\Component\VEvent;
|
||||
use Sabre\VObject\Component\VTodo;
|
||||
|
||||
|
||||
class iCalEventProcessor {
|
||||
|
||||
/**
|
||||
* @var Config
|
||||
*/
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
*/
|
||||
private $taskrc;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
||||
private $taskDataDir;
|
||||
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $cachedTasks = [];
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
||||
private $taskBinFile;
|
||||
|
||||
|
||||
/**
|
||||
* @var Taskwarrior
|
||||
*/
|
||||
|
||||
private $taskwarrior;
|
||||
|
||||
|
||||
public function __construct(Config $taskConfig = null){
|
||||
if(!is_null($taskConfig)){
|
||||
$this->taskConfig = $taskConfig;
|
||||
} else {
|
||||
$this->taskConfig = new Config();
|
||||
}
|
||||
|
||||
$this->taskwarrior = $this->taskConfig->getTaskwarriorInstance();
|
||||
$this->logger = $this->taskConfig->getLogger();
|
||||
}
|
||||
|
||||
|
||||
public function importTask(VTodo $ToDoComponent = null){
|
||||
|
||||
if(!isset($ToDoComponent)){
|
||||
$this->logger->error("vCal ToDo component is not defined");
|
||||
throw new Exception("vCal Todo component is not defined");
|
||||
}
|
||||
|
||||
|
||||
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();
|
||||
|
||||
} catch(Exception $e){
|
||||
$this->logger->error($e->message);
|
||||
throw $e;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
?>
|
Reference in New Issue
Block a user