1 | <?php namespace App\Command; |
||
2 | |||
3 | use App\Service\TextService; |
||
4 | use Symfony\Component\Console\Input\InputInterface; |
||
5 | use Symfony\Component\Console\Output\OutputInterface; |
||
6 | |||
7 | class UpdateTextAlikesCommand extends Command { |
||
8 | |||
9 | public function getName() { |
||
10 | return 'db:update-text-alikes'; |
||
11 | } |
||
12 | |||
13 | public function getDescription() { |
||
14 | return 'Update similar texts (alikes) of texts'; |
||
15 | } |
||
16 | |||
17 | /** @inheritdoc */ |
||
18 | protected function execute(InputInterface $input, OutputInterface $output): int { |
||
19 | $textService = new TextService($this->olddb()); |
||
20 | $maxAlikesCount = 50; |
||
21 | $repo = $this->getEntityManager()->getTextRepository(); |
||
22 | $dql = 'SELECT t FROM App\Entity\Text t WHERE t.id < 10'; |
||
23 | $iterableResult = $this->getEntityManager()->createQuery($dql)->iterate(); |
||
0 ignored issues
–
show
Deprecated Code
introduced
by
![]() |
|||
24 | foreach ($iterableResult AS $row) { |
||
25 | $text = $row[0]; |
||
26 | $alikes = $textService->findTextAlikes($text, $maxAlikesCount); |
||
27 | if ($text->getAlikes() != $alikes) { |
||
28 | $text->setAlikes($alikes); |
||
29 | $repo->save($text); |
||
30 | $output->write('.'); |
||
31 | } |
||
32 | } |
||
33 | return self::SUCCESS; |
||
34 | } |
||
35 | } |
||
36 |