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=""
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

View File

@ -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) {

View File

@ -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 <d.a.badura@gmail.com>
@ -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

View File

@ -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

View File

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