Compare commits

..

No commits in common. "ef9aee0368a670ce478c8b83c860f0c2df71ff08" and "d347896158e3cb935528900c3d2a6c4ae5a1a56d" have entirely different histories.

3 changed files with 12 additions and 32 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(str_replace(self::OG_BOOT_DIRECTORY, '', $details['directory'])));
$ogLive->setName($this->simplifyOgLiveFilenameService->__invoke($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,7 +3,6 @@
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;
@ -27,19 +26,10 @@ class DeleteAction extends AbstractOgBootController
*/
public function __invoke(PxeTemplate $data): JsonResponse
{
$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
);
}
$this->entityManager->remove($data);
$this->entityManager->flush();
return new JsonResponse(status: Response::HTTP_OK);
}

View File

@ -28,35 +28,25 @@ class SyncAction extends AbstractOgBootController
*/
public function __invoke(): JsonResponse
{
$content = $this->createRequest('GET', 'http://' . $this->ogBootApiUrl . '/ogboot/v1/pxe-templates');
$templateNamesFromApi = $content['message'];
$content = $this->createRequest('GET', 'http://'.$this->ogBootApiUrl . '/ogboot/v1/pxe-templates');
$existingTemplates = $this->entityManager->getRepository(PxeTemplate::class)->findAll();
foreach ($content['message'] as $template) {
$templateEntity = $this->entityManager->getRepository(PxeTemplate::class)->findOneBy(['name' => $template]);
$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) {
if ($templateEntity) {
$this->entityManager->persist($templateEntity);
} else {
$templateEntity = new PxeTemplate();
$templateEntity->setName($templateName);
$templateEntity->setName($template);
}
$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);