fix complex filter

This commit is contained in:
DavidBadura 2015-04-22 14:33:35 +00:00
parent 8385e7e7c5
commit 682561a58e
5 changed files with 31 additions and 53 deletions

View File

@ -15,10 +15,10 @@ env:
- PREFER_LOWEST="" - PREFER_LOWEST=""
before_install: before_install:
- wget http://taskwarrior.org/download/task-2.4.2.tar.gz - wget http://taskwarrior.org/download/task-2.4.3.tar.gz
- gunzip task-2.4.2.tar.gz - gunzip task-2.4.3.tar.gz
- tar xf task-2.4.2.tar - tar xf task-2.4.3.tar
- cd task-2.4.2 - cd task-2.4.3
- sudo apt-get install cmake build-essential uuid-dev libgnutls-dev libreadline6-dev --force-yes - sudo apt-get install cmake build-essential uuid-dev libgnutls-dev libreadline6-dev --force-yes
- sudo cmake -DCMAKE_BUILD_TYPE=release . - sudo cmake -DCMAKE_BUILD_TYPE=release .
- sudo make - sudo make

View File

@ -90,15 +90,11 @@ class TaskManager
} }
/** /**
* @param string|array $filter * @param string $filter
* @return Task[]|ArrayCollection * @return Task[]|ArrayCollection
*/ */
public function filterAll($filter = null) public function filterAll($filter = null)
{ {
if (is_string($filter)) {
$filter = explode(' ', $filter);
}
$result = $this->export($filter); $result = $this->export($filter);
foreach ($result as $key => $task) { foreach ($result as $key => $task) {

View File

@ -5,7 +5,7 @@ namespace DavidBadura\Taskwarrior;
use DavidBadura\Taskwarrior\Exception\CommandException; use DavidBadura\Taskwarrior\Exception\CommandException;
use DavidBadura\Taskwarrior\Exception\TaskwarriorException; use DavidBadura\Taskwarrior\Exception\TaskwarriorException;
use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Process\ProcessBuilder; use Symfony\Component\Process\Process;
/** /**
* @author David Badura <d.a.badura@gmail.com> * @author David Badura <d.a.badura@gmail.com>
@ -71,7 +71,7 @@ class Taskwarrior
/** /**
* @param array $params * @param array $params
* @param string|array $filter * @param string $filter
*/ */
public function modify(array $params, $filter = null) public function modify(array $params, $filter = null)
{ {
@ -79,7 +79,7 @@ class Taskwarrior
} }
/** /**
* @param null $filter * @param string $filter
* @return array * @return array
*/ */
public function projects($filter = null) public function projects($filter = null)
@ -90,7 +90,7 @@ class Taskwarrior
} }
/** /**
* @param null $filter * @param string $filter
* @return array * @return array
*/ */
public function tags($filter = null) public function tags($filter = null)
@ -129,7 +129,7 @@ class Taskwarrior
} }
/** /**
* @param string|array $filter * @param string $filter
* @return string * @return string
*/ */
public function export($filter = null) public function export($filter = null)
@ -139,43 +139,34 @@ class Taskwarrior
/** /**
* @param string $command * @param string $command
* @param string|array $filter * @param string $filter
* @param array $options * @param array $options
* @return string * @return string
* @throws TaskwarriorException * @throws TaskwarriorException
*/ */
public function command($command, $filter = null, array $options = array()) public function command($command, $filter = null, array $options = array())
{ {
$builder = $this->createProcessBuilder(); $parts = ['task'];
if (!is_array($filter)) { foreach ($this->rcOptions as $option) {
$filter = explode(' ', $filter); $parts[] = $option;
} }
foreach ($filter as $param) { if ($filter) {
if (empty($param)) { if (strpos($filter, '(') !== false) {
continue; $parts[] = "'" . $filter . "'";
} else {
$parts[] = $filter;
} }
$builder->add($param);
} }
$builder->add($command); $parts[] = $command;
foreach ($options as $param) { foreach ($options as $param) {
$builder->add($param); $parts[] = $param;
} }
/* $process = new Process(implode(' ', $parts));
* Local hack to allow utf8 chars
*/
$oldLocal = setlocale(LC_CTYPE, 0);
setlocale(LC_CTYPE, 'UTF8', 'en_US.UTF-8');
$process = $builder->getProcess();
setlocale(LC_CTYPE, $oldLocal);
$process->run(); $process->run();
if (!$process->isSuccessful()) { if (!$process->isSuccessful()) {
@ -261,23 +252,6 @@ class Taskwarrior
return $options; return $options;
} }
/**
* @return ProcessBuilder
*/
private function createProcessBuilder()
{
$builder = new ProcessBuilder();
foreach ($this->rcOptions as $option) {
$builder->add($option);
}
$builder->setPrefix('task');
$builder->setTimeout(360);
return $builder;
}
/** /**
* @param string $string * @param string $string
* @return array * @return array

View File

@ -711,6 +711,15 @@ class TaskManagerTest extends \PHPUnit_Framework_TestCase
$this->assertNull($task->getEnd()); $this->assertNull($task->getEnd());
} }
public function testComplexFilter()
{
$task1 = new Task();
$task1->setDescription('foo1');
$this->taskManager->save($task1);
$this->assertCount(1, $this->taskManager->filterAll('(status:pending or status:waiting)'));
}
/** /**
* @param string $string * @param string $string
* @return \DateTime * @return \DateTime

View File

@ -29,7 +29,6 @@ class TaskwarriorTest extends \PHPUnit_Framework_TestCase
$fs->remove(__DIR__ . '/.task'); $fs->remove(__DIR__ . '/.task');
} }
public function testConfig() public function testConfig()
{ {
$config = $this->taskwarrior->config(); $config = $this->taskwarrior->config();