addOption('days', 'd', InputOption::VALUE_REQUIRED, 'Keep entries younger than this many days', (string)self::DEFAULT_DAYS); } protected function execute(InputInterface $input, OutputInterface $output): int { $days = (int)$input->getOption('days'); if ($days < 1) { $output->writeln('--days must be at least 1'); return Command::INVALID; } $cutoff = time() - $days * 86400; $conn = $this->connectionPool->getConnectionForTable(self::TABLE); $deleted = $conn->executeStatement('DELETE FROM ' . self::TABLE . ' WHERE crdate < ?', [$cutoff]); $remaining = (int)$conn->executeQuery('SELECT COUNT(*) FROM ' . self::TABLE)->fetchOne(); $output->writeln(sprintf( 'deleted %d client error report(s) older than %d days (before %s), %d remaining', $deleted, $days, date('Y-m-d H:i', $cutoff), $remaining )); return Command::SUCCESS; } }