ogcore/src/Command/LoadOrganizationalUnitDefau...

173 lines
5.5 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Command;
use App\Entity\Client;
use App\Entity\Image;
use App\Entity\OrganizationalUnit;
use App\Model\OrganizationalUnitTypes;
use App\Model\UserGroupPermissions;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class LoadOrganizationalUnitDefaultCommand extends Command
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
)
{
parent::__construct('app:load-default-ous');
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$organizationalUnits = [
[
'name' => 'Universidad Test',
'type' => OrganizationalUnitTypes::ORGANIZATIONAL_UNIT
]
];
$classrooms = [
[
'name' => 'Aula Test 1',
'type' => OrganizationalUnitTypes::CLASSROOM
],
[
'name' => 'Aula Test 2',
'type' => OrganizationalUnitTypes::CLASSROOM
],
[
'name' => 'Aula Test 3',
'type' => OrganizationalUnitTypes::CLASSROOM
]
];
$clientsA = [
[
'name' => 'Cliente Test 1a',
'ip' => '1.1.1.1',
'mac' => '00:1A:2B:3C:4D:5E',
],
[
'name' => 'Cliente Test 1b',
'ip' => '2.2.2.2',
'mac' => '00:1B:3C:4D:5E:6F'
],
[
'name' => 'Cliente Test 1c',
'ip' => '3.3.3.3',
'mac' => '00:1C:4D:5E:6F:7A'
]
];
$clientsB = [
[
'name' => 'Cliente Test 2a',
'ip' => '4.4.4.4',
'mac' => '00:1D:5E:6F:7A:8B'
],
[
'name' => 'Cliente Test 2b',
'ip' => '5.5.5.5',
'mac' => '00:1E:6F:7A:8B:9C'
],
[
'name' => 'Cliente Test 2c',
'ip' => '6.6.6.6',
'mac' => '00:1F:7A:8B:9C:AD'
],
];
$clientsC = [
[
'name' => 'Cliente Test 3a',
'ip' => '7.7.7.7.',
'mac' => '00:2A:8B:9C:AD:BE'
],
[
'name' => 'Cliente Test 3b',
'ip' => '8.8.8.8',
'mac' => '00:2B:9C:AD:BE:CF'
],
[
'name' => 'Cliente Test 3c',
'ip' => '9.9.9.9',
'mac' => '00:2C:AD:BE:CF:D0'
]
];
$images = [
[
'name' => 'Imagen Test 1',
'type' => 'ISO',
'path' => '/path/to/imagen1.iso'
],
[
'name' => 'Imagen Test 2',
'type' => 'ISO',
'path' => '/path/to/imagen2.iso'
],
[
'name' => 'Imagen Test 3',
'type' => 'ISO',
'path' => '/path/to/imagen3.iso'
]
];
foreach ($organizationalUnits as $organizationalUnit) {
$organizationalUnitEntity = new OrganizationalUnit();
$organizationalUnitEntity->setName($organizationalUnit['name']);
$organizationalUnitEntity->setType($organizationalUnit['type']);
$this->entityManager->persist($organizationalUnitEntity);
foreach ($classrooms as $classroom) {
$classroomEntity = new OrganizationalUnit();
$classroomEntity->setName($classroom['name']);
$classroomEntity->setType($classroom['type']);
$classroomEntity->setParent($organizationalUnitEntity);
$this->entityManager->persist($classroomEntity);
if ($classroomEntity->getName() === 'Aula Test 1') {
$clients = $clientsA;
} elseif ($classroomEntity->getName() === 'Aula Test 2') {
$clients = $clientsB;
} elseif ($classroomEntity->getName() === 'Aula Test 3') {
$clients = $clientsC;
}
foreach ($clients as $client) {
$clientEntity = new Client();
$clientEntity->setName($client['name']);
$clientEntity->setIp($client['ip']);
$clientEntity->setMac($client['mac']);
$clientEntity->setMaintenance(false);
$clientEntity->setOrganizationalUnit($classroomEntity);
$this->entityManager->persist($clientEntity);
foreach ($images as $image) {
$imageEntity = new Image();
$imageEntity->setName($image['name']);
$imageEntity->setType($image['type']);
$imageEntity->setPath($image['path']);
$imageEntity->setOrganizationalUnit($organizationalUnitEntity);
$imageEntity->setClient($clientEntity);
$this->entityManager->persist($imageEntity);
}
}
}
$this->entityManager->flush();
}
return Command::SUCCESS;
}
}