From 313ae417476d70dab89a880091537352caf6ac05 Mon Sep 17 00:00:00 2001 From: Koen Caerels Date: Mon, 6 May 2024 11:46:55 +0200 Subject: [PATCH] Update import and fix scripts. --- .../Import/FixEmail/FixEmailHandler.php | 85 +++++++++++++++++++ .../ImportActiveMembersHandler.php | 15 ++-- .../Domain/Model/Member/MemberRepository.php | 5 ++ .../Domain/Model/Member/Subscription.php | 5 ++ .../Database/Member/MemberRepository.php | 11 +++ .../pdf/subscription_detail.html.twig | 3 +- .../Web/Controller/ImportController.php | 33 +++++++ frontends/member_module/.env.development | 3 +- 8 files changed, 153 insertions(+), 7 deletions(-) create mode 100644 application/YoshiKan/Application/Command/Import/FixEmail/FixEmailHandler.php diff --git a/application/YoshiKan/Application/Command/Import/FixEmail/FixEmailHandler.php b/application/YoshiKan/Application/Command/Import/FixEmail/FixEmailHandler.php new file mode 100644 index 0000000..dc1301c --- /dev/null +++ b/application/YoshiKan/Application/Command/Import/FixEmail/FixEmailHandler.php @@ -0,0 +1,85 @@ +subscriptionRepository->getAll(); + + /** @var Subscription $subscription */ + foreach ($allSubscriptions as $subscription) { + $filteredEmail = str_replace(' ', '', $subscription->getContactEmail()); + $filteredEmail = str_replace(';', '.', $filteredEmail); + $filteredEmail = str_replace('?', '.', $filteredEmail); + $filteredEmail = str_replace('²', '@', $filteredEmail); + $filteredEmail = strtolower($filteredEmail); + + $subscription->setContactEmail($filteredEmail); + $this->subscriptionRepository->save($subscription); + $this->entityManager->flush(); + + echo '
'.$subscription->getContactFirstname().' '.$subscription->getContactLastname().' -> '.$subscription->getContactEmail(); + ob_flush(); + flush(); + } + + return true; + } + + public function fixMembers(): bool + { + $allMembers = $this->memberRepository->getAll(); + + foreach ($allMembers as $member) { + $filteredEmail = str_replace(' ', '', $member->getContactEmail()); + $filteredEmail = str_replace(';', '.', $filteredEmail); + $filteredEmail = str_replace('?', '.', $filteredEmail); + $filteredEmail = str_replace('²', '@', $filteredEmail); + $filteredEmail = strtolower($filteredEmail); + + if ('' === $filteredEmail) { + $filteredEmail = 'judo.yoshikan@gmail.com'; + } + + $member->setContactInformation( + contactFirstname: $member->getContactFirstname(), + contactLastname: $member->getContactLastname(), + contactEmail: $filteredEmail, + contactPhone: $member->getContactPhone() + ); + $this->memberRepository->save($member); + $this->entityManager->flush(); + + echo '
'.$member->getFirstname().' '.$member->getLastname().' -> '.$member->getContactEmail(); + ob_flush(); + flush(); + } + + return true; + } +} diff --git a/application/YoshiKan/Application/Command/Import/ImportActiveMember/ImportActiveMembersHandler.php b/application/YoshiKan/Application/Command/Import/ImportActiveMember/ImportActiveMembersHandler.php index 62cd3c7..65d1462 100644 --- a/application/YoshiKan/Application/Command/Import/ImportActiveMember/ImportActiveMembersHandler.php +++ b/application/YoshiKan/Application/Command/Import/ImportActiveMember/ImportActiveMembersHandler.php @@ -66,17 +66,22 @@ public function import(): bool $dto = new \stdClass(); $dto->firstName = (string) $worksheet->getCellByColumnAndRow(2, $row)->getValue(); - $dto->lastName = mb_strtoupper($worksheet->getCellByColumnAndRow(1, $row)->getValue()); + $dto->lastName = mb_strtoupper((string) $worksheet->getCellByColumnAndRow(1, $row)->getValue()); $dto->dateOfBirth = Date::excelToDateTimeObject($worksheet->getCellByColumnAndRow(4, $row)->getValue())->format(\DateTimeInterface::ATOM); $dto->nationalNumber = (string) $worksheet->getCellByColumnAndRow(5, $row)->getValue(); $dto->street = (string) $worksheet->getCellByColumnAndRow(3, $row)->getValue(); - $dto->city = $worksheet->getCellByColumnAndRow(6, $row)->getValue(); + $dto->city = (string) $worksheet->getCellByColumnAndRow(6, $row)->getValue(); $dto->postalCode = (string) $worksheet->getCellByColumnAndRow(7, $row)->getValue(); $dto->contactPhone = (string) $worksheet->getCellByColumnAndRow(8, $row)->getValue(); - $dto->contactEmail = (string) $worksheet->getCellByColumnAndRow(9, $row)->getValue(); + + $contactEmail = 'judo.yoshikan@gmail.com'; + if ('' !== (string) $worksheet->getCellByColumnAndRow(9, $row)->getValue()) { + $contactEmail = (string) $worksheet->getCellByColumnAndRow(9, $row)->getValue(); + } + $dto->contactEmail = $contactEmail; $dto->gender = Gender::X; - $dto->location = $this->locationRepository->getById(LocationMapping::getLocationId($worksheet->getCellByColumnAndRow(26, $row)->getValue())); - $dto->grade = $this->gradeRepository->getById(GradeMapping::getGradeId($worksheet->getCellByColumnAndRow(25, $row)->getValue())); + $dto->location = $this->locationRepository->getById(LocationMapping::getLocationId((string) $worksheet->getCellByColumnAndRow(26, $row)->getValue())); + $dto->grade = $this->gradeRepository->getById(GradeMapping::getGradeId((string) $worksheet->getCellByColumnAndRow(25, $row)->getValue())); $dto->sporta = (bool) $worksheet->getCellByColumnAndRow(23, $row)->getValue(); $dto->jv = (bool) $worksheet->getCellByColumnAndRow(24, $row)->getValue(); if ($dto->sporta) { diff --git a/application/YoshiKan/Domain/Model/Member/MemberRepository.php b/application/YoshiKan/Domain/Model/Member/MemberRepository.php index bca7f85..4895773 100644 --- a/application/YoshiKan/Domain/Model/Member/MemberRepository.php +++ b/application/YoshiKan/Domain/Model/Member/MemberRepository.php @@ -61,4 +61,9 @@ public function getActiveMembersByFederationAndLocation(Federation $federation, * @return Member[] */ public function getActiveMembersByLocation(Location $location): array; + + /** + * @return Member[] + */ + public function getAll(): array; } diff --git a/application/YoshiKan/Domain/Model/Member/Subscription.php b/application/YoshiKan/Domain/Model/Member/Subscription.php index bfeda15..04b934f 100644 --- a/application/YoshiKan/Domain/Model/Member/Subscription.php +++ b/application/YoshiKan/Domain/Model/Member/Subscription.php @@ -396,6 +396,11 @@ public function setNewMemberFields( $this->addressCity = $addressCity; } + public function setContactEmail(string $contactEmail): void + { + $this->contactEmail = $contactEmail; + } + public function fullChange( string $contactFirstname, string $contactLastname, diff --git a/application/YoshiKan/Infrastructure/Database/Member/MemberRepository.php b/application/YoshiKan/Infrastructure/Database/Member/MemberRepository.php index af5d418..3ed399c 100644 --- a/application/YoshiKan/Infrastructure/Database/Member/MemberRepository.php +++ b/application/YoshiKan/Infrastructure/Database/Member/MemberRepository.php @@ -214,4 +214,15 @@ public function getActiveMembersByLocation(Location $location): array return $q->getQuery()->getResult(); } + + /** + * @return Member[] + */ + public function getAll(): array + { + $q = $this->createQueryBuilder('t')->andWhere('0 = 0'); + $q->addOrderBy('t.id', 'DESC'); + + return $q->getQuery()->getResult(); + } } diff --git a/application/YoshiKan/Infrastructure/Templates/pdf/subscription_detail.html.twig b/application/YoshiKan/Infrastructure/Templates/pdf/subscription_detail.html.twig index 3150dce..102043b 100644 --- a/application/YoshiKan/Infrastructure/Templates/pdf/subscription_detail.html.twig +++ b/application/YoshiKan/Infrastructure/Templates/pdf/subscription_detail.html.twig @@ -70,7 +70,8 @@ Gebdatum - ° {{ subscription.dateOfBirth |date('d/m/Y') }} ( {{ subscription.gender.value }} ) + ° {{ subscription.dateOfBirth |date('d/m/Y') }} + {# ( {{ subscription.gender.value }} )#} diff --git a/application/YoshiKan/Infrastructure/Web/Controller/ImportController.php b/application/YoshiKan/Infrastructure/Web/Controller/ImportController.php index d27c968..0cf7e30 100644 --- a/application/YoshiKan/Infrastructure/Web/Controller/ImportController.php +++ b/application/YoshiKan/Infrastructure/Web/Controller/ImportController.php @@ -13,6 +13,7 @@ namespace App\YoshiKan\Infrastructure\Web\Controller; +use App\YoshiKan\Application\Command\Import\FixEmail\FixEmailHandler; use App\YoshiKan\Application\Command\Import\ImportActiveMember\ImportActiveMembersHandler; use App\YoshiKan\Application\Command\Import\ImportSubscriptionArchive\ImportSubscriptionArchiveHandler; use App\YoshiKan\Domain\Model\Member\Federation; @@ -117,4 +118,36 @@ public function importArchiveMembersGrades(Request $request): Response return new JsonResponse($response, 200, []); } + + #[IsGranted('ROLE_DEVELOPER')] + #[Route('/mm/fWXCq7sBpYQngXil/import/fix/subscriptions', name: 'import_fix_subscription_emails', methods: ['GET'])] + public function fixSubscriptionEmails(Request $request): Response + { + $fixHandler = new FixEmailHandler( + $this->entityManager, + $this->entityManager->getRepository(Member::class), + $this->entityManager->getRepository(Subscription::class), + ); + $fixHandler->fixSubscriptions(); + + $response = 'Fixed!'; + + return new JsonResponse($response, 200, []); + } + + #[IsGranted('ROLE_DEVELOPER')] + #[Route('/mm/fWXCq7sBpYQngXil/import/fix/members', name: 'import_fix_member_emails', methods: ['GET'])] + public function fixMemberEmails(Request $request): Response + { + $fixHandler = new FixEmailHandler( + $this->entityManager, + $this->entityManager->getRepository(Member::class), + $this->entityManager->getRepository(Subscription::class), + ); + $fixHandler->fixMembers(); + + $response = 'Fixed!'; + + return new JsonResponse($response, 200, []); + } } diff --git a/frontends/member_module/.env.development b/frontends/member_module/.env.development index dc87409..db9fc4a 100644 --- a/frontends/member_module/.env.development +++ b/frontends/member_module/.env.development @@ -1,2 +1,3 @@ -VITE_API_URL=http://localhost.charlesproxy.com:8080/mm/api +# VITE_API_URL=http://localhost.charlesproxy.com:8080/mm/api +VITE_API_URL=http://localhost:8080/mm/api VITE_VERSION=0.0.2