zend-blog-3-backend

Форк
0
/
FakeEmailCheck.php 
68 строк · 1.7 Кб
1
<?php
2

3
namespace App\Command;
4

5
use App\Repository\CommentatorRepository;
6
use App\Utils\VerifyEmail;
7
use Doctrine\ORM\EntityManagerInterface;
8
use Symfony\Component\Console\Command\Command;
9
use Symfony\Component\Console\Helper\Table;
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Output\OutputInterface;
12

13
class FakeEmailCheck extends Command
14
{
15
    private CommentatorRepository $repository;
16

17
    private EntityManagerInterface $em;
18

19
    public function __construct(CommentatorRepository $repository, EntityManagerInterface $em)
20
    {
21
        parent::__construct();
22

23
        $this->repository = $repository;
24
        $this->em = $em;
25
    }
26

27
    protected function configure(): void
28
    {
29
        $this
30
            ->setName('mtt:fake-email:check')
31
            ->setDescription('Check commentators email')
32
        ;
33
    }
34

35
    protected function execute(InputInterface $input, OutputInterface $output): int
36
    {
37
        $rows = [];
38

39
        $commentators = $this->repository->getWithUncheckedEmails();
40
        foreach ($commentators as $entity) {
41
            $result = VerifyEmail::isValid($entity->getEmail());
42

43
            $entity
44
                ->setFakeEmail(!$result)
45
                ->setEmailCheck(new \DateTime())
46
            ;
47

48
            $rows[] = [
49
                $entity->getId(),
50
                $entity->getEmail(),
51
                $result ? '<fg=green>true</>' : '<fg=red>false</>',
52
            ];
53
        }
54

55
        $this->em->flush();
56

57
        if (count($rows)) {
58
            $table = new Table($output);
59
            $table->setHeaders(['ID', 'email', 'result']);
60

61
            $table->setRows($rows)->render();
62
        } else {
63
            $output->writeln('Nothing to check');
64
        }
65

66
        return 0;
67
    }
68
}
69

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.