From cd92bf9a1882a22522b7a39bbb4287f152271cf5 Mon Sep 17 00:00:00 2001 From: Guillaume Leclerc Date: Thu, 13 Apr 2017 11:07:44 +0800 Subject: [PATCH] Fix issue with wrong harvest ID being deleted after UNDO The issue was that when we started a new timer just for toggl, the harvest ID (other services) were not initialized back to null, while they should. Those IDs in the workflow configuration file are just to handle the UNDO functionality and should reflect the status of the last ran timer through the workflow. If only one service is started, all the other ones IDs have to be back to null. --- commands/AlfredTime.class.php | 17 +++++- ...1s iMac's conflicted copy 2017-04-13).php" | 53 +++++++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 "commands/time (Guillaume\342\200\231s iMac's conflicted copy 2017-04-13).php" diff --git a/commands/AlfredTime.class.php b/commands/AlfredTime.class.php index db1cb5da..310fdf59 100644 --- a/commands/AlfredTime.class.php +++ b/commands/AlfredTime.class.php @@ -36,8 +36,23 @@ public function startTimer($description = '', $projectsDefault = null, $tagsDefa { $startType = $startDefault === true ? 'start_default' : 'start'; $atLeastOneServiceStarted = false; + $implementedServices = $this->implementedServicesForFeature($startType); - foreach ($this->implementedServicesForFeature($startType) as $service) { + /** + * When starting a new timer, all the services timer IDs have to be put to null + * so that when the user uses the UNDO feature, it doesn't delete old previous + * other services timers. The timer IDs are used for the UNDO feature and + * should then contain the IDs of the last starts through the workflow, not + * through each individual service + */ + if (empty($implementedServices) === false) { + foreach ($this->activatedServices() as $service) { + $this->config['workflow']['timer_' . $service . '_id'] = null; + $this->saveConfiguration(); + } + } + + foreach ($implementedServices as $service) { $defaultProjectId = isset($projectsDefault[$service]) ? $projectsDefault[$service] : null; $defaultTags = isset($tagsDefault[$service]) ? $tagsDefault[$service] : null; diff --git "a/commands/time (Guillaume\342\200\231s iMac's conflicted copy 2017-04-13).php" "b/commands/time (Guillaume\342\200\231s iMac's conflicted copy 2017-04-13).php" new file mode 100644 index 00000000..d35ae5a1 --- /dev/null +++ "b/commands/time (Guillaume\342\200\231s iMac's conflicted copy 2017-04-13).php" @@ -0,0 +1,53 @@ +generateDefaultConfigurationFile(); + exec('open "' . getenv('alfred_workflow_data') . '/config.json"'); +} elseif (substr($query, 0, 4) === 'sync') { + $message = $alfredTime->syncOnlineDataToLocalCache(); +} elseif (substr($query, 0, 5) === 'edit') { + exec('open "' . getenv('alfred_workflow_data') . '/config.json"'); +} elseif (substr($query, 0, 4) === 'undo') { + $message = $alfredTime->UndoTimer(); +} elseif (substr($query, 0, 6) === 'delete') { + /** + * For now, only handle Toggl + */ + $timerData = json_decode(getenv('timer_data'), true); + $message = $alfredTime->deleteTimer($timerData['id']); +} elseif (substr($query, 0, 8) === 'continue') { + $timerData = json_decode(getenv('timer_data'), true); + $project = ['toggl' => $timerData['pid']]; + $tags = empty($timerData['tags']) === true ? [] : $timerData['tags']; + $tag = ['toggl' => implode(', ', $tags)]; + $message = $alfredTime->startTimer($timerData['description'], $project, $tag); +} elseif (substr($query, 0, 6) === 'start ') { + $description = substr($query, 6); + + /** + * For now, only handle Toggl projects and tags + */ + $project = [ + 'toggl' => getenv('project_id'), + ]; + + $tag = [ + 'toggl' => getenv('tag_name') + ]; + + $message = $alfredTime->startTimer($description, $project, $tag); +} elseif (substr($query, 0, 14) === 'start_default ') { + $description = substr($query, 14); + $message = $alfredTime->startTimerWithDefaultOptions($description); +} elseif (substr($query, 0, 4) === 'stop') { + $message = $alfredTime->stopRunningTimer(); +} + +echo $message;