addOption('dry-run', null, InputOption::VALUE_NONE, 'Show what would be updated without actually updating'); } /** * @see Command::execute() */ protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); $dryRun = $input->getOption('dry-run'); $drafts = $this->draftRepository->findBy(['bookingNumber' => null]); if (0 === \count($drafts)) { $io->success('No drafts without booking number found.'); return Command::SUCCESS; } $io->title(sprintf('Processing %d draft(s)', \count($drafts))); $updated = 0; $failed = 0; $skipped = 0; foreach ($drafts as $draft) { $bookingId = $draft->getBookingId(); $user = $draft->getUser(); $bookingData = $this->dataLoader->fetchBookingData($bookingId, $user); if (!$bookingData instanceof Booking) { $io->warning(sprintf('Could not fetch booking %d for user %s', $bookingId, $user->getEmail())); ++$failed; continue; } // bookingNumber maps to BPN XML vorgang $bookingNumber = $bookingData->bookingNumber; if (null === $bookingNumber) { $io->warning(sprintf('No booking number (vorgang) found for booking %d', $bookingId)); ++$skipped; continue; } if ($dryRun) { $io->text(sprintf( '[DRY RUN] Would set booking number %d for draft %d (bookingId %d)', $bookingNumber, $draft->getId(), $bookingId )); } else { $draft->setBookingNumber($bookingNumber); } ++$updated; } if (false === $dryRun) { $this->entityManager->flush(); } $io->newLine(); $io->table( ['Status', 'Count'], [ ['Updated', $updated], ['Failed (API error)', $failed], ['Skipped (no booking number)', $skipped], ] ); if ($dryRun) { $io->note('Dry run - no changes were made.'); } else { $io->success(sprintf('Updated %d draft(s).', $updated)); } return Command::SUCCESS; } }