From 4a36d7e5114a2809e831ed8c9dd971b374cdc142 Mon Sep 17 00:00:00 2001 From: DavidBadura Date: Tue, 10 Feb 2015 20:49:30 +0000 Subject: [PATCH] add reopen feature --- src/TaskManager.php | 27 ++++++++++++++++++++++++++- src/Taskwarrior.php | 4 ++++ tests/TaskManagerTest.php | 26 ++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/src/TaskManager.php b/src/TaskManager.php index f947b14..0e6f90b 100644 --- a/src/TaskManager.php +++ b/src/TaskManager.php @@ -141,6 +141,26 @@ class TaskManager $this->refresh($task); } + /** + * @param Task $task + */ + public function reopen(Task $task) + { + if (!$task->getUuid()) { + return; + } + + if ($task->isPending() || $task->isWaiting() || $task->isReccuring()) { + return; + } + + $this->taskwarrior->modify([ + 'status' => Task::STATUS_PENDING + ], $task->getUuid()); + + $this->refresh($task); + } + /** * @param Task $task */ @@ -212,7 +232,12 @@ class TaskManager $this->setValue($old, 'urgency', $new->getUrgency()); $this->setValue($old, 'status', $new->getStatus()); $this->setValue($old, 'modified', $new->getModified()); - $this->setValue($old, 'end', $new->getEnd()); + + if ($new->isPending()) { // fix reopen problem + $this->setValue($old, 'end', null); + } else { + $this->setValue($old, 'end', $new->getEnd()); + } } /** diff --git a/src/Taskwarrior.php b/src/Taskwarrior.php index ec18413..726b425 100644 --- a/src/Taskwarrior.php +++ b/src/Taskwarrior.php @@ -225,6 +225,10 @@ class Taskwarrior } } + if (array_key_exists('status', $params)) { + $options[] = 'status:' . $params['status']; + } + if (array_key_exists('description', $params)) { $options[] = $params['description']; } diff --git a/tests/TaskManagerTest.php b/tests/TaskManagerTest.php index 1d4954a..98dcd3c 100644 --- a/tests/TaskManagerTest.php +++ b/tests/TaskManagerTest.php @@ -592,6 +592,32 @@ class TaskManagerTest extends \PHPUnit_Framework_TestCase $this->assertEquals($date2, $task1->getUntil()); } + public function testReopen() + { + $task = new Task(); + $task->setDescription('foo'); + + $this->taskManager->save($task); + $this->assertTrue($task->isPending()); + $this->assertNull($task->getEnd()); + + $this->taskManager->done($task); + $this->assertTrue($task->isCompleted()); + $this->assertInstanceOf('Carbon\Carbon', $task->getEnd()); + + $this->taskManager->reopen($task); + $this->assertTrue($task->isPending()); + $this->assertNull($task->getEnd()); + + $this->taskManager->delete($task); + $this->assertTrue($task->isDeleted()); + $this->assertInstanceOf('Carbon\Carbon', $task->getEnd()); + + $this->taskManager->reopen($task); + $this->assertTrue($task->isPending()); + $this->assertNull($task->getEnd()); + } + /** * @param string $string * @return \DateTime