From 405b8a9f598e2122d1fe3c2dffa4fe56ba90f7b1 Mon Sep 17 00:00:00 2001 From: Alexey Skobkin Date: Sun, 19 Mar 2023 18:50:25 +0300 Subject: [PATCH] Ported RestoreRemovedUsersCommand. --- src/Command/ImportUsersCommand.php | 1 - .../Command/RestoreRemovedUsersCommand.php | 66 ++++++------------- 2 files changed, 20 insertions(+), 47 deletions(-) rename {old/src/PointToolsBundle => src}/Command/RestoreRemovedUsersCommand.php (58%) diff --git a/src/Command/ImportUsersCommand.php b/src/Command/ImportUsersCommand.php index 33a3a2e..1dd9d46 100644 --- a/src/Command/ImportUsersCommand.php +++ b/src/Command/ImportUsersCommand.php @@ -57,7 +57,6 @@ class ImportUsersCommand extends Command protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); - $fs = new Filesystem(); $fileName = $input->getArgument('file'); diff --git a/old/src/PointToolsBundle/Command/RestoreRemovedUsersCommand.php b/src/Command/RestoreRemovedUsersCommand.php similarity index 58% rename from old/src/PointToolsBundle/Command/RestoreRemovedUsersCommand.php rename to src/Command/RestoreRemovedUsersCommand.php index e8bc057..9d49703 100644 --- a/old/src/PointToolsBundle/Command/RestoreRemovedUsersCommand.php +++ b/src/Command/RestoreRemovedUsersCommand.php @@ -1,67 +1,40 @@ logger = $logger; - $this->em = $em; - $this->userRepo = $userRepo; - $this->userApi = $userApi; - $this->delay = $apiDelay; } - /** - * {@inheritdoc} - */ - protected function configure() + protected function execute(InputInterface $input, OutputInterface $output): int { - $this - ->setName('point:users:restore') - ->setDescription('Check removed users status and restore if user was deleted by error.') - ; - } + $io = new SymfonyStyle($input, $output); - /** - * {@inheritdoc} - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - /** @var User $removedUser */ foreach ($this->userRepo->findBy(['removed' => true]) as $removedUser) { - usleep($this->delay); + \usleep($this->apiDelay); try { - /** @var User $remoteUser */ $remoteUser = $this->userApi->getUserById($removedUser->getId()); if ($remoteUser->getId() === $removedUser->getId()) { @@ -70,7 +43,6 @@ class RestoreRemovedUsersCommand extends Command 'login' => $removedUser->getLogin(), ]); $removedUser->restore(); - $this->em->flush(); } } catch (UserNotFoundException $e) { @@ -93,5 +65,7 @@ class RestoreRemovedUsersCommand extends Command } $this->em->flush(); + + return Command::SUCCESS; } }