refs #2939. Propagate network settings
testing/ogcore-api/pipeline/head There was a failure building this commit
Details
testing/ogcore-api/pipeline/head There was a failure building this commit
Details
parent
2d11a84141
commit
beb0b946d2
|
|
@ -33,6 +33,12 @@ resources:
|
|||
input: false
|
||||
uriTemplate: /organizational-units/{uuid}/change-parent
|
||||
controller: App\Controller\OrganizationalUnitChangeParentAction
|
||||
propagate_network_settings:
|
||||
class: ApiPlatform\Metadata\Post
|
||||
method: POST
|
||||
input: false
|
||||
uriTemplate: /organizational-units/{uuid}/propagate-network-settings
|
||||
controller: App\Controller\PropagateNetworkSettingsAction
|
||||
|
||||
properties:
|
||||
App\Entity\OrganizationalUnit:
|
||||
|
|
|
|||
|
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\OrganizationalUnit;
|
||||
use App\Repository\OrganizationalUnitRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
class PropagateNetworkSettingsAction extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly OrganizationalUnitRepository $organizationalUnitRepository,
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(OrganizationalUnit $organizationalUnit): JsonResponse
|
||||
{
|
||||
$networkSettings = $organizationalUnit->getNetworkSettings();
|
||||
|
||||
if (!$networkSettings) {
|
||||
return new JsonResponse(
|
||||
data: 'No network settings found for this organizational unit',
|
||||
status: Response::HTTP_UNPROCESSABLE_ENTITY
|
||||
);
|
||||
}
|
||||
|
||||
foreach ($organizationalUnit->getOrganizationalUnits() as $childUnit) {
|
||||
if (!$childUnit->isExcludeParentChanges()) {
|
||||
$childUnit->updateNetworkSettingsRecursively($networkSettings);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($organizationalUnit->getClients() as $client) {
|
||||
$client->setMenu($networkSettings->getMenu());
|
||||
$client->setHardwareProfile($networkSettings->getHardwareProfile());
|
||||
$client->setOgLive($networkSettings->getOgLive());
|
||||
$client->setRepository($networkSettings->getRepository());
|
||||
$client->setTemplate($networkSettings->getPxeTemplate());
|
||||
}
|
||||
|
||||
$this->entityManager->flush();
|
||||
|
||||
return new JsonResponse(
|
||||
data: 'Network settings propagated successfully',
|
||||
status: Response::HTTP_OK
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -341,10 +341,15 @@ class OrganizationalUnit extends AbstractEntity
|
|||
foreach ($this->getClients() as $client) {
|
||||
$client->setMenu($networkSettings->getMenu());
|
||||
$client->setHardwareProfile($networkSettings->getHardwareProfile());
|
||||
$client->setOgLive($networkSettings->getOgLive());
|
||||
$client->setRepository($networkSettings->getRepository());
|
||||
$client->setTemplate($networkSettings->getPxeTemplate());
|
||||
}
|
||||
|
||||
foreach ($this->getOrganizationalUnits() as $childUnit) {
|
||||
$childUnit->updateNetworkSettingsRecursively($networkSettings);
|
||||
if (!$childUnit->isExcludeParentChanges()) {
|
||||
$childUnit->updateNetworkSettingsRecursively($networkSettings);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ use ApiPlatform\Symfony\EventListener\EventPriorities;
|
|||
use App\Controller\OgBoot\PxeBootFile\PostAction;
|
||||
use App\Dto\Output\OrganizationalUnitOutput;
|
||||
use App\Entity\Client;
|
||||
use App\Entity\NetworkSettings;
|
||||
use App\Entity\OrganizationalUnit;
|
||||
use App\Model\OrganizationalUnitTypes;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
|
@ -55,99 +54,12 @@ final readonly class OrganizationalUnitSubscriber implements EventSubscriberInte
|
|||
/** @var OrganizationalUnit $organizationalUnitEntity */
|
||||
$organizationalUnitEntity = $organizationalUnitOutput->getEntity();
|
||||
|
||||
if ($organizationalUnitEntity->getNetworkSettings() === null || $organizationalUnitEntity->isExcludeParentChanges()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$newNetworkSettings = $this->cloneNetworkSettings($organizationalUnitEntity->getNetworkSettings());
|
||||
|
||||
$this->updateChildrenNetworkSettings($organizationalUnitEntity, $newNetworkSettings);
|
||||
|
||||
if ($organizationalUnitEntity->getType() === OrganizationalUnitTypes::CLASSROOM) {
|
||||
$this->syncOgBoot($organizationalUnitEntity);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function updateChildrenNetworkSettings(OrganizationalUnit $parentUnit, NetworkSettings $networkSettings): void
|
||||
{
|
||||
/** @var OrganizationalUnit $childUnit */
|
||||
foreach ($parentUnit->getOrganizationalUnits() as $childUnit) {
|
||||
if ($childUnit->isExcludeParentChanges()) {
|
||||
$childUnit->setNetworkSettings(null);
|
||||
} else{
|
||||
|
||||
$childUnit->setNetworkSettings($networkSettings);
|
||||
|
||||
foreach ($childUnit->getClients() as $client) {
|
||||
$client->setOgLive($networkSettings->getOgLive());
|
||||
$client->setMenu($networkSettings->getMenu());
|
||||
$client->setRepository($networkSettings->getRepository());
|
||||
$client->setTemplate($networkSettings->getPxeTemplate());
|
||||
$this->entityManager->persist($client);
|
||||
}
|
||||
}
|
||||
$this->entityManager->persist($childUnit);
|
||||
$this->entityManager->flush();
|
||||
|
||||
$this->updateChildrenNetworkSettings($childUnit, $networkSettings);
|
||||
}
|
||||
}
|
||||
|
||||
private function cloneNetworkSettings(NetworkSettings $original): NetworkSettings
|
||||
{
|
||||
$cloned = new NetworkSettings();
|
||||
|
||||
$cloned->setNextServer($original->getNextServer());
|
||||
$cloned->setBootFileName($original->getBootFileName());
|
||||
$cloned->setProxy($original->getProxy());
|
||||
$cloned->setDns($original->getDns());
|
||||
$cloned->setNetmask($original->getNetmask());
|
||||
$cloned->setRouter($original->getRouter());
|
||||
$cloned->setP2pTime($original->getP2pTime());
|
||||
$cloned->setP2pMode($original->getP2pMode());
|
||||
$cloned->setMcastMode($original->getMcastMode());
|
||||
$cloned->setMcastIp($original->getMcastIp());
|
||||
$cloned->setMcastPort($original->getMcastPort());
|
||||
$cloned->setMcastSpeed($original->getMcastSpeed());
|
||||
$cloned->setMenu($original->getMenu());
|
||||
$cloned->setRepository($original->getRepository());
|
||||
$cloned->setOgLive($original->getOgLive());
|
||||
$cloned->setPxeTemplate($original->getPxeTemplate());
|
||||
$cloned->setNetiface($original->getNetiface());
|
||||
|
||||
return $cloned;
|
||||
}
|
||||
|
||||
private function buildNetworkSettings($organizationalUnitEntity): NetworkSettings
|
||||
{
|
||||
if ($organizationalUnitEntity->getNetworkSettings() === null) {
|
||||
$newNetworkSettings = new NetworkSettings();
|
||||
} else {
|
||||
$newNetworkSettings = $organizationalUnitEntity->getNetworkSettings();
|
||||
}
|
||||
|
||||
$newNetworkSettings->setNextServer($organizationalUnitEntity->getNetworkSettings()->getNextServer());
|
||||
$newNetworkSettings->setBootFileName($organizationalUnitEntity->getNetworkSettings()->getBootFileName());
|
||||
$newNetworkSettings->setProxy($organizationalUnitEntity->getNetworkSettings()->getProxy());
|
||||
$newNetworkSettings->setDns($organizationalUnitEntity->getNetworkSettings()->getDns());
|
||||
$newNetworkSettings->setNetmask($organizationalUnitEntity->getNetworkSettings()->getNetmask());
|
||||
$newNetworkSettings->setRouter($organizationalUnitEntity->getNetworkSettings()->getRouter());
|
||||
$newNetworkSettings->setP2pTime($organizationalUnitEntity->getNetworkSettings()->getP2pTime());
|
||||
$newNetworkSettings->setP2pMode($organizationalUnitEntity->getNetworkSettings()->getP2pMode());
|
||||
$newNetworkSettings->setMcastMode($organizationalUnitEntity->getNetworkSettings()->getMcastMode());
|
||||
$newNetworkSettings->setMcastIp($organizationalUnitEntity->getNetworkSettings()->getMcastIp());
|
||||
$newNetworkSettings->setMcastPort($organizationalUnitEntity->getNetworkSettings()->getMcastPort());
|
||||
$newNetworkSettings->setMcastSpeed($organizationalUnitEntity->getNetworkSettings()->getMcastSpeed());
|
||||
$newNetworkSettings->setMenu($organizationalUnitEntity->getNetworkSettings()->getMenu());
|
||||
$newNetworkSettings->setRepository($organizationalUnitEntity->getNetworkSettings()->getRepository());
|
||||
$newNetworkSettings->setOgLive($organizationalUnitEntity->getNetworkSettings()->getOgLive());
|
||||
$newNetworkSettings->setPxeTemplate($organizationalUnitEntity->getNetworkSettings()->getPxeTemplate());
|
||||
$newNetworkSettings->setNetiface($organizationalUnitEntity->getNetworkSettings()->getNetiface());
|
||||
|
||||
return $newNetworkSettings;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws TransportExceptionInterface
|
||||
* @throws ServerExceptionInterface
|
||||
|
|
|
|||
Loading…
Reference in New Issue