1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Movies\Command; |
4
|
|
|
|
5
|
|
|
use App\Movies\Entity\Movie; |
6
|
|
|
use App\Movies\Entity\MovieCard; |
7
|
|
|
use App\Movies\Parser\Megogo; |
8
|
|
|
use App\Movies\Repository\MovieCardRepository; |
9
|
|
|
use App\Movies\Repository\MovieRepository; |
10
|
|
|
use App\Users\Repository\UserRepository; |
11
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
12
|
|
|
use Psr\SimpleCache\CacheInterface; |
13
|
|
|
use Symfony\Component\Console\Command\Command; |
14
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
15
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
16
|
|
|
|
17
|
|
|
class LoadWatchCards extends Command |
18
|
|
|
{ |
19
|
|
|
/** @var $repository MovieRepository */ |
20
|
|
|
private $repository; |
21
|
|
|
|
22
|
|
|
private $userRepository; |
23
|
|
|
|
24
|
|
|
/** @var $parser Megogo */ |
25
|
|
|
private $parser; |
26
|
|
|
|
27
|
|
|
private $em; |
28
|
|
|
private $cache; |
29
|
|
|
|
30
|
|
|
private const CACHE_TIME = 2592000; // 30 days |
31
|
|
|
|
32
|
|
|
public function __construct(EntityManagerInterface $em, UserRepository $userRepository, MovieCardRepository $cardRepository, MovieRepository $repository, Megogo $parser, CacheInterface $cache, ?string $name = null) |
33
|
|
|
{ |
34
|
|
|
parent::__construct($name); |
35
|
|
|
|
36
|
|
|
$this->repository = $repository; |
37
|
|
|
$this->cardRepository = $cardRepository; |
|
|
|
|
38
|
|
|
$this->userRepository = $userRepository; |
39
|
|
|
$this->parser = $parser; |
40
|
|
|
$this->cache = $cache; |
41
|
|
|
$this->em = $em; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
protected function configure() |
45
|
|
|
{ |
46
|
|
|
$this |
47
|
|
|
->setName('app:load-watch-cards') |
48
|
|
|
->setDescription('Find movies on megogo') |
49
|
|
|
->setHelp('php bin/console app:load-watch-cards'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
protected function execute(InputInterface $i, OutputInterface $o) |
53
|
|
|
{ |
54
|
|
|
$title = 'Megogo'; |
55
|
|
|
$locale = 'uk'; |
56
|
|
|
$movies = $this->repository->findAllWithoutCardsQuery($title, $locale)->getResult(); |
57
|
|
|
$user = $this->userRepository->findOneBy([ |
58
|
|
|
'username' => 'support' |
59
|
|
|
]); |
60
|
|
|
|
61
|
|
|
/** @var $movie Movie */ |
62
|
|
|
foreach ($movies as $movie) { |
63
|
|
|
$cacheKey = 'megogo_notfound_' . $movie->getId(); |
64
|
|
|
if ($this->cache->has($cacheKey)) { |
65
|
|
|
continue; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
try { |
69
|
|
|
$url = $this->parser->getUrlByTitle($movie->getOriginalTitle()); |
70
|
|
|
} catch (\ErrorException $e) { |
|
|
|
|
71
|
|
|
$this->cache->set($cacheKey, true, self::CACHE_TIME); |
72
|
|
|
$o->writeln(sprintf( |
73
|
|
|
'[LoadWatchCards] [%s]: %s', $movie->getOriginalTitle(), $e->getMessage() |
74
|
|
|
)); |
75
|
|
|
continue; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
$description = sprintf('Дивитись онлайн в хорошій якості у найбільшому онлайн кінотеатрі у східній Європі'); |
79
|
|
|
$card = new MovieCard($movie, $user, $locale, $title, $description, MovieCard::TYPE_WATCH, $url); |
|
|
|
|
80
|
|
|
|
81
|
|
|
$this->em->persist($card); |
82
|
|
|
$this->em->flush(); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
} |
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.