diff --git a/lib/Console.php b/lib/Console.php index 435e4e0..6f69467 100644 --- a/lib/Console.php +++ b/lib/Console.php @@ -23,7 +23,7 @@ class Console extends AbstractConsole { $stdin = array_merge($stdin, $this->defaultArgs, $args); if (isset($input)) { - $stdin[] = $this->convertToString($input); + $input = $this->convertToString($input); } $process = new Process(implode(' ', $stdin), $input, $envs); $process->inheritEnvironmentVariables(); @@ -32,7 +32,6 @@ class Console extends AbstractConsole { $process->mustRun(); return $process->getOutput(); } catch (ProcessFailedException $error) { - echo $error->getMessage(); throw $error; } } diff --git a/lib/Storages/Taskwarrior.php b/lib/Storages/Taskwarrior.php index d5a9742..9b1c8d6 100644 --- a/lib/Storages/Taskwarrior.php +++ b/lib/Storages/Taskwarrior.php @@ -26,6 +26,13 @@ class Taskwarrior implements IStorage { public function refresh() { $output = $this->console->execute('task', ['sync'], null, ['TASKRC' => $this->configs['taskrc'],'TASKDATA' => $this->configs['taskdata']]); + $tasks = json_decode($this->console->execute('task', ['export'], null, + ['TASKRC' => $this->configs['taskrc'], 'TASKDATA' => $this->configs['taskdata']]), true); + foreach ($tasks as $task) { + if (isset($task['uid'])) { + $this->tasks[$task['uid']] = $task; + } + } $this->logger->info($output); } @@ -37,7 +44,7 @@ class Taskwarrior implements IStorage { $task['uid'] = (string)$vtodo->UID; } - if (isset($vtodo->SUMMARY) && !isset($vtodo->DESCRIPTION)){ + if (isset($vtodo->SUMMARY)){ $task['description'] = (string)$vtodo->SUMMARY; } else if(isset($vtodo->DESCRIPTION)) { $task['description'] = (string)$vtodo->DESCRIPTION; @@ -108,8 +115,8 @@ class Taskwarrior implements IStorage { $task['tags'] = []; foreach ($vtodo->CATEGORIES as $category) { if (isset($this->configs['project_tag_suffix'])) { - $projTagSuffixRegExp = sprintf('/^%s_/', $this->configs['project_tag_suffix']); - if (preg_match($category, $projTagSuffixRegExp)) { + $projTagSuffixRegExp = sprintf('/^%s/', $this->configs['project_tag_suffix']); + if (preg_match($projTagSuffixRegExp, $category)) { $task['project'] = preg_replace($projTagSuffixRegExp, '', $category); continue; } @@ -122,19 +129,23 @@ class Taskwarrior implements IStorage { } public function save(Calendar $c) { - if (!isset($c->VTODO)){ - throw new \Exception('Calendar event does not contain VTODO'); - $this->logger->error('Calendar event does not contain VTODO'); + try { + if (!isset($c->VTODO)){ + throw new \Exception('Calendar event does not contain VTODO'); + } + $this->logger->info(json_encode($c->jsonSerialize())); + $this->refresh(); + $task = $this->vObjectToTask($c->VTODO); + $this->logger->info(json_encode($task)); + $this->logger->info( + sprintf('Executing TASKRC = %s TASKDATA = %s task import %s', $this->configs['taskrc'], $this->configs['taskdata'], json_encode($task)) + ); + $output = $this->console->execute('task', ['import'], $task, + ['TASKRC' => $this->configs['taskrc'],'TASKDATA' => $this->configs['taskdata']]); + $this->logger->info($output); + } catch (\Exception $e) { + $this->logger->error($e->getTraceAsString()); + throw $e; } - $this->logger->info($c->VTODO->getJsonValue()); - $this->refresh(); - $task = $this->vObjectToTask($c->VTODO); - $this->logger->info(json_encode($task)); - $this->logger->info( - sprintf('Executing TASKRC = %s TASKDATA = %s task import %s', $this->configs['taskrc'], $this->configs['taskdata'], $task) - ); - $output = $this->console->execute('task', ['import'], $task, - ['TASKRC' => $this->configs['taskrc'],'TASKDATA' => $this->configs['taskdata']]); - $this->logger->info($output); } }