feat: added modify taskwarrior command
This commit is contained in:
parent
68470e3dee
commit
f713fbb16b
@ -118,7 +118,7 @@ class Plugin extends ServerPlugin {
|
|||||||
$response->setStatus(200);
|
$response->setStatus(200);
|
||||||
$response->setBody('');
|
$response->setBody('');
|
||||||
$response->setHeader('Content-Type', 'text/plain');
|
$response->setHeader('Content-Type', 'text/plain');
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -4,57 +4,89 @@ namespace Aerex\TaskwarriorPlugin\Taskwarrior\Commands;
|
|||||||
use Aerex\TaskwarriorPlugin\Taskwarrior\Task;
|
use Aerex\TaskwarriorPlugin\Taskwarrior\Task;
|
||||||
use Aerex\TaskwarriorPlugin\Config;
|
use Aerex\TaskwarriorPlugin\Config;
|
||||||
use Symfony\Component\Process\Process;
|
use Symfony\Component\Process\Process;
|
||||||
|
use Symfony\Component\Process\Exception\ProcessFailedException;
|
||||||
|
use Aerex\TaskwarriorPlugin\Exceptions\TaskwarriorCommandException;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class TodoStrategy implements IStrategy {
|
class TodoStrategy implements IStrategy {
|
||||||
|
private $config;
|
||||||
|
|
||||||
public function __construct(TaskwarriorConfig $config){
|
public function __construct(Config $config){
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function count($uuid){
|
||||||
|
$cmd[] = $this->config->getTaskBin();
|
||||||
|
$cmd[] = sprintf('%s count', $uuid);
|
||||||
|
return $this->executeCommand($cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function modify($task){
|
||||||
|
$cmd[] = $this->config->getTaskBin();
|
||||||
|
|
||||||
|
$uuid = $task->getUuid();
|
||||||
|
$taskJson = $task->convertToArray();
|
||||||
|
|
||||||
|
// Append modify command
|
||||||
|
$cmd[] = sprintf(' %s modify ', $uuid);
|
||||||
|
|
||||||
|
$document = $task->getDescription();
|
||||||
|
|
||||||
|
// Append as first modifier description if set
|
||||||
|
|
||||||
|
if(isset($document)){
|
||||||
|
$cmd[] = $document;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function add(Task $task){
|
// Append on modifiers
|
||||||
$cmd[] = $this->config->getTaskBin();
|
foreach($taskJson as $prop => $value){
|
||||||
$cmd[] = 'add';
|
if(isset($value) && $value != null){
|
||||||
|
$cmd[] = sprintf(' %s: %s ', $prop, $value);
|
||||||
if($task->getDescription() != null){
|
|
||||||
$cmd[] = sprintf('"%s"', (string)$task->getDescription());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if($task->getCategories() != null){
|
|
||||||
$categories = implode(' +', (string)$task->getCategories());
|
|
||||||
$cmd[] = $categories;
|
|
||||||
}
|
|
||||||
|
|
||||||
if($task->getDue() != null){
|
|
||||||
$cmd[] = sprintf("due:%s",$task->getDue('Y-m-dTH:i:s'));
|
|
||||||
}
|
|
||||||
|
|
||||||
if($task->getRecurrence() != null){
|
|
||||||
$rrule = $task->getRecurrence()->getParts();
|
|
||||||
$cmd[] = sprintf('recur:%s', $rrule['FREQ']);
|
|
||||||
if(isset($rrule['UNTIL'])){
|
|
||||||
$cmd[] = sprintf('until:%s', $rrule['UNTIL']);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if($task->getStatus() != null){
|
|
||||||
$cmd[] = sprintf('status:%s', (string)$task->getStatus());
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->executeCommand($cmd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function count($uuid){
|
return $this->executeCommand($cmd);
|
||||||
$cmd[] = $this->config->getTaskBin();
|
|
||||||
$cmd[] = sprintf('%s count', $uuid);
|
}
|
||||||
return $this->executeCommand($cmd);
|
|
||||||
|
public function add(Task $task){
|
||||||
|
$cmd[] = $this->config->getTaskBin();
|
||||||
|
$cmd[] = 'add';
|
||||||
|
|
||||||
|
if($task->getDescription() != null){
|
||||||
|
$cmd[] = sprintf('"%s"', (string)$task->getDescription());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($task->getCategories() != null){
|
||||||
|
$categories = implode(' +', (string)$task->getCategories());
|
||||||
|
$cmd[] = $categories;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($task->getDue() != null){
|
||||||
|
$cmd[] = sprintf("due:%s",$task->getDue('Y-m-dTH:i:s'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if($task->getRecurrence() != null){
|
||||||
|
$rrule = $task->getRecurrence()->getParts();
|
||||||
|
$cmd[] = sprintf('recur:%s', $rrule['FREQ']);
|
||||||
|
if(isset($rrule['UNTIL'])){
|
||||||
|
$cmd[] = sprintf('until:%s', $rrule['UNTIL']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if($task->getStatus() != null){
|
||||||
|
$cmd[] = sprintf('status:%s', (string)$task->getStatus());
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->executeCommand($cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private function executeCommand($command){
|
|
||||||
$rcOptions = $this->config->getOptions();
|
private function executeCommand($command){
|
||||||
|
$rcOptions = $this->config->getOptions();
|
||||||
|
|
||||||
foreach ($rcOptions as $rcOption) {
|
foreach ($rcOptions as $rcOption) {
|
||||||
$command[] = $rcOption;
|
$command[] = $rcOption;
|
||||||
@ -64,17 +96,20 @@ class TodoStrategy implements IStrategy {
|
|||||||
echo $cmdString;
|
echo $cmdString;
|
||||||
$process = new Process($cmdString);
|
$process = new Process($cmdString);
|
||||||
|
|
||||||
$process->run();
|
try {
|
||||||
|
$process->mustRun();
|
||||||
|
// clear cmd queue
|
||||||
|
$this->cmd = [];
|
||||||
|
return $process->getOutput();
|
||||||
|
} catch(ProcessFailedException $error){
|
||||||
|
throw new TaskwarriorCommandException($error->getMesage());
|
||||||
|
return;
|
||||||
|
|
||||||
if(!$process->isSuccessful()){
|
|
||||||
echo $process;
|
|
||||||
throw new TaskwarriorCommandLineException($process);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// clear cmd queue
|
|
||||||
$this->cmd = [];
|
|
||||||
return $process->getOutput();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Aerex\TaskwarriorPlugin\Taskwarrior;
|
namespace Aerex\TaskwarriorPlugin\Taskwarrior;
|
||||||
@ -13,12 +14,15 @@ class Task {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
|
*
|
||||||
|
* @JMS\Type("string")
|
||||||
*/
|
*/
|
||||||
private $uuid;
|
private $uuid;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*
|
*
|
||||||
|
* @JMS\Type("string")
|
||||||
*/
|
*/
|
||||||
private $description;
|
private $description;
|
||||||
|
|
||||||
@ -107,11 +111,12 @@ class Task {
|
|||||||
private $status;
|
private $status;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @var Task[]|ArrayCollection
|
||||||
*
|
*
|
||||||
* @JMS\Type("Depends")
|
|
||||||
*/
|
*/
|
||||||
private $depends;
|
private $depends;
|
||||||
|
|
||||||
|
|
||||||
public function __construct($UUID=null){
|
public function __construct($UUID=null){
|
||||||
$validator = new Uuid();
|
$validator = new Uuid();
|
||||||
|
|
||||||
@ -126,10 +131,50 @@ class Task {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getUuid(){
|
public function getUuid(){
|
||||||
return $this->uuid;
|
return $this->uuid;
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function convertToArray(){
|
||||||
|
$tagsString = null;
|
||||||
|
$dependsString = null;
|
||||||
|
$dueString = null;
|
||||||
|
|
||||||
|
// Process array properties
|
||||||
|
if(isset($this->tags)){
|
||||||
|
$tagsString = implode(',', $this->tags);
|
||||||
|
}
|
||||||
|
if(isset($this->depends)){
|
||||||
|
$dependsString = implode(',', $this->depends);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Process date properties
|
||||||
|
if(isset($this->due)){
|
||||||
|
$dueString = $this->due->format('Y-m-dTH:i:s');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return array(
|
||||||
|
"status" => $this->status,
|
||||||
|
"start" => $this->start,
|
||||||
|
"wait" => $this->wait,
|
||||||
|
"end" => $this->end,
|
||||||
|
"entry" => $this->entry,
|
||||||
|
"priority" => $this->priority,
|
||||||
|
"project" => $this->project,
|
||||||
|
"due" => $this->due,
|
||||||
|
"tags" => $tagsString,
|
||||||
|
"urgency" => $this->urgency,
|
||||||
|
"recu" => $this->recur,
|
||||||
|
"until" => $this->until,
|
||||||
|
"tags" => $this->annotations,
|
||||||
|
"modified" => $this->modified,
|
||||||
|
"depends" => $dependsString
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -140,7 +185,7 @@ public function setDescription(VTodo $component){
|
|||||||
if(!isset($component->DESCRIPTION) && isset($component->SUMMARY)){
|
if(!isset($component->DESCRIPTION) && isset($component->SUMMARY)){
|
||||||
$this->description = $component->SUMMARY;
|
$this->description = $component->SUMMARY;
|
||||||
} else if(!isset($component->DESCRIPTION) && !isset($component->SUMMARY)){
|
} else if(!isset($component->DESCRIPTION) && !isset($component->SUMMARY)){
|
||||||
throw new Exception('Task must have a description or summary');
|
throw new Exception("Task must have a description or summary");
|
||||||
} else {
|
} else {
|
||||||
$this->description = $component->DESCRIPTION;
|
$this->description = $component->DESCRIPTION;
|
||||||
}
|
}
|
||||||
@ -192,7 +237,11 @@ public function setDue(VTodo $document){
|
|||||||
$this->due = new Carbon($document->DUE->getDateTime()->format(\DateTime::W3C));
|
$this->due = new Carbon($document->DUE->getDateTime()->format(\DateTime::W3C));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public function getDue(){
|
public function getDue($format=null){
|
||||||
|
if($format != null){
|
||||||
|
return $this->due->format($format);
|
||||||
|
}
|
||||||
|
|
||||||
return $this->due;
|
return $this->due;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,7 +285,6 @@ public function getRecurrence(){
|
|||||||
return $this->recur;
|
return $this->recur;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setRecurrence(VTodo $document){
|
public function setRecurrence(VTodo $document){
|
||||||
if(isset($document->RRULE)){
|
if(isset($document->RRULE)){
|
||||||
$this->recur = $document->RRULE;
|
$this->recur = $document->RRULE;
|
||||||
@ -252,3 +300,4 @@ public function getStatus(){
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,11 @@ use Aerex\TaskwarriorPlugin\Config;
|
|||||||
class Taskwarrior {
|
class Taskwarrior {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var IStrategy
|
||||||
|
*/
|
||||||
|
private $strategy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var TaskwarriorConfig
|
* @var TaskwarriorConfig
|
||||||
*/
|
*/
|
||||||
@ -23,7 +28,6 @@ class Taskwarrior {
|
|||||||
*/
|
*/
|
||||||
private $taskrc;
|
private $taskrc;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
@ -34,11 +38,6 @@ class Taskwarrior {
|
|||||||
*/
|
*/
|
||||||
private $rcOptions;
|
private $rcOptions;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var IStrategy
|
|
||||||
*/
|
|
||||||
|
|
||||||
private $strategy;
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
@ -49,8 +48,11 @@ class Taskwarrior {
|
|||||||
}
|
}
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
}
|
}
|
||||||
|
public function getConfig(){
|
||||||
|
return $this->config;
|
||||||
|
}
|
||||||
|
|
||||||
public function setStrategy(IStrategy $strategy){
|
public function setStrategy($strategy){
|
||||||
$this->strategy = $strategy;
|
$this->strategy = $strategy;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,12 +67,18 @@ class Taskwarrior {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function count($uuid){
|
public function count($uuid){
|
||||||
return $this->strategy->cound($uuid);
|
return $this->strategy->count($uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function modify($task){
|
||||||
|
return $this->strategy->modify($task);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,28 +4,33 @@ namespace Aerex\TaskwarriorPlugin\Taskwarrior;
|
|||||||
|
|
||||||
use Aerex\TaskwarriorPlugin\Taskwarrior\Taskwarrior;
|
use Aerex\TaskwarriorPlugin\Taskwarrior\Taskwarrior;
|
||||||
use Aerex\TaskwarriorPlugin\Taskwarrior\Task;
|
use Aerex\TaskwarriorPlugin\Taskwarrior\Task;
|
||||||
|
use Aerex\TaskwarriorPlugin\Taskwarrior\Commands\TodoStrategy;
|
||||||
use Sabre\VObject\Component\VTodo;
|
use Sabre\VObject\Component\VTodo;
|
||||||
|
|
||||||
class TaskwarriorManager {
|
class TaskwarriorManager {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var TodoStrategy
|
* @var TodoStrategy
|
||||||
*/
|
*/
|
||||||
private $todoStrategy;
|
private $todoStrategy;
|
||||||
|
|
||||||
|
|
||||||
public function __construct($taskwarrior){
|
public function __construct($taskwarrior){
|
||||||
if(!isset($taskwarrior)){
|
if(!isset($taskwarrior)){
|
||||||
$this->taskwarrior = new Taskwarrior();
|
$this->taskwarrior = new Taskwarrior();
|
||||||
} else {
|
} else {
|
||||||
$this->taskwarrior = $taskwarrior;
|
$this->taskwarrior = $taskwarrior;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize strategies
|
// Initialize strategies
|
||||||
$this->todoStrategy = new TodoStrategy($this->taskwarrior->getConfig());
|
$this->todoStrategy = new TodoStrategy($this->taskwarrior->getConfig());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function addTask(VTodo $document){
|
public function addTask(VTodo $document){
|
||||||
|
|
||||||
$this->taskwarrior->setStrategy($this->todoStrategy);
|
$this->taskwarrior->setStrategy($this->todoStrategy);
|
||||||
|
|
||||||
$task = $this->taskwarrior->createTask((string)$document->UID);
|
$task = $this->taskwarrior->createTask((string)$document->UID);
|
||||||
@ -38,8 +43,6 @@ class TaskwarriorManager {
|
|||||||
|
|
||||||
$task->setCategories($document);
|
$task->setCategories($document);
|
||||||
|
|
||||||
$task->setStatus($document);
|
|
||||||
|
|
||||||
$task->setRecurrence($document);
|
$task->setRecurrence($document);
|
||||||
|
|
||||||
return $this->taskwarrior->add($task);
|
return $this->taskwarrior->add($task);
|
||||||
@ -48,11 +51,11 @@ class TaskwarriorManager {
|
|||||||
|
|
||||||
public function updateTask(VTodo $document){
|
public function updateTask(VTodo $document){
|
||||||
|
|
||||||
$task = $this->taskwarrior->get($document->UID);
|
$task = $this->taskwarrior->createTask((string)$document->UID);
|
||||||
|
|
||||||
$task->setDescription($document);
|
$task->setDescription($document);
|
||||||
|
|
||||||
$task->setEntry($document);
|
$task->setEntryTime($document);
|
||||||
|
|
||||||
$task->setStartTime($document);
|
$task->setStartTime($document);
|
||||||
|
|
||||||
@ -74,11 +77,19 @@ class TaskwarriorManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function taskExists($taskUuid){
|
public function taskExists($taskUuid){
|
||||||
$this->taskwarrior->setStrategy($this->$todoStrategy);
|
|
||||||
return $this->taskwarrior->count((string)$taskUuid);
|
$this->taskwarrior->setStrategy($this->todoStrategy);
|
||||||
|
$exists = $this->taskwarrior->count((string)$taskUuid);
|
||||||
|
echo("exists " . $exists);
|
||||||
|
if($exists === "1"){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user