50 lines
1.7 KiB
PHP
50 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Service;
|
|
|
|
use App\Entity\Client;
|
|
use App\Entity\OperativeSystem;
|
|
use App\Entity\Partition;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
|
|
class CreatePartitionService
|
|
{
|
|
public function __construct(
|
|
protected EntityManagerInterface $entityManager
|
|
)
|
|
{
|
|
}
|
|
|
|
public function __invoke(array $data, Client $clientEntity): void
|
|
{
|
|
foreach ($data['cfg'] as $cfg) {
|
|
$partitionEntity = $this->entityManager->getRepository(Partition::class)
|
|
->findOneBy(['client' => $clientEntity, 'diskNumber' => $cfg['disk'], 'partitionNumber' => $cfg['par']]);
|
|
|
|
if (!$partitionEntity) {
|
|
$partitionEntity = new Partition();
|
|
}
|
|
|
|
if (isset($cfg['soi']) && $cfg['soi'] !== '') {
|
|
$operativeSystem = $this->entityManager->getRepository(OperativeSystem::class)
|
|
->findOneBy(['name' => $cfg['soi']]);
|
|
|
|
if (!$operativeSystem) {
|
|
$operativeSystem = new OperativeSystem();
|
|
$operativeSystem->setName($cfg['soi']);
|
|
$this->entityManager->persist($operativeSystem);
|
|
}
|
|
$partitionEntity->setOperativeSystem($operativeSystem);
|
|
}
|
|
|
|
$partitionEntity->setClient($clientEntity);
|
|
$partitionEntity->setDiskNumber($cfg['disk']);
|
|
$partitionEntity->setPartitionNumber($cfg['par']);
|
|
$partitionEntity->setSize($cfg['tam']);
|
|
$partitionEntity->setMemoryUsage(((int) $cfg['uso']) * 100);
|
|
$this->entityManager->persist($partitionEntity);
|
|
}
|
|
|
|
$this->entityManager->flush();
|
|
}
|
|
} |