addOption('dry-run', null, InputOption::VALUE_NONE, 'Show what would be deleted without actually deleting'); } /** * @see Command::execute() */ protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); $dryRun = $input->getOption('dry-run'); if ($dryRun) { $expiredDrafts = $this->draftRepository->createQueryBuilder('d') ->where('d.travelDate < :today') ->setParameter('today', new \DateTimeImmutable('today')) ->getQuery() ->getResult(); $count = \count($expiredDrafts); if (0 === $count) { $io->success('No expired drafts found.'); return Command::SUCCESS; } $io->note(sprintf('[DRY RUN] Would delete %d expired draft(s)', $count)); return Command::SUCCESS; } $deletedCount = $this->draftRepository->deleteExpiredDrafts(); if (0 === $deletedCount) { $io->success('No expired drafts found.'); return Command::SUCCESS; } $this->logger->info('Deleted expired booking edit drafts', [ 'count' => $deletedCount, ]); $io->success(sprintf('Deleted %d expired draft(s).', $deletedCount)); return Command::SUCCESS; } }