Compare commits

..

2 Commits

Author SHA1 Message Date
Manuel Aranda Rosales ef9aee0368 refs #1967. Sync ogBoot API when put template
testing/ogcore-api/pipeline/head This commit looks good Details
2025-05-07 17:07:48 +02:00
Manuel Aranda Rosales 927e38102e refs #1967. Sync ogBoot API when put template 2025-05-07 17:02:57 +02:00
3 changed files with 32 additions and 12 deletions

View File

@ -30,7 +30,7 @@ class InstallOgLiveResponseAction extends AbstractController
{
public CONST string OG_LIVE_INSTALL_SUCCESS = 'success';
public CONST string OG_LIVE_INSTALL_FAILED = 'failure';
const string OG_BOOT_DIRECTORY = '/opt/opengnsys/ogboot/tftpboot//';
const string OG_BOOT_DIRECTORY = '/opt/opengnsys/ogboot/tftpboot/';
public function __construct(
protected readonly EntityManagerInterface $entityManager,
@ -94,7 +94,7 @@ class InstallOgLiveResponseAction extends AbstractController
private function updateOgLive (OgLive $ogLive, mixed $details, string $status): void
{
if ( is_array($details) && $status === self::OG_LIVE_INSTALL_SUCCESS) {
$ogLive->setName($this->simplifyOgLiveFilenameService->__invoke($details['directory']));
$ogLive->setName($this->simplifyOgLiveFilenameService->__invoke(str_replace(self::OG_BOOT_DIRECTORY, '', $details['directory'])));
$ogLive->setDate(new \DateTime($this->extractOgLiveFilenameDateService->__invoke($details['directory'])));
$ogLive->setFilename(str_replace(self::OG_BOOT_DIRECTORY, '', $details['directory']));
$ogLive->setInstalled(true);

View File

@ -3,6 +3,7 @@
namespace App\Controller\OgBoot\PxeTemplate;
use App\Controller\OgBoot\AbstractOgBootController;
use App\Entity\Client;
use App\Entity\PxeTemplate;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
@ -26,11 +27,20 @@ class DeleteAction extends AbstractOgBootController
*/
public function __invoke(PxeTemplate $data): JsonResponse
{
$content = $this->createRequest('DELETE', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/pxe-templates/'.$data->getName());
$this->entityManager->remove($data);
$this->entityManager->flush();
$content = $this->createRequest('DELETE', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/pxe-templates/'.$data->getName());
$defaultTemplateEntity = $this->entityManager->getRepository(PxeTemplate::class)->findOneBy(['isDefault' => true]);
if ($defaultTemplateEntity === null) {
return new JsonResponse(
'Default template not found',
Response::HTTP_NOT_FOUND
);
}
return new JsonResponse(status: Response::HTTP_OK);
}
}

View File

@ -28,25 +28,35 @@ class SyncAction extends AbstractOgBootController
*/
public function __invoke(): JsonResponse
{
$content = $this->createRequest('GET', 'http://'.$this->ogBootApiUrl . '/ogboot/v1/pxe-templates');
$content = $this->createRequest('GET', 'http://' . $this->ogBootApiUrl . '/ogboot/v1/pxe-templates');
$templateNamesFromApi = $content['message'];
foreach ($content['message'] as $template) {
$templateEntity = $this->entityManager->getRepository(PxeTemplate::class)->findOneBy(['name' => $template]);
$existingTemplates = $this->entityManager->getRepository(PxeTemplate::class)->findAll();
if ($templateEntity) {
$this->entityManager->persist($templateEntity);
} else {
$existingTemplateNames = array_map(fn($t) => $t->getName(), $existingTemplates);
foreach ($existingTemplates as $existingTemplate) {
if (!in_array($existingTemplate->getName(), $templateNamesFromApi, true)) {
$this->entityManager->remove($existingTemplate);
}
}
foreach ($templateNamesFromApi as $templateName) {
$templateEntity = $this->entityManager->getRepository(PxeTemplate::class)->findOneBy(['name' => $templateName]);
if (!$templateEntity) {
$templateEntity = new PxeTemplate();
$templateEntity->setName($template);
$templateEntity->setName($templateName);
}
$templateContent = $this->createRequest('GET', 'http://'.$this->ogBootApiUrl . '/ogboot/v1/pxe-templates/'.$templateEntity->getName());
$templateContent = $this->createRequest('GET', 'http://' . $this->ogBootApiUrl . '/ogboot/v1/pxe-templates/' . $templateEntity->getName());
$templateEntity->setTemplateContent($templateContent['template_content']);
$templateEntity->setSynchronized(true);
$this->entityManager->persist($templateEntity);
}
$this->entityManager->flush();
return new JsonResponse(data: $content, status: Response::HTTP_OK);