61 lines
1.9 KiB
PHP
61 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Command;
|
|
|
|
use App\Entity\DeviceGroup;
|
|
use App\Entity\DeviceMaintenanceTask;
|
|
use App\Entity\Maintenance;
|
|
use App\Service\MaintenanceManagerService;
|
|
use Doctrine\ORM\EntityManager;
|
|
use Symfony\Component\Console\Command\Command;
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
class ConvertMaintenanceHashCommand extends Command
|
|
{
|
|
/** @var EntityManager */
|
|
private $entityManager;
|
|
|
|
/** @var MaintenanceManagerService */
|
|
private $maintenanceManager;
|
|
|
|
public function __construct(EntityManager $entityManager, MaintenanceManagerService $maintenanceManagerService)
|
|
{
|
|
$this->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();
|
|
}
|
|
}
|