refs #658. Refactor endpoints
parent
750e36ec99
commit
6afce69f14
|
@ -90,7 +90,6 @@ resources:
|
||||||
class: ApiPlatform\Metadata\Post
|
class: ApiPlatform\Metadata\Post
|
||||||
method: POST
|
method: POST
|
||||||
input: false
|
input: false
|
||||||
output: false
|
|
||||||
uriTemplate: /og-lives/server/{uuid}/uninstall
|
uriTemplate: /og-lives/server/{uuid}/uninstall
|
||||||
controller: App\Controller\OgBoot\OgLive\UninstallAction
|
controller: App\Controller\OgBoot\OgLive\UninstallAction
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Controller\OgBoot;
|
||||||
|
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\HttpKernel\Attribute\AsController;
|
||||||
|
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||||
|
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]
|
||||||
|
abstract class AbstractOgBootController extends AbstractController
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
protected readonly string $ogBootApiUrl,
|
||||||
|
protected readonly EntityManagerInterface $entityManager
|
||||||
|
)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws TransportExceptionInterface
|
||||||
|
* @throws ServerExceptionInterface
|
||||||
|
* @throws RedirectionExceptionInterface
|
||||||
|
* @throws ClientExceptionInterface
|
||||||
|
*/
|
||||||
|
public function createRequest (HttpClientInterface $httpClient, string $method, string $url, array $params = []): JsonResponse|array
|
||||||
|
{
|
||||||
|
$params = array_merge($params, [
|
||||||
|
'headers' => [
|
||||||
|
'accept' => 'application/json',
|
||||||
|
'Content-Type' => 'application/json'
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$response = $httpClient->request($method, $url, $params);
|
||||||
|
|
||||||
|
return json_decode($response->getContent(), true);
|
||||||
|
} catch (ClientExceptionInterface | ServerExceptionInterface $e) {
|
||||||
|
$response = $e->getResponse();
|
||||||
|
$content = json_decode($response->getContent(false), true);
|
||||||
|
throw new HttpException($response->getStatusCode(), $content['error'] ?? 'An error occurred');
|
||||||
|
} catch (TransportExceptionInterface $e) {
|
||||||
|
throw new HttpException(Response::HTTP_INTERNAL_SERVER_ERROR, $e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,20 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Controller\OgBoot;
|
|
||||||
|
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
||||||
use Symfony\Component\HttpKernel\Attribute\AsController;
|
|
||||||
|
|
||||||
#[AsController]
|
|
||||||
abstract class AbstractOgLiveController extends AbstractController
|
|
||||||
{
|
|
||||||
public function __construct(
|
|
||||||
protected readonly string $ogBootApiUrl,
|
|
||||||
protected readonly EntityManagerInterface $entityManager
|
|
||||||
)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -2,11 +2,12 @@
|
||||||
|
|
||||||
namespace App\Controller\OgBoot\OgLive;
|
namespace App\Controller\OgBoot\OgLive;
|
||||||
|
|
||||||
use App\Controller\OgBoot\AbstractOgLiveController;
|
use App\Controller\OgBoot\AbstractOgBootController;
|
||||||
use App\Entity\OgLive;
|
use App\Entity\OgLive;
|
||||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\HttpKernel\Attribute\AsController;
|
use Symfony\Component\HttpKernel\Attribute\AsController;
|
||||||
|
use Symfony\Component\Validator\Exception\ValidatorException;
|
||||||
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
||||||
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
||||||
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
||||||
|
@ -14,7 +15,7 @@ use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||||
|
|
||||||
#[AsController]
|
#[AsController]
|
||||||
class GetAction extends AbstractOgLiveController
|
class GetAction extends AbstractOgBootController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @throws TransportExceptionInterface
|
* @throws TransportExceptionInterface
|
||||||
|
@ -24,18 +25,12 @@ class GetAction extends AbstractOgLiveController
|
||||||
*/
|
*/
|
||||||
public function __invoke(OgLive $data, HttpClientInterface $httpClient): JsonResponse
|
public function __invoke(OgLive $data, HttpClientInterface $httpClient): JsonResponse
|
||||||
{
|
{
|
||||||
try {
|
if (!$data->getChecksum()) {
|
||||||
$response = $httpClient->request('GET', $this->ogBootApiUrl.'/ogboot/v1/oglives/'.$data->getChecksum(), [
|
throw new ValidatorException('Checksum is required');
|
||||||
'headers' => [
|
|
||||||
'accept' => 'application/json',
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
} catch (TransportExceptionInterface $e) {
|
|
||||||
return new JsonResponse( data: 'An error occurred', status: Response::HTTP_INTERNAL_SERVER_ERROR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = json_decode($response->getContent(), true);
|
$content = $this->createRequest($httpClient, 'GET', $this->ogBootApiUrl.'/ogboot/v1/oglives/'.$data->getChecksum());
|
||||||
|
|
||||||
return new JsonResponse( data: $data, status: Response::HTTP_OK);
|
return new JsonResponse(data: $content, status: Response::HTTP_OK);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,10 +2,11 @@
|
||||||
|
|
||||||
namespace App\Controller\OgBoot\OgLive;
|
namespace App\Controller\OgBoot\OgLive;
|
||||||
|
|
||||||
use App\Controller\OgBoot\AbstractOgLiveController;
|
use App\Controller\OgBoot\AbstractOgBootController;
|
||||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\HttpKernel\Attribute\AsController;
|
use Symfony\Component\HttpKernel\Attribute\AsController;
|
||||||
|
use Symfony\Component\Validator\Exception\ValidatorException;
|
||||||
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
||||||
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
||||||
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
||||||
|
@ -13,7 +14,7 @@ use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||||
|
|
||||||
#[AsController]
|
#[AsController]
|
||||||
class GetCollectionAction extends AbstractOgLiveController
|
class GetCollectionAction extends AbstractOgBootController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @throws TransportExceptionInterface
|
* @throws TransportExceptionInterface
|
||||||
|
@ -23,18 +24,8 @@ class GetCollectionAction extends AbstractOgLiveController
|
||||||
*/
|
*/
|
||||||
public function __invoke(HttpClientInterface $httpClient): JsonResponse
|
public function __invoke(HttpClientInterface $httpClient): JsonResponse
|
||||||
{
|
{
|
||||||
try {
|
$content = $this->createRequest($httpClient, 'GET', $this->ogBootApiUrl.'/ogboot/v1/oglives');
|
||||||
$response = $httpClient->request('GET', $this->ogBootApiUrl.'/ogboot/v1/oglives', [
|
|
||||||
'headers' => [
|
|
||||||
'accept' => 'application/json',
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
} catch (TransportExceptionInterface $e) {
|
|
||||||
return new JsonResponse( data: 'An error occurred', status: Response::HTTP_INTERNAL_SERVER_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
$data = json_decode($response->getContent(), true);
|
return new JsonResponse(data: $content, status: Response::HTTP_OK);
|
||||||
|
|
||||||
return new JsonResponse( data: $data, status: Response::HTTP_OK);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace App\Controller\OgBoot\OgLive;
|
namespace App\Controller\OgBoot\OgLive;
|
||||||
|
|
||||||
use App\Controller\OgBoot\AbstractOgLiveController;
|
use App\Controller\OgBoot\AbstractOgBootController;
|
||||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\HttpKernel\Attribute\AsController;
|
use Symfony\Component\HttpKernel\Attribute\AsController;
|
||||||
|
@ -13,7 +13,7 @@ use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||||
|
|
||||||
#[AsController]
|
#[AsController]
|
||||||
class GetDefaultAction extends AbstractOgLiveController
|
class GetDefaultAction extends AbstractOgBootController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @throws TransportExceptionInterface
|
* @throws TransportExceptionInterface
|
||||||
|
@ -23,18 +23,8 @@ class GetDefaultAction extends AbstractOgLiveController
|
||||||
*/
|
*/
|
||||||
public function __invoke(HttpClientInterface $httpClient): JsonResponse
|
public function __invoke(HttpClientInterface $httpClient): JsonResponse
|
||||||
{
|
{
|
||||||
try {
|
$content = $this->createRequest($httpClient, 'GET', $this->ogBootApiUrl.'/ogboot/v1/oglives/default');
|
||||||
$response = $httpClient->request('GET', $this->ogBootApiUrl.'/ogboot/v1/oglives/default', [
|
|
||||||
'headers' => [
|
|
||||||
'accept' => 'application/json',
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
} catch (TransportExceptionInterface $e) {
|
|
||||||
return new JsonResponse( data: 'An error occurred', status: Response::HTTP_INTERNAL_SERVER_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
$data = json_decode($response->getContent(), true);
|
return new JsonResponse(status: Response::HTTP_OK);
|
||||||
|
|
||||||
return new JsonResponse( data: $data, status: Response::HTTP_OK);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace App\Controller\OgBoot\OgLive;
|
namespace App\Controller\OgBoot\OgLive;
|
||||||
|
|
||||||
use App\Controller\OgBoot\AbstractOgLiveController;
|
use App\Controller\OgBoot\AbstractOgBootController;
|
||||||
use App\Entity\OgLive;
|
use App\Entity\OgLive;
|
||||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
@ -14,7 +14,7 @@ use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||||
|
|
||||||
#[AsController]
|
#[AsController]
|
||||||
class GetIsosAction extends AbstractOgLiveController
|
class GetIsosAction extends AbstractOgBootController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @throws TransportExceptionInterface
|
* @throws TransportExceptionInterface
|
||||||
|
@ -24,20 +24,8 @@ class GetIsosAction extends AbstractOgLiveController
|
||||||
*/
|
*/
|
||||||
public function __invoke(HttpClientInterface $httpClient): JsonResponse
|
public function __invoke(HttpClientInterface $httpClient): JsonResponse
|
||||||
{
|
{
|
||||||
$ogLivesInserted = 0;
|
$content = $this->createRequest($httpClient, 'GET', $this->ogBootApiUrl.'/ogboot/v1/oglives/isos');
|
||||||
|
|
||||||
try {
|
return new JsonResponse(data: $content, status: Response::HTTP_OK);
|
||||||
$response = $httpClient->request('GET', $this->ogBootApiUrl.'/ogboot/v1/oglives/isos', [
|
|
||||||
'headers' => [
|
|
||||||
'accept' => 'application/json',
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
} catch (TransportExceptionInterface $e) {
|
|
||||||
return new JsonResponse( data: 'An error occurred', status: Response::HTTP_INTERNAL_SERVER_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
$data = json_decode($response->getContent(), true);
|
|
||||||
|
|
||||||
return new JsonResponse( data: [ 'data' => $data, 'ogLivesInserted' => $ogLivesInserted], status: Response::HTTP_OK);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,12 +2,13 @@
|
||||||
|
|
||||||
namespace App\Controller\OgBoot\OgLive;
|
namespace App\Controller\OgBoot\OgLive;
|
||||||
|
|
||||||
use App\Controller\OgBoot\AbstractOgLiveController;
|
use App\Controller\OgBoot\AbstractOgBootController;
|
||||||
use App\Entity\OgLive;
|
use App\Entity\OgLive;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\HttpKernel\Attribute\AsController;
|
use Symfony\Component\HttpKernel\Attribute\AsController;
|
||||||
|
use Symfony\Component\Validator\Exception\ValidatorException;
|
||||||
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
||||||
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
||||||
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
||||||
|
@ -15,7 +16,7 @@ use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||||
|
|
||||||
#[AsController]
|
#[AsController]
|
||||||
class InstallAction extends AbstractOgLiveController
|
class InstallAction extends AbstractOgBootController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @throws TransportExceptionInterface
|
* @throws TransportExceptionInterface
|
||||||
|
@ -25,28 +26,22 @@ class InstallAction extends AbstractOgLiveController
|
||||||
*/
|
*/
|
||||||
public function __invoke(OgLive $data, HttpClientInterface $httpClient, EntityManagerInterface $entityManager): JsonResponse
|
public function __invoke(OgLive $data, HttpClientInterface $httpClient, EntityManagerInterface $entityManager): JsonResponse
|
||||||
{
|
{
|
||||||
try {
|
if (!$data->getDownloadUrl()) {
|
||||||
$response = $httpClient->request('POST', $this->ogBootApiUrl.'/ogboot/v1/oglives/install', [
|
throw new ValidatorException('Download URL is required');
|
||||||
'headers' => [
|
}
|
||||||
'accept' => 'application/json',
|
|
||||||
'Content-Type' => 'application/json',
|
$params = [
|
||||||
],
|
|
||||||
'json' => [
|
'json' => [
|
||||||
'url' => $data->getDownloadUrl()
|
'url' => $data->getDownloadUrl()
|
||||||
]
|
]
|
||||||
]);
|
];
|
||||||
} catch (TransportExceptionInterface $e) {
|
|
||||||
return new JsonResponse( data: $e->getMessage(), status: Response::HTTP_INTERNAL_SERVER_ERROR);
|
$content = $this->createRequest($httpClient, 'POST', $this->ogBootApiUrl.'/ogboot/v1/oglives/install', $params);
|
||||||
}
|
|
||||||
|
|
||||||
if ($response->getStatusCode() === Response::HTTP_OK) {
|
|
||||||
$data->setInstalled(true);
|
$data->setInstalled(true);
|
||||||
$entityManager->persist($data);
|
$entityManager->persist($data);
|
||||||
$entityManager->flush();
|
$entityManager->flush();
|
||||||
}
|
|
||||||
|
|
||||||
$data = json_decode($response->getContent(), true);
|
return new JsonResponse(data: $content, status: Response::HTTP_OK);
|
||||||
|
|
||||||
return new JsonResponse( data: $data, status: Response::HTTP_OK);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,12 +2,13 @@
|
||||||
|
|
||||||
namespace App\Controller\OgBoot\OgLive;
|
namespace App\Controller\OgBoot\OgLive;
|
||||||
|
|
||||||
use App\Controller\OgBoot\AbstractOgLiveController;
|
use App\Controller\OgBoot\AbstractOgBootController;
|
||||||
use App\Entity\OgLive;
|
use App\Entity\OgLive;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\HttpKernel\Attribute\AsController;
|
use Symfony\Component\HttpKernel\Attribute\AsController;
|
||||||
|
use Symfony\Component\Validator\Exception\ValidatorException;
|
||||||
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
||||||
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
||||||
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
||||||
|
@ -15,7 +16,7 @@ use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||||
|
|
||||||
#[AsController]
|
#[AsController]
|
||||||
class SetDefaultAction extends AbstractOgLiveController
|
class SetDefaultAction extends AbstractOgBootController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @throws TransportExceptionInterface
|
* @throws TransportExceptionInterface
|
||||||
|
@ -25,27 +26,22 @@ class SetDefaultAction extends AbstractOgLiveController
|
||||||
*/
|
*/
|
||||||
public function __invoke(OgLive $data, HttpClientInterface $httpClient, EntityManagerInterface $entityManager): JsonResponse
|
public function __invoke(OgLive $data, HttpClientInterface $httpClient, EntityManagerInterface $entityManager): JsonResponse
|
||||||
{
|
{
|
||||||
try {
|
if (!$data->getChecksum()) {
|
||||||
$response = $httpClient->request('PUT', $this->ogBootApiUrl.'/ogboot/v1/oglives/default', [
|
throw new ValidatorException('Checksum URL is required');
|
||||||
'headers' => [
|
}
|
||||||
'accept' => 'application/json',
|
|
||||||
],
|
$params = [
|
||||||
'json' => [
|
'json' => [
|
||||||
'checksum' => $data->getChecksum()
|
'checksum' => $data->getChecksum()
|
||||||
]
|
]
|
||||||
]);
|
];
|
||||||
} catch (TransportExceptionInterface $e) {
|
|
||||||
return new JsonResponse( data: 'An error occurred', status: Response::HTTP_INTERNAL_SERVER_ERROR);
|
$content = $this->createRequest($httpClient, 'PUT', $this->ogBootApiUrl.'/ogboot/v1/oglives/default', $params);
|
||||||
}
|
|
||||||
|
|
||||||
if ($response->getStatusCode() === Response::HTTP_OK) {
|
|
||||||
$data->setIsDefault(true);
|
$data->setIsDefault(true);
|
||||||
$entityManager->persist($data);
|
$entityManager->persist($data);
|
||||||
$entityManager->flush();
|
$entityManager->flush();
|
||||||
}
|
|
||||||
|
|
||||||
$data = json_decode($response->getContent(), true);
|
return new JsonResponse(status: Response::HTTP_OK);
|
||||||
|
|
||||||
return new JsonResponse( data: $data, status: Response::HTTP_OK);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,12 +2,13 @@
|
||||||
|
|
||||||
namespace App\Controller\OgBoot\OgLive;
|
namespace App\Controller\OgBoot\OgLive;
|
||||||
|
|
||||||
use App\Controller\OgBoot\AbstractOgLiveController;
|
use App\Controller\OgBoot\AbstractOgBootController;
|
||||||
use App\Entity\OgLive;
|
use App\Entity\OgLive;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\HttpKernel\Attribute\AsController;
|
use Symfony\Component\HttpKernel\Attribute\AsController;
|
||||||
|
use Symfony\Component\Validator\Exception\ValidatorException;
|
||||||
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
||||||
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
||||||
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
||||||
|
@ -15,7 +16,7 @@ use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||||
|
|
||||||
#[AsController]
|
#[AsController]
|
||||||
class SyncAction extends AbstractOgLiveController
|
class SyncAction extends AbstractOgBootController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @throws TransportExceptionInterface
|
* @throws TransportExceptionInterface
|
||||||
|
@ -25,32 +26,31 @@ class SyncAction extends AbstractOgLiveController
|
||||||
*/
|
*/
|
||||||
public function __invoke(HttpClientInterface $httpClient, EntityManagerInterface $entityManager): JsonResponse
|
public function __invoke(HttpClientInterface $httpClient, EntityManagerInterface $entityManager): JsonResponse
|
||||||
{
|
{
|
||||||
try {
|
$content = $this->createRequest($httpClient, 'GET', $this->ogBootApiUrl . '/ogboot/v1/oglives');
|
||||||
$response = $httpClient->request('GET', $this->ogBootApiUrl.'/ogboot/v1/oglives', [
|
|
||||||
'headers' => [
|
|
||||||
'accept' => 'application/json',
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
|
|
||||||
} catch (TransportExceptionInterface $e) {
|
foreach ($content['installed_ogLives'] as $ogLive) {
|
||||||
return new JsonResponse( data: 'An error occurred', status: Response::HTTP_INTERNAL_SERVER_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
$data = json_decode($response->getContent(), true);
|
|
||||||
|
|
||||||
foreach ($data['installed_ogLives'] as $ogLive) {
|
|
||||||
$ogLiveEntity = $this->entityManager->getRepository(OgLive::class)->findOneBy(['checksum' => $ogLive['id']]);
|
$ogLiveEntity = $this->entityManager->getRepository(OgLive::class)->findOneBy(['checksum' => $ogLive['id']]);
|
||||||
if ($ogLiveEntity) {
|
if ($ogLiveEntity) {
|
||||||
$ogLiveEntity->setName($ogLive['filename']);
|
$this->extracted($ogLiveEntity, $ogLive);
|
||||||
$ogLiveEntity->setInstalled(true);
|
|
||||||
$ogLiveEntity->setArchitecture($ogLive['architecture']);
|
|
||||||
$ogLiveEntity->setKernel($ogLive['kernel']);
|
|
||||||
$ogLiveEntity->setRevision($ogLive['revision']);
|
|
||||||
$ogLiveEntity->setDirectory($ogLive['directory']);
|
|
||||||
$ogLiveEntity->setChecksum($ogLive['id']);
|
|
||||||
$this->entityManager->persist($ogLiveEntity);
|
$this->entityManager->persist($ogLiveEntity);
|
||||||
} else {
|
} else {
|
||||||
$ogLiveEntity = new OgLive();
|
$ogLiveEntity = new OgLive();
|
||||||
|
$this->extracted($ogLiveEntity, $ogLive);
|
||||||
|
}
|
||||||
|
$this->entityManager->persist($ogLiveEntity);
|
||||||
|
}
|
||||||
|
$this->entityManager->flush();
|
||||||
|
|
||||||
|
return new JsonResponse(data: $content, status: Response::HTTP_OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param OgLive|null $ogLiveEntity
|
||||||
|
* @param mixed $ogLive
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function extracted(OgLive|null $ogLiveEntity, mixed $ogLive): void
|
||||||
|
{
|
||||||
$ogLiveEntity->setName($ogLive['filename']);
|
$ogLiveEntity->setName($ogLive['filename']);
|
||||||
$ogLiveEntity->setInstalled(true);
|
$ogLiveEntity->setInstalled(true);
|
||||||
$ogLiveEntity->setArchitecture($ogLive['architecture']);
|
$ogLiveEntity->setArchitecture($ogLive['architecture']);
|
||||||
|
@ -59,12 +59,4 @@ class SyncAction extends AbstractOgLiveController
|
||||||
$ogLiveEntity->setDirectory($ogLive['directory']);
|
$ogLiveEntity->setDirectory($ogLive['directory']);
|
||||||
$ogLiveEntity->setChecksum($ogLive['id']);
|
$ogLiveEntity->setChecksum($ogLive['id']);
|
||||||
}
|
}
|
||||||
$this->entityManager->persist($ogLiveEntity);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->entityManager->flush();
|
|
||||||
|
|
||||||
return new JsonResponse( data: $data, status: Response::HTTP_OK);
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -2,12 +2,14 @@
|
||||||
|
|
||||||
namespace App\Controller\OgBoot\OgLive;
|
namespace App\Controller\OgBoot\OgLive;
|
||||||
|
|
||||||
use App\Controller\OgBoot\AbstractOgLiveController;
|
use App\Controller\OgBoot\AbstractOgBootController;
|
||||||
use App\Entity\OgLive;
|
use App\Entity\OgLive;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\HttpKernel\Attribute\AsController;
|
use Symfony\Component\HttpKernel\Attribute\AsController;
|
||||||
|
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||||
|
use Symfony\Component\Validator\Exception\ValidatorException;
|
||||||
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
||||||
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
||||||
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
||||||
|
@ -15,7 +17,7 @@ use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||||
|
|
||||||
#[AsController]
|
#[AsController]
|
||||||
class UninstallAction extends AbstractOgLiveController
|
class UninstallAction extends AbstractOgBootController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @throws ServerExceptionInterface
|
* @throws ServerExceptionInterface
|
||||||
|
@ -25,22 +27,14 @@ class UninstallAction extends AbstractOgLiveController
|
||||||
*/
|
*/
|
||||||
public function __invoke(OgLive $data, HttpClientInterface $httpClient, EntityManagerInterface $entityManager): JsonResponse
|
public function __invoke(OgLive $data, HttpClientInterface $httpClient, EntityManagerInterface $entityManager): JsonResponse
|
||||||
{
|
{
|
||||||
try {
|
if (!$data->getChecksum()) {
|
||||||
$response = $httpClient->request('DELETE', $this->ogBootApiUrl.'/ogboot/v1/oglives/'.$data->getChecksum(), [
|
throw new ValidatorException('Checksum is required');
|
||||||
'headers' => [
|
|
||||||
'accept' => 'application/json',
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
|
|
||||||
} catch (TransportExceptionInterface $e) {
|
|
||||||
return new JsonResponse( data: $e->getMessage(), status: Response::HTTP_INTERNAL_SERVER_ERROR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($response->getStatusCode() === Response::HTTP_OK) {
|
$content = $this->createRequest($httpClient, 'DELETE', $this->ogBootApiUrl.'/ogboot/v1/oglives/'.$data->getChecksum());
|
||||||
$data->setInstalled(false);
|
|
||||||
$entityManager->persist($data);
|
$entityManager->remove($data);
|
||||||
$entityManager->flush();
|
$entityManager->flush();
|
||||||
}
|
|
||||||
|
|
||||||
return new JsonResponse(status: Response::HTTP_OK);
|
return new JsonResponse(status: Response::HTTP_OK);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace App\Controller\OgBoot\PxeBootFile;
|
namespace App\Controller\OgBoot\PxeBootFile;
|
||||||
|
|
||||||
use App\Controller\OgBoot\AbstractOgLiveController;
|
use App\Controller\OgBoot\AbstractOgBootController;
|
||||||
use App\Entity\PxeBootFile;
|
use App\Entity\PxeBootFile;
|
||||||
use App\Entity\PxeTemplate;
|
use App\Entity\PxeTemplate;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
@ -16,7 +16,7 @@ use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||||
|
|
||||||
#[AsController]
|
#[AsController]
|
||||||
class GetCollectionAction extends AbstractOgLiveController
|
class GetCollectionAction extends AbstractOgBootController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @throws TransportExceptionInterface
|
* @throws TransportExceptionInterface
|
||||||
|
@ -26,18 +26,8 @@ class GetCollectionAction extends AbstractOgLiveController
|
||||||
*/
|
*/
|
||||||
public function __invoke(HttpClientInterface $httpClient): JsonResponse
|
public function __invoke(HttpClientInterface $httpClient): JsonResponse
|
||||||
{
|
{
|
||||||
try {
|
$content = $this->createRequest($httpClient, 'GET', $this->ogBootApiUrl.'/ogboot/v1/pxes');
|
||||||
$response = $httpClient->request('GET', $this->ogBootApiUrl.'/ogboot/v1/pxes', [
|
|
||||||
'headers' => [
|
|
||||||
'accept' => 'application/json',
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
} catch (TransportExceptionInterface $e) {
|
|
||||||
return new JsonResponse( data: 'An error occurred', status: Response::HTTP_INTERNAL_SERVER_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
$data = json_decode($response->getContent(), true);
|
return new JsonResponse(data: $content, status: Response::HTTP_OK);
|
||||||
|
|
||||||
return new JsonResponse( data: $data, status: Response::HTTP_OK);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,8 +2,9 @@
|
||||||
|
|
||||||
namespace App\Controller\OgBoot\PxeTemplate;
|
namespace App\Controller\OgBoot\PxeTemplate;
|
||||||
|
|
||||||
use App\Controller\OgBoot\AbstractOgLiveController;
|
use App\Controller\OgBoot\AbstractOgBootController;
|
||||||
use App\Entity\PxeTemplate;
|
use App\Entity\PxeTemplate;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
@ -15,7 +16,7 @@ use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||||
|
|
||||||
#[AsController]
|
#[AsController]
|
||||||
class DeleteAction extends AbstractOgLiveController
|
class DeleteAction extends AbstractOgBootController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @throws TransportExceptionInterface
|
* @throws TransportExceptionInterface
|
||||||
|
@ -23,7 +24,7 @@ class DeleteAction extends AbstractOgLiveController
|
||||||
* @throws RedirectionExceptionInterface
|
* @throws RedirectionExceptionInterface
|
||||||
* @throws ClientExceptionInterface
|
* @throws ClientExceptionInterface
|
||||||
*/
|
*/
|
||||||
public function __invoke(PxeTemplate $data, HttpClientInterface $httpClient): JsonResponse
|
public function __invoke(PxeTemplate $data, HttpClientInterface $httpClient, EntityManagerInterface $entityManager): JsonResponse
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$response = $httpClient->request('DELETE', $this->ogBootApiUrl.'/ogboot/v1/pxe-templates/'.$data->getName(), [
|
$response = $httpClient->request('DELETE', $this->ogBootApiUrl.'/ogboot/v1/pxe-templates/'.$data->getName(), [
|
||||||
|
@ -35,8 +36,11 @@ class DeleteAction extends AbstractOgLiveController
|
||||||
return new JsonResponse( data: 'An error occurred', status: Response::HTTP_INTERNAL_SERVER_ERROR);
|
return new JsonResponse( data: 'An error occurred', status: Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = json_decode($response->getContent(), true);
|
if ($response->getStatusCode() === Response::HTTP_OK) {
|
||||||
|
$entityManager->remove($data);
|
||||||
|
$entityManager->flush();
|
||||||
|
}
|
||||||
|
|
||||||
return new JsonResponse( data: $data, status: Response::HTTP_OK);
|
return new JsonResponse(status: Response::HTTP_OK);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace App\Controller\OgBoot\PxeTemplate;
|
namespace App\Controller\OgBoot\PxeTemplate;
|
||||||
|
|
||||||
use App\Controller\OgBoot\AbstractOgLiveController;
|
use App\Controller\OgBoot\AbstractOgBootController;
|
||||||
use App\Entity\PxeTemplate;
|
use App\Entity\PxeTemplate;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
|
@ -15,7 +15,7 @@ use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||||
|
|
||||||
#[AsController]
|
#[AsController]
|
||||||
class GetAction extends AbstractOgLiveController
|
class GetAction extends AbstractOgBootController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @throws TransportExceptionInterface
|
* @throws TransportExceptionInterface
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace App\Controller\OgBoot\PxeTemplate;
|
namespace App\Controller\OgBoot\PxeTemplate;
|
||||||
|
|
||||||
use App\Controller\OgBoot\AbstractOgLiveController;
|
use App\Controller\OgBoot\AbstractOgBootController;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
@ -14,7 +14,7 @@ use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||||
|
|
||||||
#[AsController]
|
#[AsController]
|
||||||
class GetCollectionAction extends AbstractOgLiveController
|
class GetCollectionAction extends AbstractOgBootController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @throws TransportExceptionInterface
|
* @throws TransportExceptionInterface
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace App\Controller\OgBoot\PxeTemplate;
|
namespace App\Controller\OgBoot\PxeTemplate;
|
||||||
|
|
||||||
use App\Controller\OgBoot\AbstractOgLiveController;
|
use App\Controller\OgBoot\AbstractOgBootController;
|
||||||
use App\Entity\PxeTemplate;
|
use App\Entity\PxeTemplate;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
@ -16,7 +16,7 @@ use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||||
|
|
||||||
#[AsController]
|
#[AsController]
|
||||||
class PostAction extends AbstractOgLiveController
|
class PostAction extends AbstractOgBootController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @throws TransportExceptionInterface
|
* @throws TransportExceptionInterface
|
||||||
|
|
Loading…
Reference in New Issue