mapper = $mapper; $this->tagMapper = $tagMapper; $this->logger = $logger; } /** * @return void */ protected function configure() { $this->setName('mail:repair:tags'); $this->setDescription('Create default tags for account. If no account ID given, all tag entries will be repaired'); $this->addArgument(self::ARGUMENT_ACCOUNT_ID, InputArgument::OPTIONAL); } protected function execute(InputInterface $input, OutputInterface $output): int { $accountId = (int)$input->getArgument(self::ARGUMENT_ACCOUNT_ID); if ($accountId === 0) { $accounts = $this->mapper->getAllAccounts(); $output->writeln(sprintf('%d accounts to check found', count($accounts))); if ($accounts === []) { $output->writeLn('No accounts exist'); return 1; } } else { try { $account = $this->mapper->findById($accountId); $accounts = [$account]; $output->writeLn('Found account with email: ' . $account->getEmail() . ''); } catch (DoesNotExistException $e) { $output->writeLn('This account does not exist'); } } $progress = new ProgressBar($output); foreach ($accounts as $account) { $this->tagMapper->createDefaultTags($account); $progress->advance(); } $progress->finish(); $output->writeln(''); $output->writeln('Patched default tags for ' . count($accounts)); return 0; } }