Skip to content

Commit

Permalink
Merge pull request #383 from H2-invent/hotfix/clean_email_new_line
Browse files Browse the repository at this point in the history
Hotfix/clean email new line
  • Loading branch information
holema authored Apr 25, 2023
2 parents 6373867 + b75454e commit 34bb809
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 17 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
47 changes: 33 additions & 14 deletions src/Command/SystemRepairCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand All @@ -50,32 +57,44 @@ 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);
}
}
$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++;
}
}
$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);
}
}
}
4 changes: 2 additions & 2 deletions src/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public function getEmail(): ?string

public function setEmail(string $email): self
{
$this->email = $email;
$this->email = rtrim($email);

return $this;
}
Expand Down Expand Up @@ -181,7 +181,7 @@ public function getUsername(): ?string

public function setUsername(?string $username): self
{
$this->username = $username;
$this->username = rtrim($username);

return $this;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Rooms/RoomAddServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "[email protected]\ntest@local4.de\ntest@local6.de";
$user = "[email protected]".PHP_EOL.PHP_EOL."test@local4.de".PHP_EOL."test@local6.de";
$res = $roomAddService->createParticipants($user, $room);
self::assertEquals(0, sizeof($res));
$count = 0;
Expand Down

0 comments on commit 34bb809

Please sign in to comment.