Completed
Push — master ( c5110b...a167e6 )
by Valentyn
13:46
created

FixReleaseDateQueue   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 2
cbo 5
dl 0
loc 48
ccs 0
cts 26
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A configure() 0 7 1
A execute() 0 24 4
1
<?php
2
3
namespace App\Movies\Command;
4
5
use App\Movies\Entity\ReleaseDateQueue;
6
use App\Movies\Repository\ReleaseDateQueueRepository;
7
use App\Movies\Service\ImdbIdLoaderService;
8
use Doctrine\ORM\EntityManagerInterface;
9
use Symfony\Component\Console\Command\Command;
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Output\OutputInterface;
12
13
class FixReleaseDateQueue extends Command
14
{
15
    private $repository;
16
    private $imdb;
17
    private $em;
18
19
    public function __construct(ImdbIdLoaderService $imdb, ReleaseDateQueueRepository $repository, EntityManagerInterface $em, ?string $name = null)
20
    {
21
        parent::__construct($name);
22
23
        $this->repository = $repository;
24
        $this->imdb = $imdb;
25
        $this->em = $em;
26
    }
27
28
    protected function configure()
29
    {
30
        $this
31
            ->setName('app:fix-release-date-queue')
32
            ->setDescription('Check inactive queue items to fix them')
33
            ->setHelp('This command will search for inactive queue items and will try to fix them (load imdb id)');
34
    }
35
36
    protected function execute(InputInterface $input, OutputInterface $output)
37
    {
38
        $queueItems = $this->repository->findAllWithMovies(0)->getResult();
39
40
        $i = 0;
41
        /** @var $queueItem ReleaseDateQueue */
42
        foreach ($queueItems as $queueItem) {
43
            $movie = $queueItem->getMovie();
44
            $tmdbId = $movie->getTmdb()->getId();
45
            if (null !== $imdbId = $this->imdb->getImdbId($tmdbId)) {
46
                $queueItem->activate();
47
                $movie->setImdbId($imdbId);
48
            }
49
50
            if ($i === 5) {
51
                $i = 0;
52
                sleep(5);
53
            }
54
55
            ++$i;
56
        }
57
58
        $this->em->flush();
59
    }
60
}
61