Task/Doctrine/DoctrineBatchWriterTask.php
protected function writeBatch(ProcessState $state): void
    {
        if (0 === \count($this->batch)) {
            $state->setSkipped(true);

            return;
        }

        // Support for multiple entity managers is overkill but might be necessary
        $entityManagers = new \SplObjectStorage();
        foreach ($this->batch as $entity) {
            $class = ClassUtils::getClass($entity);
            $entityManager = $this->doctrine->getManagerForClass($class);
            if (!$entityManager instanceof EntityManagerInterface) {
                throw new \UnexpectedValueException("No manager found for class {$class}");
            }
            $entityManager->persist($entity);
            $entityManagers->attach($entityManager);
        }

        foreach ($entityManagers as $entityManager) {
            $entityManager->flush();
        }

        $state->setOutput($this->batch);
        $this->batch = [];
    }
protected function writeBatch(ProcessState $state): void
    {
        if (0 === \count($this->batch)) {
            $state->setSkipped(true);

            return;
        }

        // Support for multiple entity managers is overkill but might be necessary
        $entityManagers = new \SplObjectStorage();
        foreach ($this->batch as $entity) {
            $class = ClassUtils::getClass($entity);
            $entityManager = $this->doctrine->getManagerForClass($class);
            if (!$entityManager instanceof EntityManagerInterface) {
                throw new \UnexpectedValueException("No manager found for class {$class}");
            }
            $entityManager->persist($entity);
            $entityManagers->attach($entityManager);
        }

        foreach ($entityManagers as $entityManager) {
            $entityManager->flush();
        }

        $state->setOutput($this->batch);
        $this->batch = [];
    }
@param ProcessState $state

@throws \UnexpectedValueException
@throws \Symfony\Component\OptionsResolver\Exception\ExceptionInterface
@throws \UnexpectedValueException