Skip to content
This repository has been archived by the owner on Jun 27, 2022. It is now read-only.

Commit

Permalink
add reopen feature
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidBadura committed Feb 10, 2015
1 parent 37374f4 commit 4a36d7e
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/TaskManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,26 @@ public function done(Task $task)
$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
*/
Expand Down Expand Up @@ -212,7 +232,12 @@ private function merge(Task $old, Task $new)
$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());
}
}

/**
Expand Down
4 changes: 4 additions & 0 deletions src/Taskwarrior.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ private function getOptions($params)
}
}

if (array_key_exists('status', $params)) {
$options[] = 'status:' . $params['status'];
}

if (array_key_exists('description', $params)) {
$options[] = $params['description'];
}
Expand Down
26 changes: 26 additions & 0 deletions tests/TaskManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,32 @@ public function testUntilModify()
$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
Expand Down

0 comments on commit 4a36d7e

Please sign in to comment.