1 | <?php |
||
20 | class MovieTranslationsProcessor implements Processor, TopicSubscriberInterface |
||
21 | { |
||
22 | const LOAD_TRANSLATIONS = 'LoadMoviesTranslationsFromTMDB'; |
||
23 | |||
24 | private $em; |
||
25 | private $searchService; |
||
26 | private $movieRepository; |
||
27 | private $locales; |
||
28 | private $localesCount; |
||
29 | private $producer; |
||
30 | |||
31 | 3 | public function __construct(EntityManagerInterface $em, ProducerInterface $producer, MovieRepository $movieRepository, TmdbSearchService $searchService, LocaleService $localeService) |
|
40 | |||
41 | /** |
||
42 | * @param QMessage $message |
||
43 | * @param Context $session |
||
44 | * |
||
45 | * @throws \Doctrine\ORM\ORMException |
||
46 | * @throws \ErrorException |
||
47 | * |
||
48 | * @return object|string |
||
49 | */ |
||
50 | 3 | public function process(QMessage $message, Context $session) |
|
87 | |||
88 | /** |
||
89 | * @param int $tmdbId |
||
90 | * |
||
91 | * @throws TmdbMovieNotFoundException |
||
92 | * @throws TmdbRequestLimitException |
||
93 | * |
||
94 | * @return \Iterator |
||
95 | */ |
||
96 | 3 | private function loadTranslationsFromTMDB(int $tmdbId): \Iterator |
|
110 | |||
111 | /** |
||
112 | * @param \Iterator $moviesTranslationsDTOs |
||
113 | * @param Movie $movie |
||
114 | * |
||
115 | * @throws \Doctrine\ORM\ORMException |
||
116 | * @throws \ErrorException |
||
117 | */ |
||
118 | 3 | private function addTranslations(\Iterator $moviesTranslationsDTOs, Movie $movie): void |
|
135 | |||
136 | /** |
||
137 | * @param Movie $movie |
||
138 | * |
||
139 | * @throws \ErrorException |
||
140 | * |
||
141 | * @return bool |
||
142 | */ |
||
143 | 3 | private function isAllTranslationsSaved(Movie $movie): bool |
|
144 | { |
||
145 | 3 | $existingTranslations = []; |
|
146 | 3 | foreach ($this->locales as $locale) { |
|
147 | 3 | if ($movie->getTranslation($locale, false) !== null) { |
|
148 | $existingTranslations[] = $locale; |
||
149 | } |
||
150 | } |
||
151 | |||
152 | 3 | return \count(array_diff($this->locales, $existingTranslations)) <= 2; |
|
153 | } |
||
154 | |||
155 | public static function getSubscribedTopics() |
||
159 | } |
||
160 |