diff --git a/src/Controller/OgBoot/OgLive/InstallAction.php b/src/Controller/OgBoot/OgLive/InstallAction.php index 2572499..e2bbe17 100644 --- a/src/Controller/OgBoot/OgLive/InstallAction.php +++ b/src/Controller/OgBoot/OgLive/InstallAction.php @@ -34,7 +34,7 @@ class InstallAction extends AbstractOgBootController $params = [ 'json' => [ 'url' => $data->getDownloadUrl(), - 'ogCoreId' => $data->getUuid() + 'id' => $data->getUuid() ] ]; diff --git a/src/Controller/OgBoot/OgLive/Webhook/InstallOgLiveResponseAction.php b/src/Controller/OgBoot/OgLive/Webhook/InstallOgLiveResponseAction.php index 336e957..f5e7cbc 100644 --- a/src/Controller/OgBoot/OgLive/Webhook/InstallOgLiveResponseAction.php +++ b/src/Controller/OgBoot/OgLive/Webhook/InstallOgLiveResponseAction.php @@ -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(); + } } \ No newline at end of file