mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-08 00:02:15 +01:00
add support for activity columns in clockify exports
This commit is contained in:
@@ -50,7 +50,7 @@ class ClockifyProjectsImporter extends DefaultImporter
|
||||
]);
|
||||
}
|
||||
|
||||
if ($record[$tasksKey] !== '') {
|
||||
if ($tasksKey !== null && $record[$tasksKey] !== '') {
|
||||
$tasks = explode(', ', $record[$tasksKey]);
|
||||
foreach ($tasks as $task) {
|
||||
$this->taskImportHelper->getKey([
|
||||
@@ -90,20 +90,27 @@ class ClockifyProjectsImporter extends DefaultImporter
|
||||
throw new ImportException('Invalid CSV header, missing field: '.$requiredField);
|
||||
}
|
||||
}
|
||||
// Clockify renamed the "Task" column to "Tasks" in newer exports; accept either.
|
||||
if (! in_array('Task', $header, true) && ! in_array('Tasks', $header, true)) {
|
||||
// Clockify names the tasks column "Task", "Tasks" or "Activities" depending on the export; accept any.
|
||||
if ($this->getTasksKey($header) === null) {
|
||||
throw new ImportException('Invalid CSV header, missing field: Tasks');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clockify renamed the "Task" column to "Tasks" in newer exports.
|
||||
* Clockify names the tasks column differently depending on the export
|
||||
* version: "Task" (older), "Tasks" (newer) or "Activities".
|
||||
*
|
||||
* @param array<string> $header
|
||||
*/
|
||||
private function getTasksKey(array $header): string
|
||||
private function getTasksKey(array $header): ?string
|
||||
{
|
||||
return in_array('Tasks', $header, true) ? 'Tasks' : 'Task';
|
||||
foreach (['Tasks', 'Task', 'Activities'] as $field) {
|
||||
if (in_array($field, $header, true)) {
|
||||
return $field;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -54,6 +54,7 @@ class ClockifyTimeEntriesImporter extends DefaultImporter
|
||||
$reader->setEscape('');
|
||||
$header = $reader->getHeader();
|
||||
$this->validateHeader($header);
|
||||
$taskKey = $this->getTaskKey($header);
|
||||
$records = $reader->getRecords();
|
||||
foreach ($records as $record) {
|
||||
$userId = $this->userImportHelper->getKey([
|
||||
@@ -96,9 +97,9 @@ class ClockifyTimeEntriesImporter extends DefaultImporter
|
||||
]);
|
||||
}
|
||||
$taskId = null;
|
||||
if ($record['Task'] !== '') {
|
||||
if ($taskKey !== null && $record[$taskKey] !== '') {
|
||||
$taskId = $this->taskImportHelper->getKey([
|
||||
'name' => $record['Task'],
|
||||
'name' => $record[$taskKey],
|
||||
'project_id' => $projectId,
|
||||
'organization_id' => $this->organization->id,
|
||||
]);
|
||||
@@ -216,7 +217,6 @@ class ClockifyTimeEntriesImporter extends DefaultImporter
|
||||
'Project',
|
||||
'Client',
|
||||
'Description',
|
||||
'Task',
|
||||
'User',
|
||||
'Group',
|
||||
'Email',
|
||||
@@ -231,6 +231,26 @@ class ClockifyTimeEntriesImporter extends DefaultImporter
|
||||
throw new ImportException('Invalid CSV header, missing field: '.$requiredField);
|
||||
}
|
||||
}
|
||||
// Clockify names the task column "Task" or "Activity" depending on the export; accept either.
|
||||
if ($this->getTaskKey($header) === null) {
|
||||
throw new ImportException('Invalid CSV header, missing field: Task');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clockify names the task column "Task" or "Activity" depending on the export version.
|
||||
*
|
||||
* @param array<string> $header
|
||||
*/
|
||||
private function getTaskKey(array $header): ?string
|
||||
{
|
||||
foreach (['Task', 'Activity'] as $field) {
|
||||
if (in_array($field, $header, true)) {
|
||||
return $field;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
|
||||
Reference in New Issue
Block a user