addOption( 'retention', 'r', InputOption::VALUE_REQUIRED, 'Retention period in months', (string) self::DEFAULT_RETENTION_MONTHS ); } protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); $retentionMonths = (int) $input->getOption('retention'); if ($retentionMonths < 1) { $io->error('Retention period must be at least 1 month.'); return Command::FAILURE; } $threshold = (new \DateTimeImmutable())->modify(sprintf('-%d months', $retentionMonths)); $deletedCount = $this->logEntryRepository->deleteOlderThan($threshold); $message = sprintf( 'Removed %d log entries older than %d month%s (before %s)', $deletedCount, $retentionMonths, 1 === $retentionMonths ? '' : 's', $threshold->format('Y-m-d H:i:s') ); $this->logger->info($message); $io->success($message); return Command::SUCCESS; } }