accountService = $service; $this->random = $random; $this->hasher = $hasher; $this->messageMapper = $messageMapper; } protected function configure(): void { $this->setName('mail:account:export-threads'); $this->setDescription('Exports a user\'s account threads'); $this->addArgument(self::ARGUMENT_ACCOUNT_ID, InputArgument::REQUIRED); $this->addOption(self::OPTION_REDACT, 'r', InputOption::VALUE_NONE); } protected function execute(InputInterface $input, OutputInterface $output): int { $accountId = (int)$input->getArgument(self::ARGUMENT_ACCOUNT_ID); try { $account = $this->accountService->findById($accountId); } catch (DoesNotExistException $e) { $output->writeln("Account $accountId does not exist"); return 1; } $threads = $this->messageMapper->findThreadingData($account); if ($input->getOption(self::OPTION_REDACT)) { $salt = $this->random->generate(32); $output->writeln(json_encode( array_map(static fn (DatabaseMessage $message) => $message->redact( static fn (string $str) => hash('md5', $str . $salt) . '@redacted' ), $threads), JSON_PRETTY_PRINT )); } else { $output->writeln( json_encode( $threads, JSON_PRETTY_PRINT ) ); } return 0; } }