diff --git a/.gitignore b/.gitignore index 21f2e561..6409d14f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ # ========== KIMAI ========== +# some hosters require a htaccess to change the PHP version +.htaccess + .idea/ .DS_Store diff --git a/src/Command/KimaiImporterCommand.php b/src/Command/KimaiImporterCommand.php index 3f76db34..57b395ce 100755 --- a/src/Command/KimaiImporterCommand.php +++ b/src/Command/KimaiImporterCommand.php @@ -291,7 +291,44 @@ final class KimaiImporterCommand extends Command $bytesCached = memory_get_usage(true); - $io->success('Fetched Kimai v1 data, trying to import now ...'); + $io->success('Fetched Kimai v1 data, validating now ...'); + $validationMessages = []; + try { + $usedEmails = []; + foreach ($users as $oldUser) { + if (empty($oldUser['mail'])) { + $validationMessages[] = sprintf('User "%s" with ID %s has no email', $oldUser['name'], $oldUser['userID']); + continue; + } + if (in_array($oldUser['mail'], $usedEmails)) { + $validationMessages[] = sprintf('Email "%s" for user "%s" with ID %s is already used', $oldUser['mail'], $oldUser['name'], $oldUser['userID']); + } + $usedEmails[] = $oldUser['mail']; + } + + $customerIds = []; + foreach ($customer as $oldCustomer) { + $customerIds[] = $oldCustomer['customerID']; + } + + foreach ($projects as $oldProject) { + if (!in_array($oldProject['customerID'], $customerIds)) { + $validationMessages[] = sprintf('Project "%s" with ID %s has unknown customer with ID %s', $oldProject['name'], $oldProject['projectID'], $oldProject['customerID']); + } + } + } catch (Exception $ex) { + $validationMessages[] = $ex->getMessage(); + } + + if (!empty($validationMessages)) { + foreach ($validationMessages as $errorMessage) { + $io->error($errorMessage); + } + + return 1; + } + + $io->success('Pre-validated data, trying to import now ...'); $allImports = 0;