From 135578861714ca889c83b1ff9baab8b2311a5940 Mon Sep 17 00:00:00 2001 From: Guillaume Leclerc Date: Mon, 7 Jan 2019 22:51:15 +0800 Subject: [PATCH] Fix #21. Add ability to start with wrong credentials and not crash the workflow --- src/Harvest.php | 14 ++++++++++++-- src/Toggl.php | 10 +++++++++- src/WorkflowHandler.php | 8 ++++---- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/Harvest.php b/src/Harvest.php index b9c83951..175fb3de 100644 --- a/src/Harvest.php +++ b/src/Harvest.php @@ -73,8 +73,18 @@ public function generateTimer($description, $projectId, $taskId) public function getOnlineData() { $data = []; - $data['projects'] = $this->timerAction('get_projects', 'projects'); - $data['tasks'] = $this->timerAction('get_tags', 'tasks'); + + $projects = $this->timerAction('get_projects', 'projects'); + + if ($projects !== false) { + $data['projects'] = $projects; + } + + $tasks = $this->timerAction('get_tags', 'tasks'); + + if ($tasks !== false) { + $data['tasks'] = $tasks; + } return $data; } diff --git a/src/Toggl.php b/src/Toggl.php index af5bc587..26e9ff0b 100644 --- a/src/Toggl.php +++ b/src/Toggl.php @@ -76,7 +76,15 @@ public function generateTimer($description, $projectId, $tagData) */ public function getOnlineData() { - return $this->timerAction('get_online_data', 'me?with_related_data=true'); + $data = []; + + $togglData = $this->timerAction('get_online_data', 'me?with_related_data=true'); + + if ($togglData !== false) { + $data = $togglData; + } + + return $data; } /** diff --git a/src/WorkflowHandler.php b/src/WorkflowHandler.php index d6e5b06e..8638be2a 100644 --- a/src/WorkflowHandler.php +++ b/src/WorkflowHandler.php @@ -188,12 +188,12 @@ private function syncServiceOnlineDataToLocalCache($service) { $data = $this->$service->getOnlineData(); + $this->saveServiceDataCache($service, $data); + if (empty($data) === true) { - return $this->getNotificationForService($service, 'data', false); + return $this->getNotificationForService($service, 'cache', false); } - $this->saveServiceDataCache($service, $data); - - return $this->getNotificationForService($service, 'data', true); + return $this->getNotificationForService($service, 'cached', true); } }