diff --git a/.travis.yml b/.travis.yml index 8f117f6..84b5e59 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,10 +15,10 @@ env: - PREFER_LOWEST="" before_install: - - wget http://taskwarrior.org/download/task-2.4.2.tar.gz - - gunzip task-2.4.2.tar.gz - - tar xf task-2.4.2.tar - - cd task-2.4.2 + - wget http://taskwarrior.org/download/task-2.4.3.tar.gz + - gunzip task-2.4.3.tar.gz + - tar xf task-2.4.3.tar + - cd task-2.4.3 - sudo apt-get install cmake build-essential uuid-dev libgnutls-dev libreadline6-dev --force-yes - sudo cmake -DCMAKE_BUILD_TYPE=release . - sudo make diff --git a/src/TaskManager.php b/src/TaskManager.php index a8a92a7..abb8c25 100644 --- a/src/TaskManager.php +++ b/src/TaskManager.php @@ -90,15 +90,11 @@ class TaskManager } /** - * @param string|array $filter + * @param string $filter * @return Task[]|ArrayCollection */ public function filterAll($filter = null) { - if (is_string($filter)) { - $filter = explode(' ', $filter); - } - $result = $this->export($filter); foreach ($result as $key => $task) { diff --git a/src/Taskwarrior.php b/src/Taskwarrior.php index 3ae4e14..ad72506 100644 --- a/src/Taskwarrior.php +++ b/src/Taskwarrior.php @@ -5,7 +5,7 @@ namespace DavidBadura\Taskwarrior; use DavidBadura\Taskwarrior\Exception\CommandException; use DavidBadura\Taskwarrior\Exception\TaskwarriorException; use Symfony\Component\Filesystem\Filesystem; -use Symfony\Component\Process\ProcessBuilder; +use Symfony\Component\Process\Process; /** * @author David Badura @@ -71,7 +71,7 @@ class Taskwarrior /** * @param array $params - * @param string|array $filter + * @param string $filter */ public function modify(array $params, $filter = null) { @@ -79,7 +79,7 @@ class Taskwarrior } /** - * @param null $filter + * @param string $filter * @return array */ public function projects($filter = null) @@ -90,7 +90,7 @@ class Taskwarrior } /** - * @param null $filter + * @param string $filter * @return array */ public function tags($filter = null) @@ -129,7 +129,7 @@ class Taskwarrior } /** - * @param string|array $filter + * @param string $filter * @return string */ public function export($filter = null) @@ -139,43 +139,34 @@ class Taskwarrior /** * @param string $command - * @param string|array $filter + * @param string $filter * @param array $options * @return string * @throws TaskwarriorException */ public function command($command, $filter = null, array $options = array()) { - $builder = $this->createProcessBuilder(); + $parts = ['task']; - if (!is_array($filter)) { - $filter = explode(' ', $filter); + foreach ($this->rcOptions as $option) { + $parts[] = $option; } - foreach ($filter as $param) { - if (empty($param)) { - continue; + if ($filter) { + if (strpos($filter, '(') !== false) { + $parts[] = "'" . $filter . "'"; + } else { + $parts[] = $filter; } - - $builder->add($param); } - $builder->add($command); + $parts[] = $command; foreach ($options as $param) { - $builder->add($param); + $parts[] = $param; } - /* - * 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 = new Process(implode(' ', $parts)); $process->run(); if (!$process->isSuccessful()) { @@ -261,23 +252,6 @@ class Taskwarrior 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 * @return array diff --git a/tests/TaskManagerTest.php b/tests/TaskManagerTest.php index a95bcb8..b354b9c 100644 --- a/tests/TaskManagerTest.php +++ b/tests/TaskManagerTest.php @@ -711,6 +711,15 @@ class TaskManagerTest extends \PHPUnit_Framework_TestCase $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 * @return \DateTime diff --git a/tests/TaskwarriorTest.php b/tests/TaskwarriorTest.php index d61bb99..0286492 100644 --- a/tests/TaskwarriorTest.php +++ b/tests/TaskwarriorTest.php @@ -29,7 +29,6 @@ class TaskwarriorTest extends \PHPUnit_Framework_TestCase $fs->remove(__DIR__ . '/.task'); } - public function testConfig() { $config = $this->taskwarrior->config();