diff --git a/old/src/PointToolsBundle/Command/UpdateSubscriptionsCommand.php b/src/Command/UpdateSubscriptionsCommand.php similarity index 76% rename from old/src/PointToolsBundle/Command/UpdateSubscriptionsCommand.php rename to src/Command/UpdateSubscriptionsCommand.php index 9506b48..ddf2f33 100644 --- a/old/src/PointToolsBundle/Command/UpdateSubscriptionsCommand.php +++ b/src/Command/UpdateSubscriptionsCommand.php @@ -1,77 +1,40 @@ em = $em; - $this->logger = $logger; - $this->userRepo = $userRepo; - $this->api = $api; - $this->subscriptionManager = $subscriptionManager; - $this->apiDelay = $apiDelay; - $this->appUserId = $appUserId; } protected function configure() { $this - ->setName('point:update:subscriptions') - ->setDescription('Update subscriptions of users subscribed to service') ->addOption( 'all-users', null, @@ -87,46 +50,46 @@ class UpdateSubscriptionsCommand extends Command ; } - 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('UpdateSubscriptionsCommand started.'); - $this->progress = new ProgressBar($output); - $this->progress->setFormat('debug'); + $progress = $io->createProgressBar(); + $progress->setFormat(ProgressBar::FORMAT_DEBUG); if (!$input->getOption('check-only')) { // Beginning transaction for all changes $this->em->beginTransaction(); } try { - $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; } if (0 === count($usersForUpdate)) { $this->logger->info('No local subscribers. Finishing.'); - return 0; + return Command::SUCCESS; } $this->logger->info('Processing users subscribers'); - $this->progress->start(count($usersForUpdate)); + $progress->start(count($usersForUpdate)); 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(); // Flushing all changes at once to the database if (!$input->getOption('check-only')) { @@ -136,7 +99,7 @@ class UpdateSubscriptionsCommand extends Command $this->logger->debug('Finished'); - return 0; + return Command::SUCCESS; } private function updateUser(User $user): void @@ -183,11 +146,11 @@ class UpdateSubscriptionsCommand extends Command } } - private function getUsersForUpdate(): array + private function getUsersForUpdate(InputInterface $input): array { $usersForUpdate = []; - if ($this->input->getOption('all-users')) { + if ($input->getOption('all-users')) { $usersForUpdate = $this->userRepo->findBy(['removed' => false]); } else { /** @var User $serviceUser */ @@ -258,4 +221,4 @@ class UpdateSubscriptionsCommand extends Command return $usersForUpdate; } -} \ No newline at end of file +}