53 lines
2.0 KiB
PHP
53 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Controller\OgBoot\PxeTemplate;
|
|
|
|
use App\Controller\OgBoot\AbstractOgBootController;
|
|
use App\Entity\OgLive;
|
|
use App\Entity\PxeTemplate;
|
|
use App\Model\OgLiveStatus;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\HttpKernel\Attribute\AsController;
|
|
use Symfony\Component\Validator\Exception\ValidatorException;
|
|
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
|
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
|
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
|
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
|
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
|
|
|
#[AsController]
|
|
class SyncAction extends AbstractOgBootController
|
|
{
|
|
/**
|
|
* @throws TransportExceptionInterface
|
|
* @throws ServerExceptionInterface
|
|
* @throws RedirectionExceptionInterface
|
|
* @throws ClientExceptionInterface
|
|
*/
|
|
public function __invoke(): JsonResponse
|
|
{
|
|
$content = $this->createRequest('GET', 'http://'.$this->ogBootApiUrl . '/ogboot/v1/pxe-templates');
|
|
|
|
foreach ($content['message'] as $template) {
|
|
$templateEntity = $this->entityManager->getRepository(PxeTemplate::class)->findOneBy(['name' => $template]);
|
|
|
|
if ($templateEntity) {
|
|
$this->entityManager->persist($templateEntity);
|
|
} else {
|
|
$templateEntity = new PxeTemplate();
|
|
$templateEntity->setName($template);
|
|
}
|
|
|
|
$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);
|
|
}
|
|
} |