diff --git a/old/src/PointToolsBundle/Command/UpdateUsersPrivacyCommand.php b/src/Command/UpdateUsersPrivacyCommand.php similarity index 70% rename from old/src/PointToolsBundle/Command/UpdateUsersPrivacyCommand.php rename to src/Command/UpdateUsersPrivacyCommand.php index efec431..14b89b8 100644 --- a/old/src/PointToolsBundle/Command/UpdateUsersPrivacyCommand.php +++ b/src/Command/UpdateUsersPrivacyCommand.php @@ -1,66 +1,40 @@ em = $em; - $this->logger = $logger; - $this->userRepo = $userRepo; - $this->api = $api; - $this->apiDelay = $apiDelay; - $this->appUserId = $appUserId; } - /** - * {@inheritdoc} - */ protected function configure() { $this - ->setName('point:update:privacy') - ->setDescription('Update users privacy') ->addOption( 'all-users', null, @@ -70,47 +44,43 @@ class UpdateUsersPrivacyCommand extends Command ; } - /** - * {@inheritdoc} - */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { - $this->input = $input; + $io = new SymfonyStyle($input, $output); $this->logger->debug(static::class.' started.'); - $this->progress = new ProgressBar($output); - $this->progress->setFormat('debug'); + $progress = $io->createProgressBar(); + $progress->setFormat(ProgressBar::FORMAT_DEBUG); try { - /** @var User[] $usersForUpdate */ - $usersForUpdate = $this->getUsersForUpdate(); + $usersForUpdate = $this->getUsersForUpdate($input); } catch (\Exception $e) { $this->logger->error('Error while getting service subscribers', ['exception' => get_class($e), 'message' => $e->getMessage()]); - return 1; + return Command::FAILURE; } $this->logger->info('Processing users privacy.'); - $this->progress->start(count($usersForUpdate)); + $progress->start(count($usersForUpdate)); - foreach ($usersForUpdate as $idx => $user) { + foreach ($usersForUpdate as $user) { usleep($this->apiDelay); - $this->progress->advance(); + $progress->advance(); $this->logger->info('Processing @'.$user->getLogin()); $this->updateUser($user); } - $this->progress->finish(); + $progress->finish(); $this->em->flush(); $this->logger->debug('Finished'); - return 0; + return Command::SUCCESS; } private function updateUser(User $user): void @@ -150,9 +120,10 @@ class UpdateUsersPrivacyCommand extends Command } } - private function getUsersForUpdate(): array + /** @return User[] */ + private function getUsersForUpdate(InputInterface $input): array { - if ($this->input->getOption('all-users')) { + if ($input->getOption('all-users')) { return $this->userRepo->findBy(['removed' => false]); } @@ -197,7 +168,6 @@ class UpdateUsersPrivacyCommand extends Command $localSubscribers = []; - /** @var Subscription $subscription */ foreach ($serviceUser->getSubscribers() as $subscription) { $localSubscribers[] = $subscription->getSubscriber(); }