From b75454e86368087f0fc0ddfc5f7277f6da5970a6 Mon Sep 17 00:00:00 2001 From: h2entwicklung Date: Mon, 24 Apr 2023 22:50:18 +0200 Subject: [PATCH] * fix emails sometime contains newline return * repair contains now fix of the emails if they contain newline characters --- Dockerfile | 1 + install.sh | 1 + src/Command/SystemRepairCommand.php | 47 ++++++++++++++++++++--------- src/Entity/User.php | 4 +-- tests/Rooms/RoomAddServiceTest.php | 2 +- 5 files changed, 38 insertions(+), 17 deletions(-) diff --git a/Dockerfile b/Dockerfile index fa21c8d85..25954c486 100644 --- a/Dockerfile +++ b/Dockerfile @@ -26,4 +26,5 @@ RUN chown -R www-data:www-data var RUN chmod -R 777 var RUN chown -R www-data:www-data public/uploads/ RUN chmod -R 775 public/uploads/ +RUN php bin/console app:system:repair USER docker \ No newline at end of file diff --git a/install.sh b/install.sh index 3ce261bee..1bb8c4735 100644 --- a/install.sh +++ b/install.sh @@ -62,6 +62,7 @@ clear php bin/console cache:clear clear php bin/console cache:warmup +php bin/console app:system:repair clear npm install diff --git a/src/Command/SystemRepairCommand.php b/src/Command/SystemRepairCommand.php index dfa19045c..757849a7b 100644 --- a/src/Command/SystemRepairCommand.php +++ b/src/Command/SystemRepairCommand.php @@ -18,9 +18,9 @@ class SystemRepairCommand extends Command protected static $defaultName = 'app:system:repair'; protected static $defaultDescription = 'Add a short description for your command'; private $em; + private SymfonyStyle $io; - - public function __construct(EntityManagerInterface $entityManager,string $name = null) + public function __construct(EntityManagerInterface $entityManager, string $name = null) { parent::__construct($name); $this->em = $entityManager; @@ -35,13 +35,20 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); + $this->io = $io; $io->info('We try to repair the system.....'); $count = 0; - $rooms =$this->em->getRepository(Rooms::class)->findAll(); + $user = $this->em->getRepository(User::class)->findAll(); + $io->info('--------We start with the users------'); + foreach ($user as $u){ + $this->repairEmail(user: $u); + } + $this->em->flush(); + $rooms = $this->em->getRepository(Rooms::class)->findAll(); - foreach ($rooms as $room){ - if(!$room->getModerator() || !$room->getServer()){ - foreach ($room->getUser() as $user){ + foreach ($rooms as $room) { + if (!$room->getModerator() || !$room->getServer()) { + foreach ($room->getUser() as $user) { $count++; $room->removeUser($user); } @@ -50,8 +57,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int } $this->em->flush(); $lobbyWaitingUser = $this->em->getRepository(LobbyWaitungUser::class)->findAll(); - foreach ($lobbyWaitingUser as $waitingUser){ - if($waitingUser->getCreatedAt() < (new \DateTime())->modify('-10days')){ + foreach ($lobbyWaitingUser as $waitingUser) { + if ($waitingUser->getCreatedAt() < (new \DateTime())->modify('-10days')) { $count++; $this->em->remove($waitingUser); } @@ -59,18 +66,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->em->flush(); $user = $this->em->getRepository(User::class)->findAll(); $count += $this->repairWaitungUser(); - $io->success(sprintf('We found %d coruppt datasets',$count)); + $io->success(sprintf('We found %d coruppt datasets', $count)); return Command::SUCCESS; } - private function repairWaitungUser(){ - $waitingUser =$this->em->getRepository(LobbyWaitungUser::class)->findAll(); + private function repairWaitungUser() + { + $waitingUser = $this->em->getRepository(LobbyWaitungUser::class)->findAll(); $count = 0; - foreach ($waitingUser as $data){ + foreach ($waitingUser as $data) { try { - $session = $data->getCallerSession(); - }catch (\Exception $exception){ + $session = $data->getCallerSession(); + } catch (\Exception $exception) { $this->em->remove($data); $count++; } @@ -78,4 +86,15 @@ private function repairWaitungUser(){ $this->em->flush(); return $count; } + + private function repairEmail(User $user) + { + $emailOrg = $user->getEmail(); + $email = rtrim($user->getEmail()); + if ($email!== $emailOrg){ + $this->io->info(sprintf('-------%s was corrupt--------',$email)); + $user->setEmail(email: $email); + $this->em->persist($user); + } + } } diff --git a/src/Entity/User.php b/src/Entity/User.php index 3003dbdf2..3f7f899d7 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -145,7 +145,7 @@ public function getEmail(): ?string public function setEmail(string $email): self { - $this->email = $email; + $this->email = rtrim($email); return $this; } @@ -181,7 +181,7 @@ public function getUsername(): ?string public function setUsername(?string $username): self { - $this->username = $username; + $this->username = rtrim($username); return $this; } diff --git a/tests/Rooms/RoomAddServiceTest.php b/tests/Rooms/RoomAddServiceTest.php index ca07d93a1..f2921b3ec 100644 --- a/tests/Rooms/RoomAddServiceTest.php +++ b/tests/Rooms/RoomAddServiceTest.php @@ -19,7 +19,7 @@ public function testaddParticipant(): void $roomAddService = self::getContainer()->get(RoomAddService::class); $roomRepo = self::getContainer()->get(RoomsRepository::class); $room = $roomRepo->findOneBy(array('name' => 'TestMeeting: 0')); - $user = "test@local5.de\ntest@local4.de\ntest@local6.de"; + $user = "test@local5.de".PHP_EOL.PHP_EOL."test@local4.de".PHP_EOL."test@local6.de"; $res = $roomAddService->createParticipants($user, $room); self::assertEquals(0, sizeof($res)); $count = 0;