validate v1 data before import (#1552)

This commit is contained in:
Kevin Papst
2020-03-15 23:34:14 +01:00
committed by GitHub
parent e6e6a1eeea
commit 6eeb01ad48
2 changed files with 41 additions and 1 deletions

3
.gitignore vendored
View File

@@ -1,4 +1,7 @@
# ========== KIMAI ==========
# some hosters require a htaccess to change the PHP version
.htaccess
.idea/
.DS_Store

View File

@@ -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;