Skip to content

Commit

Permalink
fixes #11 - projects are created multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinpapst committed Jan 14, 2024
1 parent 4242799 commit bba32a7
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions Importer/AbstractTimesheetImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use App\Entity\Tag;
use App\Entity\User;
use App\Project\ProjectService;
use App\Repository\ProjectRepository;
use App\Repository\TagRepository;
use App\Timesheet\TimesheetService;
use App\User\UserService;
Expand Down Expand Up @@ -62,12 +63,13 @@ abstract class AbstractTimesheetImporter
private bool $globalActivity = true;

public function __construct(
private CustomerService $customerService,
private ProjectService $projectService,
private ActivityService $activityService,
private UserService $userService,
private TagRepository $tagRepository,
private TimesheetService $timesheetService,
private readonly CustomerService $customerService,
private readonly ProjectService $projectService,
private readonly ProjectRepository $projectRepository,
private readonly ActivityService $activityService,
private readonly UserService $userService,
private readonly TagRepository $tagRepository,
private readonly TimesheetService $timesheetService,
protected TranslatorInterface $translator,
) {
}
Expand Down Expand Up @@ -412,13 +414,7 @@ private function getProject(string $project, string $customer, bool $dryRun): Pr

if (!\array_key_exists($cacheKey, $this->projectCache)) {
$tmpCustomer = $this->getCustomer($customer, $dryRun);
$tmpProject = $this->projectService->findProjectByName($project);

if (null !== $tmpProject && $tmpProject->getCustomer() !== null) {
if ($tmpProject->getCustomer()->getName() !== null && $tmpCustomer->getName() !== null && strcasecmp($tmpProject->getCustomer()->getName(), $tmpCustomer->getName()) !== 0) {
$tmpProject = null;
}
}
$tmpProject = $this->projectRepository->findOneBy(['name' => $project, 'customer' => $tmpCustomer->getId()]);

if ($tmpProject === null) {
$tmpProject = $this->projectService->createNewProject($tmpCustomer);
Expand Down

0 comments on commit bba32a7

Please sign in to comment.