refs #1523. Hierarchy networkSettings
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
ce61d3cfc2
commit
4fd3a78c0a
|
@ -2,7 +2,87 @@
|
|||
|
||||
namespace App\EventSubscriber;
|
||||
|
||||
class OrganizationalUnitSubscriber
|
||||
{
|
||||
use ApiPlatform\Symfony\EventListener\EventPriorities;
|
||||
use App\Controller\OgBoot\PxeBootFile\PostAction;
|
||||
use App\Dto\Output\OrganizationalUnitOutput;
|
||||
use App\Entity\NetworkSettings;
|
||||
use App\Entity\OrganizationalUnit;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Event\ViewEvent;
|
||||
use Symfony\Component\HttpKernel\KernelEvents;
|
||||
|
||||
final readonly class OrganizationalUnitSubscriber implements EventSubscriberInterface
|
||||
{
|
||||
public function __construct(
|
||||
private EntityManagerInterface $entityManager,
|
||||
)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static function getSubscribedEvents(): array
|
||||
{
|
||||
return [
|
||||
KernelEvents::VIEW => ['updateNetworkSettings', EventPriorities::POST_WRITE],
|
||||
];
|
||||
}
|
||||
|
||||
public function updateNetworkSettings(ViewEvent $event): void
|
||||
{
|
||||
$organizationalUnitOutput = $event->getControllerResult();
|
||||
$method = $event->getRequest()->getMethod();
|
||||
|
||||
if (!$organizationalUnitOutput instanceof OrganizationalUnitOutput ||
|
||||
!in_array($method, [Request::METHOD_POST, Request::METHOD_PUT, Request::METHOD_PATCH])) {
|
||||
return;
|
||||
}
|
||||
|
||||
/** @var OrganizationalUnit $organizationalUnitEntity */
|
||||
$organizationalUnitEntity = $organizationalUnitOutput->getEntity();
|
||||
|
||||
if ($organizationalUnitEntity->getNetworkSettings() === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$newNetworkSettings = $this->buildNetworkSettings($organizationalUnitEntity);
|
||||
|
||||
$this->updateChildrenNetworkSettings($organizationalUnitEntity, $newNetworkSettings);
|
||||
|
||||
$this->entityManager->flush();
|
||||
}
|
||||
|
||||
|
||||
private function updateChildrenNetworkSettings(OrganizationalUnit $parentUnit, NetworkSettings $networkSettings): void
|
||||
{
|
||||
foreach ($parentUnit->getOrganizationalUnits() as $childUnit) {
|
||||
$childUnit->setNetworkSettings($networkSettings);
|
||||
$this->entityManager->persist($childUnit);
|
||||
|
||||
$this->updateChildrenNetworkSettings($childUnit, $networkSettings);
|
||||
}
|
||||
}
|
||||
|
||||
private function buildNetworkSettings($organizationalUnitEntity): NetworkSettings
|
||||
{
|
||||
$newNetworkSettings = new NetworkSettings();
|
||||
$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());
|
||||
|
||||
return $newNetworkSettings;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue