• Doctrine detach?

    @usr58
    public function execute(InputInterface $input, OutputInterface $output): int
    {
            $counter = 0;
            $batchSize = 50;
            $existingDeviceSerialNumbers = ['1', ..........'10000'];
    
            for ($i = $startSerialNumber; $i <= $stopSerialNumber; $i++) {
                if (in_array((string)$i, $existingDeviceSerialNumbers, true)) {
                    continue;
                }
    
                $entityDto = new Entity(........);
                $this->entityManager->persist($entityDto);
    
                $counter++;
                $output->writeln(sprintf('count %d', $i));
    
                if (counter % $batchSize) === 0) {
                	$this->entityManager->flush();
                	$this->entityManager->clear();
                    gc_collect_cycles();
                }
            }
    
            $this->entityManager->flush();
    
            return Command::SUCCESS;
    }
    Написано