Added default command loader OUs
testing/ogcore-api/pipeline/head There was a failure building this commit Details

develop-jenkins
Manuel Aranda Rosales 2024-10-08 17:00:12 +02:00
parent 1e2947b183
commit d3c43f4f81
1 changed files with 144 additions and 0 deletions

View File

@ -0,0 +1,144 @@
<?php
declare(strict_types=1);
namespace App\Command;
use App\Entity\Client;
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'
]
];
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);
}
}
$this->entityManager->flush();
}
return Command::SUCCESS;
}
}