fix: rewrite app:update-all-users-cron
This commit is contained in:
parent
1a3a306db5
commit
5e3851a6ca
|
@ -31,45 +31,22 @@ class UpdateAllUsersCronCommand extends Command
|
||||||
|
|
||||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||||
{
|
{
|
||||||
$io = new SymfonyStyle($input, $output);
|
|
||||||
|
|
||||||
$em = $this->entityManager;
|
$em = $this->entityManager;
|
||||||
$repo = $em->getRepository(User::class);
|
$repo = $em->getRepository(User::class);
|
||||||
|
|
||||||
$chunkSize = 100;
|
$repo->createQueryBuilder('u')
|
||||||
$count = $repo->count([]);
|
->update()
|
||||||
|
->set('u.log', 0)
|
||||||
|
->where('u.log = 1')
|
||||||
|
->getQuery()
|
||||||
|
->execute();
|
||||||
|
|
||||||
$io->progressStart($count);
|
$repo->createQueryBuilder('u')
|
||||||
for ($i = 0; $i < $count; $i += $chunkSize) {
|
->update()
|
||||||
$data = $repo->findBy([], null, $chunkSize, $i);
|
->set('u.log', 1)
|
||||||
if ($data == []) {
|
->where('u.score > 900 OR u.score < 100')
|
||||||
break;
|
->getQuery()
|
||||||
}
|
->execute();
|
||||||
|
|
||||||
/** @var User */
|
|
||||||
foreach ($data as $user) {
|
|
||||||
$score = (int) $user->getScore();
|
|
||||||
if ($score < 100 || $score > 900) {
|
|
||||||
$user->setLog(true);
|
|
||||||
|
|
||||||
$log = new UserLog();
|
|
||||||
$log->setScore($user->getScore());
|
|
||||||
$log->setUserId($user->getId());
|
|
||||||
|
|
||||||
$em->persist($user);
|
|
||||||
$em->persist($log);
|
|
||||||
} else if ($user->getLog()) {
|
|
||||||
$user->setLog(false);
|
|
||||||
$em->persist($user);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$io->progressAdvance($chunkSize);
|
|
||||||
|
|
||||||
$em->flush();
|
|
||||||
$em->clear();
|
|
||||||
}
|
|
||||||
$io->progressFinish();
|
|
||||||
|
|
||||||
return Command::SUCCESS;
|
return Command::SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue