refs #658. Updated endpoints with failure and success logic
parent
aa1da83a70
commit
8bfc471144
|
@ -34,7 +34,7 @@ class InstallAction extends AbstractOgBootController
|
|||
$params = [
|
||||
'json' => [
|
||||
'url' => $data->getDownloadUrl(),
|
||||
'ogCoreId' => $data->getUuid()
|
||||
'id' => $data->getUuid()
|
||||
]
|
||||
];
|
||||
|
||||
|
|
|
@ -22,6 +22,11 @@ use Symfony\Contracts\HttpClient\HttpClientInterface;
|
|||
#[AsController]
|
||||
class InstallOgLiveResponseAction extends AbstractController
|
||||
{
|
||||
public CONST string OG_LIVE_INSTALL_SUCCESS = 'success';
|
||||
public CONST string OG_LIVE_INSTALL_FAILED = 'failure';
|
||||
|
||||
|
||||
|
||||
public function __construct(
|
||||
protected readonly EntityManagerInterface $entityManager
|
||||
)
|
||||
|
@ -33,14 +38,15 @@ class InstallOgLiveResponseAction extends AbstractController
|
|||
{
|
||||
$data = json_decode($request->getContent(), true);
|
||||
|
||||
if ($data === null || !isset($data['message'], $data['ogCoreId'], $data['details']['result'])) {
|
||||
if ($data === null || !isset($data['message'], $data['ogCoreId'], $data['details'])) {
|
||||
return new JsonResponse(['error' => 'Invalid or incomplete JSON data'], Response::HTTP_BAD_REQUEST);
|
||||
}
|
||||
|
||||
$message = $data['message'];
|
||||
$ogCoreId = $data['ogCoreId'];
|
||||
$details = $data['details'];
|
||||
$result = $details['result'];
|
||||
$status = $data['status'];
|
||||
$result = $status === self::OG_LIVE_INSTALL_SUCCESS ? $details['result'] : [];
|
||||
|
||||
$ogLive = $this->entityManager->getRepository(OgLive::class)->findOneBy(['uuid' => $ogCoreId]);
|
||||
|
||||
|
@ -52,18 +58,28 @@ class InstallOgLiveResponseAction extends AbstractController
|
|||
return new JsonResponse(['error' => 'OgLive is already active'], Response::HTTP_BAD_REQUEST);
|
||||
}
|
||||
|
||||
$ogLive->setStatus($details['status'] === 'success' ? OgLiveStatus::ACTIVE : OgLiveStatus::FAILED);
|
||||
$ogLive->setInstalled($details['status'] === 'success');
|
||||
$ogLive->setChecksum($result['id']);
|
||||
$ogLive->setDistribution($result['distribution']);
|
||||
$ogLive->setKernel($result['kernel']);
|
||||
$ogLive->setArchitecture($result['architecture']);
|
||||
$ogLive->setRevision($result['revision']);
|
||||
$ogLive->setDirectory($result['directory']);
|
||||
|
||||
$this->entityManager->persist($ogLive);
|
||||
$this->entityManager->flush();
|
||||
$this->updateOgLive($ogLive, $details, $result, $status);
|
||||
|
||||
return new JsonResponse(data: sprintf('OgLive %s updated successfully', $ogLive->getChecksum()), status: Response::HTTP_OK);
|
||||
}
|
||||
|
||||
private function updateOgLive (OgLive $ogLive, array $details, array $result, string $status): void
|
||||
{
|
||||
if ($status === self::OG_LIVE_INSTALL_SUCCESS) {
|
||||
$ogLive->setInstalled(true);
|
||||
$ogLive->setSynchronized(true);
|
||||
$ogLive->setChecksum($result['id']);
|
||||
$ogLive->setDistribution($result['distribution']);
|
||||
$ogLive->setKernel($result['kernel']);
|
||||
$ogLive->setArchitecture($result['architecture']);
|
||||
$ogLive->setRevision($result['revision']);
|
||||
$ogLive->setDirectory($result['directory']);
|
||||
}
|
||||
|
||||
$ogLive->setStatus($status === self::OG_LIVE_INSTALL_SUCCESS ? OgLiveStatus::ACTIVE : OgLiveStatus::FAILED);
|
||||
$ogLive->setInstalled($status === self::OG_LIVE_INSTALL_SUCCESS);
|
||||
|
||||
$this->entityManager->persist($ogLive);
|
||||
$this->entityManager->flush();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue