entityManager = $entityManager; $this->maintenanceManager = $maintenanceManagerService; parent::__construct(); } protected function configure() { $this->setName('convert:hash') ->setDescription('convert v1 hash to v2'); } /** * @param InputInterface $input * @param OutputInterface $output * @return int|null|void * @throws \Doctrine\ORM\OptimisticLockException */ protected function execute(InputInterface $input, OutputInterface $output) { /** @var DeviceGroup[] $maintGroups */ $maintGroups = $this->maintenanceManager->getMaintenanceList(); foreach ($maintGroups as $maintGroup) { foreach ($maintGroup->getDevices() as $device) { foreach ($device->getTasks() as $task) { if(null !== ($entity = $this->entityManager->getRepository(Maintenance::class)->findOneBy([ 'oldHash' => $task->getLegacyHash(), ]))) { /** @var Maintenance $entity */ $entity->setHash($task->getHash()); } } } } $this->entityManager->flush(); } }