fix(tw): Reloaded tasks into object array for refresh

- chore(tw): Wrapped import function in try catch and logged error
This commit is contained in:
Aerex 2020-06-02 21:16:18 -05:00
parent 2f87752f6e
commit 00d0ea624f
2 changed files with 28 additions and 18 deletions

View File

@ -23,7 +23,7 @@ class Console extends AbstractConsole {
$stdin = array_merge($stdin, $this->defaultArgs, $args); $stdin = array_merge($stdin, $this->defaultArgs, $args);
if (isset($input)) { if (isset($input)) {
$stdin[] = $this->convertToString($input); $input = $this->convertToString($input);
} }
$process = new Process(implode(' ', $stdin), $input, $envs); $process = new Process(implode(' ', $stdin), $input, $envs);
$process->inheritEnvironmentVariables(); $process->inheritEnvironmentVariables();
@ -32,7 +32,6 @@ class Console extends AbstractConsole {
$process->mustRun(); $process->mustRun();
return $process->getOutput(); return $process->getOutput();
} catch (ProcessFailedException $error) { } catch (ProcessFailedException $error) {
echo $error->getMessage();
throw $error; throw $error;
} }
} }

View File

@ -26,6 +26,13 @@ class Taskwarrior implements IStorage {
public function refresh() { public function refresh() {
$output = $this->console->execute('task', ['sync'], null, $output = $this->console->execute('task', ['sync'], null,
['TASKRC' => $this->configs['taskrc'],'TASKDATA' => $this->configs['taskdata']]); ['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); $this->logger->info($output);
} }
@ -37,7 +44,7 @@ class Taskwarrior implements IStorage {
$task['uid'] = (string)$vtodo->UID; $task['uid'] = (string)$vtodo->UID;
} }
if (isset($vtodo->SUMMARY) && !isset($vtodo->DESCRIPTION)){ if (isset($vtodo->SUMMARY)){
$task['description'] = (string)$vtodo->SUMMARY; $task['description'] = (string)$vtodo->SUMMARY;
} else if(isset($vtodo->DESCRIPTION)) { } else if(isset($vtodo->DESCRIPTION)) {
$task['description'] = (string)$vtodo->DESCRIPTION; $task['description'] = (string)$vtodo->DESCRIPTION;
@ -108,8 +115,8 @@ class Taskwarrior implements IStorage {
$task['tags'] = []; $task['tags'] = [];
foreach ($vtodo->CATEGORIES as $category) { foreach ($vtodo->CATEGORIES as $category) {
if (isset($this->configs['project_tag_suffix'])) { if (isset($this->configs['project_tag_suffix'])) {
$projTagSuffixRegExp = sprintf('/^%s_/', $this->configs['project_tag_suffix']); $projTagSuffixRegExp = sprintf('/^%s/', $this->configs['project_tag_suffix']);
if (preg_match($category, $projTagSuffixRegExp)) { if (preg_match($projTagSuffixRegExp, $category)) {
$task['project'] = preg_replace($projTagSuffixRegExp, '', $category); $task['project'] = preg_replace($projTagSuffixRegExp, '', $category);
continue; continue;
} }
@ -122,19 +129,23 @@ class Taskwarrior implements IStorage {
} }
public function save(Calendar $c) { public function save(Calendar $c) {
try {
if (!isset($c->VTODO)){ if (!isset($c->VTODO)){
throw new \Exception('Calendar event does not contain VTODO'); throw new \Exception('Calendar event does not contain VTODO');
$this->logger->error('Calendar event does not contain VTODO');
} }
$this->logger->info($c->VTODO->getJsonValue()); $this->logger->info(json_encode($c->jsonSerialize()));
$this->refresh(); $this->refresh();
$task = $this->vObjectToTask($c->VTODO); $task = $this->vObjectToTask($c->VTODO);
$this->logger->info(json_encode($task)); $this->logger->info(json_encode($task));
$this->logger->info( $this->logger->info(
sprintf('Executing TASKRC = %s TASKDATA = %s task import %s', $this->configs['taskrc'], $this->configs['taskdata'], $task) 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, $output = $this->console->execute('task', ['import'], $task,
['TASKRC' => $this->configs['taskrc'],'TASKDATA' => $this->configs['taskdata']]); ['TASKRC' => $this->configs['taskrc'],'TASKDATA' => $this->configs['taskdata']]);
$this->logger->info($output); $this->logger->info($output);
} catch (\Exception $e) {
$this->logger->error($e->getTraceAsString());
throw $e;
}
} }
} }