Private
Public Access
79 lines
2.3 KiB
PHP
79 lines
2.3 KiB
PHP
<?php declare(strict_types=1);
|
|||
|
|
/*
|
||
|
|
* This file is part of the SplendidBear Websites' projects.
|
||
|
|
*
|
||
|
|
* Copyright (c) 2026 @ www.splendidbear.org
|
||
|
|
*
|
||
|
|
* For the full copyright and license information, please view the LICENSE
|
||
|
|
* file that was distributed with this source code.
|
||
|
|
*/
|
||
|
|
|
||
|
|
namespace App\Command;
|
||
|
|
|
||
|
|
use App\Repository\UserRepository;
|
||
|
|
use DateTime;
|
||
|
|
use Symfony\Component\Console\Attribute\AsCommand;
|
||
|
|
use Symfony\Component\Console\Command\Command;
|
||
|
|
use Symfony\Component\Console\Input\InputInterface;
|
||
|
|
use Symfony\Component\Console\Input\InputOption;
|
||
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
||
|
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
||
|
|
use Symfony\Component\Scheduler\Attribute\AsPeriodicTask;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Class PurgeExpiredPendingUsersCommand
|
||
|
|
*
|
||
|
|
* @package App\Command
|
||
|
|
* @author Lang <https://www.splendidbear.org>
|
||
|
|
* @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.',
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|