Issues (319)

src/Command/UpdateTextAlikesCommand.php (1 issue)

Severity
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
The function Doctrine\ORM\Query::iterate() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

23
		$iterableResult = /** @scrutinizer ignore-deprecated */ $this->getEntityManager()->createQuery($dql)->iterate();
Loading history...
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