Skip to content
This repository has been archived by the owner on Jun 5, 2024. It is now read-only.

Commit

Permalink
Fix issue with wrong harvest ID being deleted after UNDO
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
godbout committed Apr 13, 2017
1 parent b7c17d9 commit cd92bf9
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
17 changes: 16 additions & 1 deletion commands/AlfredTime.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

require 'AlfredTime.class.php';

$alfredTime = new AlfredTime;

$query = getenv('description');
$message = '';

if (substr($query, 0, 6) === 'config') {
$alfredTime->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;

0 comments on commit cd92bf9

Please sign in to comment.