55 lines
1.9 KiB
PHP
55 lines
1.9 KiB
PHP
<?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->setRepository($networkSettings->getRepository());
|
|
$client->setBootServer($networkSettings->getBootServer());
|
|
$client->setOgLive($networkSettings->getOgLive());
|
|
$client->setTemplate($networkSettings->getPxeTemplate());
|
|
}
|
|
|
|
$this->entityManager->flush();
|
|
|
|
return new JsonResponse(
|
|
data: 'Network settings propagated successfully',
|
|
status: Response::HTTP_OK
|
|
);
|
|
}
|
|
}
|