diff --git a/src/Command/UpdateAllUsersCronCommand.php b/src/Command/UpdateAllUsersCronCommand.php index a39e23d..a51e16b 100644 --- a/src/Command/UpdateAllUsersCronCommand.php +++ b/src/Command/UpdateAllUsersCronCommand.php @@ -31,45 +31,22 @@ class UpdateAllUsersCronCommand extends Command protected function execute(InputInterface $input, OutputInterface $output): int { - $io = new SymfonyStyle($input, $output); - $em = $this->entityManager; $repo = $em->getRepository(User::class); - $chunkSize = 100; - $count = $repo->count([]); + $repo->createQueryBuilder('u') + ->update() + ->set('u.log', 0) + ->where('u.log = 1') + ->getQuery() + ->execute(); - $io->progressStart($count); - for ($i = 0; $i < $count; $i += $chunkSize) { - $data = $repo->findBy([], null, $chunkSize, $i); - if ($data == []) { - break; - } - - /** @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(); + $repo->createQueryBuilder('u') + ->update() + ->set('u.log', 1) + ->where('u.score > 900 OR u.score < 100') + ->getQuery() + ->execute(); return Command::SUCCESS; }