* @category Class * @license https://www.gnu.org/licenses/lgpl-3.0.en.html GNU Lesser General Public License * @link www.splendidbear.org * @since 2026. 07. 27. */ #[AsCommand( name: 'app:users:purge-expired-pending', description: 'Delete unverified accounts whose activation token has expired.', )] #[AsPeriodicTask(frequency: '1 hour')] final class PurgeExpiredPendingUsersCommand extends Command { public function __construct(private readonly UserRepository $userRepository) { parent::__construct(); } protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); $now = new DateTime(); $count = $this->userRepository->countExpiredPendingUsers($now); if ($input->getOption('dry-run')) { $io->note(sprintf('%d expired pending account(s) would be deleted.', $count)); return Command::SUCCESS; } if ($count === 0) { $io->success('No expired pending accounts found.'); return Command::SUCCESS; } $deleted = $this->userRepository->deleteExpiredPendingUsers($now); $io->success(sprintf('Deleted %d expired pending account(s).', $deleted)); return Command::SUCCESS; } protected function configure(): void { $this->addOption( 'dry-run', null, InputOption::VALUE_NONE, 'Report how many accounts would be deleted without deleting them.', ); } }