Skip to content

Commit b6bbcd7

Browse files
committed
Fixed bug in toggl data importer if import contains invalid timezone
1 parent 0d4ffa1 commit b6bbcd7

File tree

12 files changed

+219
-1
lines changed

12 files changed

+219
-1
lines changed

app/Service/Import/Importers/TogglDataImporter.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
namespace App\Service\Import\Importers;
66

77
use App\Enums\Role;
8+
use App\Service\TimezoneService;
89
use Exception;
910
use Illuminate\Support\Carbon;
11+
use Illuminate\Support\Facades\Log;
12+
use Illuminate\Support\Str;
1013
use Override;
1114
use Spatie\TemporaryDirectory\TemporaryDirectory;
1215
use ValueError;
@@ -93,11 +96,22 @@ public function importData(string $data, string $timezone): void
9396
}
9497

9598
foreach ($workspaceUsers as $workspaceUser) {
99+
$timezone = Str::trim($workspaceUser->timezone);
100+
if ($timezone === '') {
101+
$timezone = 'UTC';
102+
}
103+
if (! app(TimezoneService::class)->isValid($timezone)) {
104+
Log::warning('TogglDateImporter: Invalid timezone', [
105+
'timezone' => $timezone,
106+
]);
107+
$timezone = 'UTC';
108+
}
109+
96110
$userId = $this->userImportHelper->getKey([
97111
'email' => $workspaceUser->email,
98112
], [
99113
'name' => $workspaceUser->name,
100-
'timezone' => $workspaceUser->timezone ?? 'UTC',
114+
'timezone' => $timezone,
101115
'is_placeholder' => true,
102116
], (string) $workspaceUser->uid);
103117
$this->memberImportHelper->getKey([
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[
2+
{
3+
"archived": false,
4+
"creator_id": 201,
5+
"id": 301,
6+
"name": "Big Company",
7+
"wid": 0
8+
},
9+
{
10+
"archived": true,
11+
"creator_id": 201,
12+
"id": 302,
13+
"name": "Other Company (Archived)",
14+
"wid": 0
15+
}
16+
]
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
[
2+
{
3+
"active": true,
4+
"actual_hours": null,
5+
"actual_seconds": null,
6+
"auto_estimates": false,
7+
"billable": false,
8+
"cid": null,
9+
"client_id": null,
10+
"color": "#ef5350",
11+
"currency": "EUR",
12+
"estimated_hours": null,
13+
"estimated_seconds": null,
14+
"fixed_fee": null,
15+
"guid": "",
16+
"id": 401,
17+
"is_private": true,
18+
"name": "Project without Client",
19+
"rate": null,
20+
"rate_last_updated": null,
21+
"recurring": false,
22+
"recurring_parameters": null,
23+
"start_date": "2020-01-01",
24+
"status": "active",
25+
"template": false,
26+
"template_id": null,
27+
"wid": 0,
28+
"workspace_id": 0
29+
},
30+
{
31+
"active": true,
32+
"actual_hours": null,
33+
"actual_seconds": null,
34+
"auto_estimates": false,
35+
"billable": true,
36+
"cid": 301,
37+
"client_id": 301,
38+
"color": "#ec407a",
39+
"currency": null,
40+
"estimated_hours": null,
41+
"estimated_seconds": null,
42+
"fixed_fee": null,
43+
"guid": "",
44+
"id": 402,
45+
"is_private": true,
46+
"name": "Project for Big Company",
47+
"rate": 100.01,
48+
"rate_last_updated": null,
49+
"recurring": false,
50+
"recurring_parameters": null,
51+
"start_date": "2020-01-01",
52+
"status": "active",
53+
"template": false,
54+
"template_id": null,
55+
"wid": 0,
56+
"workspace_id": 0
57+
},
58+
{
59+
"active": false,
60+
"actual_hours": null,
61+
"actual_seconds": null,
62+
"auto_estimates": false,
63+
"billable": true,
64+
"cid": 302,
65+
"client_id": 302,
66+
"color": "#6a407f",
67+
"currency": null,
68+
"estimated_hours": null,
69+
"estimated_seconds": null,
70+
"fixed_fee": null,
71+
"guid": "",
72+
"id": 403,
73+
"is_private": false,
74+
"name": "Project (Archived)",
75+
"rate": null,
76+
"rate_last_updated": null,
77+
"recurring": false,
78+
"recurring_parameters": null,
79+
"start_date": "2020-01-01",
80+
"status": "active",
81+
"template": false,
82+
"template_id": null,
83+
"wid": 0,
84+
"workspace_id": 0
85+
}
86+
]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[
2+
{
3+
"gid": null,
4+
"group_id": null,
5+
"id": 801,
6+
"labour_cost": null,
7+
"manager": true,
8+
"project_id": 402,
9+
"rate": 100.02,
10+
"rate_last_updated": null,
11+
"user_id": 2001,
12+
"workspace_id": 0
13+
}
14+
]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[
2+
{
3+
"creator_id": 0,
4+
"id": 501,
5+
"name": "Development",
6+
"workspace_id": 0
7+
},
8+
{
9+
"creator_id": 0,
10+
"id": 502,
11+
"name": "Backend",
12+
"workspace_id": 0
13+
}
14+
]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[
2+
{
3+
"active": true,
4+
"estimated_seconds": 0,
5+
"id": 601,
6+
"name": "Task 1",
7+
"project_id": 402,
8+
"recurring": false,
9+
"tracked_seconds": 0,
10+
"user_id": null,
11+
"workspace_id": 0
12+
},
13+
{
14+
"active": false,
15+
"estimated_seconds": 0,
16+
"id": 602,
17+
"name": "Task 2",
18+
"project_id": 403,
19+
"recurring": false,
20+
"tracked_seconds": 0,
21+
"user_id": null,
22+
"workspace_id": 0
23+
}
24+
]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]

0 commit comments

Comments
 (0)