mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-17 04:32:15 +01:00
Enhanced imports with billable rates and project members; Fixed error handling and import structure
This commit is contained in:
committed by
Constantin Graf
parent
7433648077
commit
a8ce994f08
@@ -28,24 +28,36 @@ class TogglDataImporter extends DefaultImporter
|
||||
$temporaryDirectory = TemporaryDirectory::make();
|
||||
$zip->extractTo($temporaryDirectory->path());
|
||||
$zip->close();
|
||||
if (! file_exists($temporaryDirectory->path('clients.json'))) {
|
||||
throw new ImportException('File "clients.json" missing in ZIP');
|
||||
}
|
||||
$clientsFileContent = file_get_contents($temporaryDirectory->path('clients.json'));
|
||||
if ($clientsFileContent === false) {
|
||||
throw new ImportException('File clients.json missing in ZIP');
|
||||
throw new ImportException('File "clients.json" can not be opened');
|
||||
}
|
||||
$clients = json_decode($clientsFileContent);
|
||||
if (! file_exists($temporaryDirectory->path('projects.json'))) {
|
||||
throw new ImportException('File "projects.json" missing in ZIP');
|
||||
}
|
||||
$projectsFileContent = file_get_contents($temporaryDirectory->path('projects.json'));
|
||||
if ($projectsFileContent === false) {
|
||||
throw new ImportException('File projects.json missing in ZIP');
|
||||
throw new ImportException('File "projects.json" can not be opened');
|
||||
}
|
||||
$projects = json_decode($projectsFileContent);
|
||||
if (! file_exists($temporaryDirectory->path('tags.json'))) {
|
||||
throw new ImportException('File "tags.json" missing in ZIP');
|
||||
}
|
||||
$tagsFileContent = file_get_contents($temporaryDirectory->path('tags.json'));
|
||||
if ($tagsFileContent === false) {
|
||||
throw new ImportException('File tags.json missing in ZIP');
|
||||
throw new ImportException('File "tags.json" can not be opened');
|
||||
}
|
||||
$tags = json_decode($tagsFileContent);
|
||||
if (! file_exists($temporaryDirectory->path('workspace_users.json'))) {
|
||||
throw new ImportException('File "workspace_users.json" missing in ZIP');
|
||||
}
|
||||
$workspaceUsersFileContent = file_get_contents($temporaryDirectory->path('workspace_users.json'));
|
||||
if ($workspaceUsersFileContent === false) {
|
||||
throw new ImportException('File workspace_users.json missing in ZIP');
|
||||
throw new ImportException('File "workspace_users.json" can not be opened');
|
||||
}
|
||||
$workspaceUsers = json_decode($workspaceUsersFileContent);
|
||||
foreach ($clients as $client) {
|
||||
@@ -61,6 +73,16 @@ class TogglDataImporter extends DefaultImporter
|
||||
], [], (string) $tag->id);
|
||||
}
|
||||
|
||||
foreach ($workspaceUsers as $workspaceUser) {
|
||||
$this->userImportHelper->getKey([
|
||||
'email' => $workspaceUser->email,
|
||||
], [
|
||||
'name' => $workspaceUser->name,
|
||||
'timezone' => $workspaceUser->timezone ?? 'UTC',
|
||||
'is_placeholder' => true,
|
||||
], (string) $workspaceUser->uid);
|
||||
}
|
||||
|
||||
foreach ($projects as $project) {
|
||||
$clientId = null;
|
||||
if ($project->client_id !== null) {
|
||||
@@ -74,28 +96,40 @@ class TogglDataImporter extends DefaultImporter
|
||||
throw new ImportException('Invalid color');
|
||||
}
|
||||
|
||||
$this->projectImportHelper->getKey([
|
||||
$projectId = $this->projectImportHelper->getKey([
|
||||
'name' => $project->name,
|
||||
'organization_id' => $this->organization->getKey(),
|
||||
], [
|
||||
'client_id' => $clientId,
|
||||
'color' => $project->color,
|
||||
'billable_rate' => $project->rate !== null ? (int) ($project->rate * 100) : null,
|
||||
], (string) $project->id);
|
||||
}
|
||||
foreach ($workspaceUsers as $workspaceUser) {
|
||||
$this->userImportHelper->getKey([
|
||||
'email' => $workspaceUser->email,
|
||||
], [
|
||||
'name' => $workspaceUser->name,
|
||||
'timezone' => $workspaceUser->timezone ?? 'UTC',
|
||||
'is_placeholder' => true,
|
||||
], (string) $workspaceUser->id);
|
||||
|
||||
if (! file_exists($temporaryDirectory->path('projects_users/'.$project->id.'.json'))) {
|
||||
throw new ImportException('File "projects_users/'.$project->id.'.json" missing in ZIP');
|
||||
}
|
||||
$projectMembersFileContent = file_get_contents($temporaryDirectory->path('projects_users/'.$project->id.'.json'));
|
||||
if ($projectMembersFileContent === false) {
|
||||
throw new ImportException('File "projects_users/'.$project->id.'.json" can not be opened');
|
||||
}
|
||||
$projectMembers = json_decode($projectMembersFileContent);
|
||||
foreach ($projectMembers as $projectMember) {
|
||||
$this->projectMemberImportHelper->getKey([
|
||||
'project_id' => $projectId,
|
||||
'user_id' => $this->userImportHelper->getKeyByExternalIdentifier((string) $projectMember->user_id),
|
||||
], [
|
||||
'billable_rate' => $projectMember->rate !== null ? (int) ($projectMember->rate * 100) : null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
$projectIds = $this->projectImportHelper->getExternalIds();
|
||||
foreach ($projectIds as $projectIdExternal) {
|
||||
if (! file_exists($temporaryDirectory->path('tasks/'.$projectIdExternal.'.json'))) {
|
||||
continue;
|
||||
}
|
||||
$tasksFileContent = file_get_contents($temporaryDirectory->path('tasks/'.$projectIdExternal.'.json'));
|
||||
if ($tasksFileContent === false) {
|
||||
throw new ImportException('File tasks/'.$projectIdExternal.'.json missing in ZIP');
|
||||
throw new ImportException('File "tasks/'.$projectIdExternal.'.json" can not be opened');
|
||||
}
|
||||
$tasks = json_decode($tasksFileContent);
|
||||
foreach ($tasks as $task) {
|
||||
|
||||
Reference in New Issue
Block a user